开发者

What is the most efficient way to run programs in Emacs after M-x compile 'ing

I have started using M-x compile to compile programs in say, C.

What is the most efficient way to run the executable e.g. a.out. At the moment I'm using M-! ./a.out. Basically, what is the best code-compile-run procedure to follow?

Almost al开发者_开发知识库l the tutorials mention how compilation is done, but I haven't seen one which addressed this issue?

Thanks, Samuel


I often just append the run command at the end of the build:

M-x compile RET gmake && ./a.out

The && will tell the shell to only invoke a.out when the compilation is successful.

Though I often run the program from an existing shell buffer (M-x shell), or from one of many shells that I manage with package very much like screen.


I use the extension smart-compile+, it allows you to specify quite convenient rules depending on the name of the file/buffer you are editing. For example, in my .emacs I specify the following rule for when running smart-compile in a project euler file:

(add-to-list 'smart-compile-alist
         '("euler.*\\.[Cc]+[Pp]*$" . "g++ -O2 -Wall -pedantic -Werror -Wreturn-type %f -lm -lgmpxx -lgmp -o ../bin/%n && time ../bin/%n")
         )

First you specify the filename pattern for the rule, then the path where it should be executed, then the compile command. In the above case, I add && time ../bin/%n to run the program directly after it has been successfully compiled.


My first choice is for interactive development; code, load files into the REPL, resolve errors (With C-x `, just as with M-x compile), and then play with the code in the REPL.

If that's not an option, I use eshell as a generic REPL. Compile, switch to eshell, run, test, repeat.


Add a rule to your makefile to compile and run your program, so M-x compile will compile and run, test, valgrind-test... whatever

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜