3

I have:

(add-hook 'text-mode-hook 'turn-on-auto-fill)

but in lisp/nxml/nxml-mode.el:

(define-derived-mode nxml-mode text-mode "nXML"

All XML files is opened with auto-fill-mode. That is inconvenient because XML file under source control and shouldn't drastically change on edits.

How can I disable auto-fill for nxml? Should I remove:

(add-hook 'text-mode-hook 'turn-on-auto-fill)

or add some workaround for nxml?

1 Answer 1

4

Prevent hooks from parent mode in derived mode

Not trivial. I certainly can't think of a nice approach. You may find https://stackoverflow.com/a/19295380 of interest, though.

How can I disable auto-fill for nxml?

The trivial approach is to simply switch it off in nxml-mode-hook. The mode will be switched on, and almost immediately switched off again.

(add-hook 'nxml-mode-hook 'turn-off-auto-fill)

Alternatively, replace 'turn-on-auto-fill in your code with a custom function that does what you really want:

(defun my-turn-on-auto-fill-maybe ()
  "Turns on `auto-fill-mode' unless I don't want it."
  (let ((exceptions '(nxml-mode)))
    (unless (apply 'derived-mode-p exceptions)
      (auto-fill-mode 1))))
2
  • From your explanation I see that (add-hook 'text-mode-hook 'turn-on-auto-fill) is bad defaults. It's better to turn on where I need then add exceptions.
    – gavenkoa
    Commented Apr 27, 2017 at 14:05
  • FWIW, the first option does retain the flyspell-mode messages, i.e., the minibuffer talks about flyspell-mode even though it's disabled, which confused me a bit.
    – Reid
    Commented Mar 21, 2022 at 23:02

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.