8

In one of my projects I need to run make package install when building instead of make. It remembers the last compile command I used, but resets to make -k every time emacs starts up. How can I customize M-x compile to default to make package install?

  • What's the value of compilation-read-command? If this variable is set to a non-nil value, M-x compile should prompt you for the compilation command to use. Alternatively, you can do C-u M-x compile; in this case, you will be prompted for the command regardless of the value of compilation-read-command. – itsjeyd Oct 5 '14 at 16:45
  • 1
    It's set to t. It does allow me to edit the command before running, but I'd like to change what it defaults to – Connor Oct 5 '14 at 16:48
  • I see. Posted the comment above before checking the edit you made to your question ;) – itsjeyd Oct 5 '14 at 16:51
  • A good question. From the manual, I had the impression that one can add "compile: ..." or "compile-command: ..." in the "Local Variables:" section at the end of a file, but my new Emacs doesn't seem to pay any attention to them... :( – imz -- Ivan Zakharyaschev Jan 23 '15 at 18:51
7

You can customize the variable compile-command to change the compilation command that is used by default:

(setq compile-command "make package install")
  • Note that the first time you run a compile command that is not make package install, that new command will become your new default. – nispio Oct 12 '14 at 14:12
2

If you want to customize the variable per project rather than globally. You can use Directory Variables. These allow you to apply certain customizations only for files in certain directory and its subdirectories.

So for example you want to use the make package install as compile command only in project A, you will need to create a file named .dir-locals.el in root directory of the project and add something like the following

((nil . ((compile-command . "make package install"))))

The syntax is explained in detail in the link to emacs manual above. As pointed out by @hatschipuh, you can use the commands add-dir-local-variable and delete-dir-local-variable to easily add and delete dir local values.

  • For convenience there are the commands add-dir-local-variable and delete-dir-local-variable. – clemera Sep 4 '15 at 10:10
  • @hatschipuh, good suggestion updated the answer to mention these commands – Iqbal Ansari Sep 6 '15 at 16:19

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.