projectional-haskell / structured-haskell-mode

Structured editing minor mode for Haskell in Emacs
BSD 3-Clause "New" or "Revised" License
541 stars 38 forks source link

auto-fill inside comments does not work #143

Open CSRaghunandan opened 7 years ago

CSRaghunandan commented 7 years ago

I've set (setq comment-auto-fill-only-comments t) and I've noticed that when structured-haskell-mode is enabled, comments aren't getting auto-filled by default. I'd have to manually select a long comment and execute fill-region.

emmanueldenloye commented 7 years ago

Hey CSRaghunandan, give this piece of code a whirl. (I might add it to pull request). It is not quite what you want, but advise fill-paragraph (or hindent-reformat-decl-or-fill if it replaces it) to use this function with defadvice.

(defun shm-fill-comment () "Fill the comment(s)." (cond ((shm-in-comment) (fill-paragraph)) ((when-let ((beg (save-excursion (comment-beginning)))) (string= "-- " (buffer-substring-no-properties beg (point)))) (let* ((start (save-excursion (comment-beginning))) (commentStart (save-excursion (goto-char start) (let ((back start)) (while back (goto-char (- back 1)) (setq back (comment-beginning)))) (point))) (commentEnd (save-excursion (goto-char start) (while (comment-forward)) (point)))) (fill-region commentStart commentEnd)))))

CSRaghunandan commented 7 years ago

@emmanueldenloye can you tell me how I can test this function out? I tried adding advice to hindent-reformat-decl-or-fill and fill-paragraph but could not get the desired feature. What I want is auto-fill-mode to behave like it does with other modes when comment-auto-fill-only-comments set to t. What it does is, when I type a word and it exceeds the fill-column value, a new comment is created on the next line automatically.

PS. I can also press return and the comment will get auto filled to multiple lines as necessary. No need press M-q.