Skip to content

Commit d7f5528

Browse files
committed
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.
1 parent 8d1454d commit d7f5528

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

haskell-simple-indent.el

+16
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ column, `tab-to-tab-stop' is done instead."
175175
(haskell-simple-indent-newline-same-col)
176176
(insert (make-string haskell-indent-spaces ? )))
177177

178+
(defun haskell-simple-indent-comment-indent-function ()
179+
"Haskell version of `comment-indent-function'."
180+
;; This is required when filladapt is turned off. Without it, when
181+
;; filladapt is not used, comments which start in column zero
182+
;; cascade one character to the right
183+
(save-excursion
184+
(beginning-of-line)
185+
(let ((eol (line-end-position)))
186+
(and comment-start-skip
187+
(re-search-forward comment-start-skip eol t)
188+
(setq eol (match-beginning 0)))
189+
(goto-char eol)
190+
(skip-chars-backward " \t")
191+
(max comment-column (+ (current-column) (if (bolp) 0 1))))))
192+
178193
;;;###autoload
179194
(define-minor-mode haskell-simple-indent-mode
180195
"Simple Haskell indentation mode that uses simple heuristic.
@@ -189,6 +204,7 @@ Runs `haskell-simple-indent-hook' on activation."
189204
:lighter " Ind"
190205
:group 'haskell-simple-indent
191206
:keymap '(([backtab] . haskell-simple-indent-backtab))
207+
(set (make-local-variable 'comment-indent-function) #'haskell-simple-indent-comment-indent-function)
192208
(kill-local-variable 'indent-line-function)
193209
(when haskell-simple-indent-mode
194210
(set (make-local-variable 'indent-line-function) 'haskell-simple-indent)

0 commit comments

Comments
 (0)