0
votes

I'm trying to configure Emacs to not activate Auto-Fill when editing an XML document.

In my .emacs file, I add a hook so that text mode will have Auto-Fill on by default:

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

I have added a directory to my load path:

(add-to-list 'load-path "~/.emacs.d/lisp/")

Inside that directory, I have written a file xml.el for this workstation, and I have tried each of the following in it, to no avail:

(add-hook 'xml-mode-hook 'turn-off-auto-fill)
(add-hook 'xml-mode-hook 'auto-fill-mode)
(remove-hook 'xml-mode-hook 'turn-on-auto-fill)
(remove-hook 'xml-mode-hook 'auto-fill-mode)

How can I disable Auto-Fill in XML mode?

EDIT: It appears this is caused by my text-mode-hook mentioned above. How can I override this hook in nxml-mode?

1
What do you mean by "I have written a file xml.el"? Did you write your own major mode for editing XML? Does it actually have an xml-mode-hook? Normally I would expect to see nxml-mode used to edit XML files, which has its own nxml-mode-hook. - Chris
No, xml.el is in ~/.emacs.d/lisp. - 2mac
Changing my hook calls to use nxml-mode-hook did not work either, though. - 2mac
Well, it would only work if you were also invoking nxml-mode. - Chris
xml.el is the name of a standard Emacs library. You shouldn't be putting a conflicting filename under your load-path, as it may shadow the standard library, breaking anything which depends on it. I recommend using a non-conflicting prefix for all of your custom elisp libraries. I use my- as a prefix, for example (for both filenames and function names). - phils

1 Answers

1
votes

Ah, nxml-mode derives from text-mode. That's slightly surprising to me (although on closer inspection, it does appear to be standard for markup language modes in Emacs).

In that case you can either disable it again in nxml-mode-hook (as text-mode-hook has already run by that point):

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

(n.b. you said in the comments that this didn't work for you, but it certainly works for me).

or else just change your text-mode-hook code to something like the following, in order to catch this case before auto-fill is enabled:

(defun my-text-mode-hook ()
  "Custom behaviours for `text-mode'."
  ;; Enable `auto-fill-mode', except in `nxml-mode' (which is derived
  ;; from `text-mode').
  (unless (eq major-mode 'nxml-mode)
    (turn-on-auto-fill)))

(add-hook 'text-mode-hook 'my-text-mode-hook)