I keep auto-fill-mode enabled by default for all LaTeX files.
This is usually nice, but occasionally one latex file contains mostly tables and I would like to disable auto-fill-mode whenever I edit that particular file.
Is it possible to specify at the top of a .tex file that I would like it to be the exception? Alternatively, is it possible to specify in .emacs the paths/names of these files?
look onto "Local Variables in Files" section in official Emacs documentation. There is eval
variable, that allows to evaluate any code. So it will look something like (put this into end of file, comment char should be mode-specific):
# Local Variables:
# eval: (auto-fill-mode -1)
# End:
I like the solution of looking for something in the file to determine whether or not to have autofill.
If you want to put an identifier at the top, you can use code like this:
(defun my-auto-fill-disabling-hook ()
"Check to see if we should disable autofill."
(save-excursion
(when (re-search-forward "Some Unique Identifier" 1000 t)
(auto-fill-mode -1))))
(add-hook 'find-file-hooks 'my-auto-fill-disabling-hook)
And obviously change "Some Unique Identifier"
to something reasonable - such as a search for the tables themselves. Then you'd get exactly what you want, LaTeX files with tables wouldn't be auto-filled.
Note: @Alex suggested using a file-local variable, but this is a mistake according to the manual itself:
Often, however, it is a mistake to enable minor modes this way. Most minor modes, like Auto Fill mode, represent individual user preferences. If you want to use a minor mode, it is better to set up major mode hooks with your init file to turn that minor mode on for yourself alone (see Init File), instead of using a local variable list to impose your taste on everyone.
This approach does not technically disable fill mode, but it is safe, unlike enabling eval, and achieves the desired result. Put a line like this as the first line of your file. Just specify the correct major mode, probably text, and set the fill-column to an appropriately large value:
-*- mode: text; fill-column: 99999 -*-
As previously suggested, you could write a hook that decides if auto-fill should be enabled, but I felt that was more work than necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With