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?

Connor
  • 1,591
  • 1
  • 19
  • 26
  • 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 05 '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 05 '14 at 16:48
  • I see. Posted the comment above before checking the edit you made to your question ;) – itsjeyd Oct 05 '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

3 Answers3

7

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

(setq compile-command "make package install")
itsjeyd
  • 14,586
  • 3
  • 58
  • 87
  • 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
3

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.

Iqbal Ansari
  • 7,468
  • 1
  • 28
  • 31
1

If you want to customize the compile command per file here is an example:

---
title: Svadhyaya
---

Svadhyaya (Sanskrit: स्वाध्याय svādhyāya m.; *self-study*) is one of the five
Niyamas (Sanskrit: नियम niyama m.; *commandments*, *restrictions*, 
*ethical rules*, *code of conduct* in Patanjalis Yogasutra). The word is 
made up of Sva (*self*, *belonging to me*) and Adhyaya (*investigation*,
*exploration*) together.

<!--
Local Variables:
mode: markdown
coding: utf-8-unix
compile-command: (string-join
    (list "pandoc" "-s" (buffer-file-name) "-o"
        (concat (file-name-sans-extension (buffer-file-name)) ".html")) " ")
End:
-->

That looks a bit awkward, but this way no dependencies to other files that may control the compilation exist (Makefile, CMakeLists.txt... not even your personal dot-emacs). So you can send the file out or unpack it years later and compile it should still work.

File-Local Variables