问题
Suppose I have two code files, one is a small test script, the other is my main piece of code (both are c++ code files). I would like emacs to use different compilation commands for each of them (for example "make test_script" for one and "make release" for the other). What's the best way to do this?
回答1:
You can use the compile-command
local variable to the buffer. For instance, in one C++ source code:
// Local Variables:
// compile-command: "make release"
// End:
and you can change that in the other source code to use the other means of compilation. To trigger that compilation, you can use M-xcompileRET.
As per your question, if you don't want compile
to ask you, you can add the following:
// Local Variables:
// compilation-read-command: nil
// compile-command: "make release"
// End:
However, you will be warned when you load the file that this variable is risky. You can accept it, but note that this means that this can cause arbitrary commands to be run by error when you just compile with a loaded file of unknown source (that is, if you get a file somewhere that have these commands and you just accept them, when you compile the file will execute any program of your own without asking you first.)
来源:https://stackoverflow.com/questions/7380240/how-do-i-get-emacs-to-change-the-compilation-command-on-a-per-buffer-basis