I'm a very new user (~ 2 days) to Emacs. I switched from vim, because it wasn't working for me. I'm learning C++ and I've run into this issue when I write M-x compile. Upon writing this command, emacs always runs make -k on my small test program. However, I want it that emacs asks me what command to run for instance, in this example I want to run g++ program_ name -o output_name. Can anyone help me out?



Ask Emacs.

C-h f compile tells you:

Compile the program including the current buffer. Default: run make. Runs COMMAND, a shell command, in a separate process asynchronously with output going to the buffer *compilation*.

You can then use the command C-x ` to find the next error message and move to the source code that caused it.

If optional second arg COMINT is t the buffer will be in Comint mode with compilation-shell-minor-mode.

Interactively, prompts for the command if the variable compilation-read-command is non-nil; otherwise uses compile-command. With prefix arg, always prompts. Additionally, with universal prefix arg, compilation buffer will be in comint mode, i.e. interactive.

To run more than one compilation at once, start one then rename the *compilation* buffer to some other name with M-x rename-buffer. Then switch buffers and start the new compilation. It will create a new *compilation* buffer.

On most systems, termination of the main compilation process kills its subprocesses.

The name used for the buffer is actually whatever is returned by the function in compilation-buffer-name-function, so you can set that to a function that generates a unique name.

The part in bold tells you the answer: be sure that user option compilation-read-command is set to a non-nil value.

And if you click the compilation-read-command link in that *Help* output then you get even more information about its behavior:

Non-nil means M-x compile reads the compilation command to use. Otherwise, M-x compile just uses the value of compile-command.

Note that changing this to nil may be a security risk, because a file might define a malicious compile-command as a file local variable, and you might not notice. Therefore, compile-command is considered unsafe if this variable is nil.


You should get a prompt by default, unless you've set compilation-read-command to nil in your config.

What I always do is write a Makefile and use helm-make instead of compile.

  • Hey thanks, I used helm but then ended it removing it from my .emacs since it was getting more obstructive. Also do you write a Makefile for every C++ program you write? Jan 12 '16 at 9:48
  • Yes, every C++ program. They can be autogenerated, see ccc-run github.com/abo-abo/cc-chainsaw/blob/master/cc-chainsaw.el#L303
    – abo-abo
    Jan 12 '16 at 9:53
  • Hey I just went to the link, understanding it will require me to know more elisp. Can you tell me how to actually be more productive in elisp? Jan 12 '16 at 11:42
  • Go through the tutorial. Use M-x to access all built-in stuff, and eval-buffer to try new stuff. You won't learn it all in a day, but after some time investment it's really worth. Also have a look at SICP if you don't know any other LISP.
    – abo-abo
    Jan 12 '16 at 12:18
  • Oh yes I have worked through sicp, hence it was easy to write my .emacs. I'll just add your package to my emacs Jan 12 '16 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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