If you are using AUCTeX (you should be), you can check the LaTeX-indent-environment-list . Adding an environment to this variable will make (among other things) Mq not fill up the paragraph. Unfortunately, this does not look like automatic fill mode. The following largely unverified code added to LaTeX-mode-hook may do what you want.
(setq auto-fill-function (lambda () (unless (> (save-excursion (or (search-backward "%%% BEGIN NO FILL" (point-min) t) 0)) (save-excursion (or (search-backward "%%% END NO FILL" (point-min) t) 0))) (do-auto-fill))))
This is very stupid and inefficient, but it seems to work quite quickly on my machine. It does not allow nesting and requires that you manually mark all sections that you do not want to fill. What I'm going to add to my .emacs (until I read your question, I did not understand how much it bothers me) is below the keys of the current environment, so there is no need for special markup (although it looks only at the most internal environment (I'm not sure what the problem is that will cause in practice)). The combination of these two functions remains as an exercise for the interested reader.
;; You can use the following to unset the variables and play around with them ;; (makunbound 'auto-fill-ignore-environments) ;; (makunbound 'auto-fill-ignore-environments-regexp) (defcustom auto-fill-ignore-environments (mapcar 'car LaTeX-indent-environment-list) "List of environments for which `auto-fill-mode' should be disabled. Used to generate `auto-fill-ignore-environments-regexp'." :type '(sexp) ) (defcustom auto-fill-ignore-environments-regexp (regexp-opt auto-fill-ignore-environments) "Regexp matching LaTeX environments for which `auto-fill-mode' should be disabled. If not set, automatically generated from `auto-fill-ignore-environments'" :type '(string) :set-after '(auto-fill-ignore-environments) ) (add-hook 'LaTeX-mode-hook (lambda () (setq auto-fill-function (lambda () (unless (string-match auto-fill-ignore-environments-regexp (LaTeX-current-environment)) (do-auto-fill))))))
I have never used defcustom before, so I'm sure that the part can be improved quite a bit.
Ivan Andrus
source share