Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto-fill inside comments does not work #143

Open
CSRaghunandan opened this issue Dec 16, 2016 · 2 comments
Open

auto-fill inside comments does not work #143

CSRaghunandan opened this issue Dec 16, 2016 · 2 comments

Comments

@CSRaghunandan
Copy link

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
Copy link
Contributor

emmanueldenloye commented Jan 22, 2017

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
Copy link
Author

CSRaghunandan commented Jan 24, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants