开发者

How do I get emacs to change the compilation command on a per-buffer basis?

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 (fo开发者_开发技巧r example "make test_script" for one and "make release" for the other). What's the best way to do this?


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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜