Emacs: command set command for each buffer

so suppose I have a file.c file and anothr.c file. I would like to set the compilation command for each of these files separately, say: gcc -Wall -O3 -of file.c and gcc -Wall -std=c99 -oa another.c . How can I set the gcc command for this buffer so that every time I open it, it knows how to compile it? Is there something with the // -*- directive or something like that? Thanks.

+4
source share
2 answers

Yes, you can use the directive in the file, as well as set a different value. Try this on line one or two:

 // -*- compile-command: "gcc -Wall -O3 -of file.c" -*- 

and then reload the file using Cx v for this option to take effect.

Sometimes I also add things like c-indent-level: 4; c-basic-offset: 4; c-indent-level: 4; c-basic-offset: 4; .

+4
source

What you are looking for is called the local variables of the file , and sometimes just “local variables”, for the declarative format in the commentary described here .

In addition to the syntax specified in the Dirk answer, you can write a "local variables" block at the end of your file:

 /* Local Variables: */ /* compile-command:"gcc -Wall -O3 -of file.c" */ /* End: */ 

You can use the add-file-local-variable interactive function to maintain this list if you do not want to enter each entry manually.

+3
source

Source: https://habr.com/ru/post/1333487/


All Articles