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?
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
delete-dir-local-variable to easily add and delete dir local values.
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.