I am working on a cmake project and I would like to set a directory variable containing the correct compile command. I added this to the root directory of the project in a .dir-locals.el file:

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

((nil .
      ((indent-tabs-mode . t)
       (fill-column . 80)
       (compile-command . "cd build && make"))))

If I enter describe-variable for the variable fill-column, I get the message that This variable's value is directory-local, set by the file .... The variable is set from its default of 70 to 80 instead. However, the compile-command variable is unchanged. Is there a bug in the file?


The variable compile-command is not buffer local by default, thus you can not set it per buffer. To change this add the following to your init file:

(make-variable-buffer-local 'compile-command)

I believe the compilation command and its history in the majority of cases should be directory local rather than buffer local.

To accomplish this, I've been planning for quite some time to modify the behavior of compilation-read-command to automatically read the value of compile-command and compile-history if present in the file .dir-locals.el under default-directory. Has anybody else tried this?

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.