0

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 ()
""
(interactive)
  (compile "variable"))
Jason Hunter
  • 709
  • 4
  • 10

2 Answers2

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.

Swarnendu Biswas
  • 1,450
  • 1
  • 12
  • 25
1

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.