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

五迷三道 提交于 2020-01-07 06:37:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!