0
votes

Normally, I need to enable the auto-fill-mode, so I have it turned on in .emacs. But when editting PHP in php-mode, I'd like to not use auto-fill-mode. Is there way to set it in .emacs such that when I'm in PHP mode, the auto-fill-paragraph mode is automatically turned off and when I leave php-mode, it's automatically turned on, barring other overriding?

Update: a closer examination of the .emacs revealed that auto-fill is set up by

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(column-number-mode t)
  ...
  '(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))
  ...)
1
auto-fill-mode doesn't look like it's global, so you have probably set that to be global somewhere in your user customization files. The easiest way I can think of to control its behavior is to put in an exception to the function that turns on auto-fill-mode (i.e., excluding php-mode) (or create such a function), or simply use it as a buffer-local minor-mode that is enabled with major-mode hooks that you normally use. The docs state that it is a buffer-local minor-mode: gnu.org/software/emacs/manual/html_node/emacs/Auto-Fill.html - lawlist
If it's an inheriting issue (e.g., php-mode is borrowing another major-mode) instead of a global setting issue, then perhaps you could try something like: (add-hook 'php-mode-hook (lambda () (auto-fill-mode -1))) The inheriting issue is one of the reasons that I set up my own text-mode that is distinct from the stock version -- i.e., so that other major modes don't inherit some text-mode settings. -1 (negative integer) turns off a minor-mode. - lawlist
@lawlist Could you give your comment as a proper answer, please? - Thomas

1 Answers

1
votes

Some major-modes inherit certain settings from other modes (e.g., text-mode is used by many popular major modes). The following code snippet can be used to disable a feature for a particular major-mode using its mode hook:

(add-hook 'php-mode-hook (lambda ()
  (auto-fill-mode -1) ))

It is sometimes helpful to check and see whether a particular feature has been enabled globally or locally, which in turn can give a clue as to whether that feature has been inherited by a major mode. In this case, the documentation for auto-fill-mode states as follows -- https://www.gnu.org/software/emacs/manual/html_node/emacs/Auto-Fill.html:

"Auto Fill mode is a buffer-local minor mode (see Minor Modes) in which lines are broken automatically when they become too wide. Breaking happens only when you type a <SPC> or <RET>."