Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I try not to cross-post, but the only response I got at stack-exchange was to post here...

What's the preferred practice for a compile-run cycle in emacs?

Previously, I used alt-x compile (mapped to F12) with make as my compile command. Within the Makefile I had an entry which would run the program that was compiled. This worked fine when my programs were non-interactive, but the compilation buffer is non-interactive.

Of course I could open a shell and run the executable, but I'd like to automate the compile-run cycle as much as possible and I assume there must be a standard practice for this and I'm guessing my executing-from-the-makefile method is a kluge...

C-u F12 works, but I'm wondering if that's the best approach for doing this (and if so, how can I bind F12 to be equivalent to C-u alt-x compile instead of just alt-x compile?).

share|improve this question
add comment

1 Answer

Here's how I do it:

  1. Use emacs in completely default settings. No special key bindings.
  2. Open terminal (and keep it open) and type "make" in it for compilation.
  3. for executing the program, ./main seems to be the most common way for me
  4. editing a new file is either c-x c-f, or most commonly in terminal "emacs foo.cc"
  5. Move mouse cursor between emacs window and terminal window depending on whether you want to edit or compile
  6. This approach has several advantages: several emacs instances are possible without confusing which window is meant for compilation, and no .emacs file copying is required when you move from one computer to next and debugging with valgrind or gdb is also easy when terminal window is open

  7. Unfortunately there is exception to nice rule of no special key bindings. goto-line is so important feature that it needs to be bind to key c-x g and c-c g.

I mostly use the following commands from emacs:


C-x c-f find a file
C-x C-s save a file
esc-<   beginning of file, 
C-s     search
c-x c-c exit emacs
c-x 2   split screen
c-x 0   remove split screen
c-x b   switch to another buffer
C-k     kill line
C-y     yank
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.