5

In Emacs (23.4.1), how do I enable a minor mode (e.g. auto-fill-mode) for all files in a major mode (e.g. text-mode) under a directory (recursively)?

It doesn't look like directory-local variables can do ths, but I might be wrong.

1 Answer 1

6

You should use a text-mode hook. In your .emacs file:

(defun turn-on-auto-fill-hook ()
  (cond ((string-match "^/home/foo/bar/blat/" buffer-file-name)
         (auto-fill-mode 1))))

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

Replace /home/foo/bar/blat with the path to the directory whose files you want to have auto-fill-mode enabled in when visited. Don't remove the caret.

2
  • 2
    Is there no better answer, now, 8 years later? I want to do this in a .dir-locals.el too ...
    – thoni56
    May 11, 2020 at 17:58
  • 1
    Yes, there is a better answer here: superuser.com/a/794979/40916
    – thoni56
    May 11, 2020 at 18:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .