Consider the following comments:

;; This is the first line of a comment.
;; This is the second line, which begins a paragraph. If I have
;;auto-fill-mode enabled, I lose the leading space!

;; However, suppose instead the first paragraph of the comment is
;; actually more than one line.
;; In that case, once I get to the end of a paragraph, the leading
;; space is preserved as desired!

The problem is that if the first paragraph of a comment is only one line, then auto-fill-mode does not fill adaptively.

I understand that a block of lines starting with ;; constitutes a single paragraph to Emacs. So the behavior is unsurprising in light of the following information from the manual:

If the paragraph has two or more lines, the fill prefix is taken from the paragraph’s second line, but only if it appears on the first line as well.

In this case, because the second line of the paragraph has content ;; and not ;; (i.e. there is no trailing whitespace), Emacs thinks the second line has no fill prefix, and therefore infers that the rest of the paragraph ought not to be filled with a prefix either.

However, I noticed the following additional information on the same manual page:

If the prefix found on the first line matches adaptive-fill-first-line-regexp, or if it appears to be a comment-starting sequence (this depends on the major mode), then the prefix found is used for filling the paragraph, provided it would not act as a paragraph starter on subsequent lines.

Since my comment is in emacs-lisp-mode, I would have thought the first line would qualify as a "comment-starting sequence" and therefore its fill prefix (a single space ) would be used, as desired. But this does not happen—what am I missing?

(I've checked the documentation strings and source code of relevant functions, read the relevant manual pages, checked the Internet for references to this problem, etc. No dice.)

To reproduce the problem, just open emacs -Q, run M-x auto-fill-mode, and type the comments above into the *scratch* buffer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.