From d7f55283973711bcfa99103a37040c2ca77e088b Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Sun, 18 Jan 2015 00:28:04 +0100 Subject: [PATCH] Implement haskell-comment-function. haskell-comment-function is useful when auto-fill-mode is enabled and comments are expected to auto-fill. This function keeps comments nicely aligned. --- haskell-simple-indent.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/haskell-simple-indent.el b/haskell-simple-indent.el index 3d3f7bc25..db9f0cca7 100644 --- a/haskell-simple-indent.el +++ b/haskell-simple-indent.el @@ -175,6 +175,21 @@ column, `tab-to-tab-stop' is done instead." (haskell-simple-indent-newline-same-col) (insert (make-string haskell-indent-spaces ? ))) +(defun haskell-simple-indent-comment-indent-function () + "Haskell version of `comment-indent-function'." + ;; This is required when filladapt is turned off. Without it, when + ;; filladapt is not used, comments which start in column zero + ;; cascade one character to the right + (save-excursion + (beginning-of-line) + (let ((eol (line-end-position))) + (and comment-start-skip + (re-search-forward comment-start-skip eol t) + (setq eol (match-beginning 0))) + (goto-char eol) + (skip-chars-backward " \t") + (max comment-column (+ (current-column) (if (bolp) 0 1)))))) + ;;;###autoload (define-minor-mode haskell-simple-indent-mode "Simple Haskell indentation mode that uses simple heuristic. @@ -189,6 +204,7 @@ Runs `haskell-simple-indent-hook' on activation." :lighter " Ind" :group 'haskell-simple-indent :keymap '(([backtab] . haskell-simple-indent-backtab)) + (set (make-local-variable 'comment-indent-function) #'haskell-simple-indent-comment-indent-function) (kill-local-variable 'indent-line-function) (when haskell-simple-indent-mode (set (make-local-variable 'indent-line-function) 'haskell-simple-indent)