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
?
3 Answers
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.– nispioCommented Oct 12, 2014 at 14:12
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
anddelete-dir-local-variable
.– clemeraCommented Sep 4, 2015 at 10:10 -
@hatschipuh, good suggestion updated the answer to mention these commands Commented Sep 6, 2015 at 16:19
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.
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 doC-u M-x compile
; in this case, you will be prompted for the command regardless of the value ofcompilation-read-command
.