I generated a .dir-locals.el by calling the function add-dir-local-variable, giving it the path for the project for which I want the variable, the variable itself, and its value.

The generated file went to my home directory (not the project path as I expected), and had the following content:

;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")

  (indent-tabs-mode . t)))

Then I went on and created a file a.c in that directory, and copied .dir-locals.el there for good measure.

The indent in that file is still set as spaces, as per my ~/.emacs.d/init.el. I expected it to be tabs, as per the local .dir-locals.el. I tried restarting emacs, but that did not work either.

What did I do wrong, or misunderstand?

I am on Mac OS Sierra.

1 Answer 1


When you call add-dir-local-variable, it assumes you are already in the directory you want to apply the directory-local variable to. When it prompts for a directory, it's asking if you want the variable applied to a subdirectory of your current directory.

So I expect giving it the absolute path to a directory is causing your problem. In your case, I think what you need is a .dir-locals.el file in the directory you're targeting (i.e., ~/tmp/test_test_dir_local) that contains the following:

  (indent-tabs-mode . t)))

The nil symbol indicates that this variable will be applied to all files in all subdirectories of the ~/tmp/test_test_dir_local. You can change it to indicate you only want it applied to a certain subdirectory (in quotes):

  (indent-tabs-mode . t)))

Or a particular major mode (no quotes):

  (indent-tabs-mode . t)))
  • That was it. I could have guessed that the file in a path, and asking for a path was the fishy thing. Thanks!
    – Gauthier
    Mar 20, 2017 at 15:42

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.