When M-x compile and specifying a compilation command, where is this command stored?

I'd like to use whatever it's stored to, in a function to quickly compile, instead of being prompted for the compile command.

(defun my-build ()
  (compile "variable"))

2 Answers 2


First, you can specify per-buffer compilation commands using the "local variables" section or hooks. See the docstring of compile-command variable. The default is "make -k ". Here is what I have for an example .c file.

// Local Variables:
// compile-command: "gcc cpp10.c -o cpp10 -lm "
// End:

Emacs will now autofill the "Compile command" with the above string whenever you visit the buffer and run compile, and you just need to confirm.

You can invoke "M-x recompile" to reuse the last compilation command and completely avoid the confirmation prompt. The variable compile-command is updated to reflect the last used compilation command. The information does not persist across Emacs sessions.


When I run C-h f compile, it shows a link to the code. Clicking that links opens the file in Emacs. Reading the code, I see, as Swarnendu did, that compile-command is the variable the code uses to save the compile command. Using C-h v compile-command shows useful information about compile-command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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