Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-filling entire paragraph automatically with auto-fill-mode?

Motivation: Using the defaults, Auto Fill mode seems not as useful as I might have hoped: If I insert a sentence in the middle of a paragraph, only the current line is re-filled. When I insert a sentence, I want the entire paragraph to be re-filled.

Question: How can I set auto-fill-function (or perhaps normal-auto-fill-function) in my .emacs file so that the paragraph is re-filled whenever a single line overflows? I tried setting it to fill-paragraph, but then I cannot insert any spaces at the end of a paragraph (e.g., to add another word).

More details: I primarily use Auto Fill mode in the AUCTeX major mode for LaTeX.

The built-in Emacs documentation for auto-fill-mode states:

When auto-fill-mode is on, the auto-fill-function variable is non-nil.

The value of normal-auto-fill-function specifies the function to use for auto-fill-function when turning Auto Fill mode on.

The documentation for the normal-auto-fill-function variable says that it is the function to use for auto-fill-function if Auto Fill mode is turned on, and that the initial value is do-auto-fill.

like image 761
Henry DeYoung Avatar asked Oct 22 '25 06:10

Henry DeYoung


2 Answers

You might like to try refill-mode. But in general, it's just tricky to make such a feature work well. Another approach is to only do the refill as part of the redisplay (i.e. without affecting the buffer's actual content). For that, try setting word-wrap or enabling visual-line-mode.

like image 73
Stefan Avatar answered Oct 24 '25 07:10

Stefan


For LaTeX files you can try (requires AUCTeX)

(add-hook 'LaTeX-mode-hook '(lambda ()
                  (setq auto-fill-function 'LaTeX-fill-paragraph)))

but use it with caution.

like image 45
giordano Avatar answered Oct 24 '25 09:10

giordano