0

I am inexperienced in Emacs and very new to directory-local variables, so please forgive any obvious things I may be missing.

I am trying to have auto-fill mode activated for all the files in a certain directory. In this directory, I have a .dir-locals.el file which contains:

((nil . ((eval add-hook 'text-mode-hook 'turn-on-auto-fill)
     (truncate-lines . nil)))
)

(FYI I have truncate-lines set to t in my .emacs file, so that's its "default" value for me.)

After saving this .dir-locals.el file, when opening a text file with Emacs in this directory, I find that truncate-lines is indeed turned off. However, auto-fill isn't working: the lines I'm writing don't break into new lines. (My fill-column value is 70.)

When I do C-h v text-mode-hook I get:

text-mode-hook's value is 
(turn-on-auto-fill text-mode-hook-identify)
...

but when I don't include the "eval add-hook..." in the .dir-locals.el file, the words turn-on-auto-fill don't appear in the text-mode-hook's value, so the .el file I have appears to be setting something, it just isn't working.

When I do M-x auto-fill-mode, then auto-fill does start working.

Any ideas why auto-fill isn't working for me from my directory local file? Alternatively, any suggestions for an alternative way to active auto-fill-mode for and only for the files in my directory?

2

The directory local variables are set after the major mode command run. Otherwise the major-mode dependent file local variables would not work.

Therefore, you just buffer-locally add turn-on-auto-fill to text-mode-hook. But the hook is not run again and your configuration is without effect.

If you want to deactivate truncate-lines for all major modes and activate auto-fill-mode just for text-mode in a certain directory (and its sub-directories) you can put the following list into your .dir-locals.el-file:

((nil . ((truncate-lines . t)))
 (text-mode . ((eval . (turn-on-auto-fill)))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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