2

I'd like to enable whitespace-mode from a .dir-locals.el file such that when I open a file managed by cc-mode, I will see trailing spaces highlighted with the whitespace face.

I think I'm close. This is what I have in my .dir-locals.el, but its not quite enough.

((cc-mode . ((whitespace-style . (face trailing))            
             (whitespace-active-style . (face trailing))))

But if I M-xwhitespace-toggle-options and choose f, then the trailing whitespace is highlighted.

3

Use the special "variable" eval as described in Specifying File Variables.

This .dir-locals.el code enables whitespace-mode for me:

((c++-mode
  (eval . (whitespace-mode))))

(I use Emacs 24.4.1.)

  • Except I would strongly recommend using the more readable (albeit entirely equivalent) dotted pair syntax: (eval . (whitespace-mode)) – phils Dec 15 '14 at 22:07
  • @phils: Sounds good; I'll update the answer. (Apparently add-dir-local-variable does not care about formatting.) – Constantine Dec 15 '14 at 22:11

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.