I usually setup a nontrivial compile command, then frequently call 'recompile. Is there a way to suppress the prompt for saving files similar to the approach in auctex invoked with (setq TeX-save-query nil)? I find it very annoying to always have to save manually, or press y at the prompt. When I hit recompile, I want all files saved if necessary.

1 Answer 1

compilation-ask-about-save is a variable defined in `compile.el'.
Its value is t

Non-nil means M-x compile asks which buffers to save before compiling.
Otherwise, it saves all modified buffers without asking.

You can customize this variable.

Here is the function recompile, which demonstrates that it also uses the variable compilation-ask-about-save:

(defun recompile (&optional edit-command)
  "Re-compile the program including the current buffer.
If this is run in a Compilation mode buffer, re-use the arguments from the
original use.  Otherwise, recompile using `compile-command'.
If the optional argument `edit-command' is non-nil, the command can be edited."
  (interactive "P")
  (save-some-buffers (not compilation-ask-about-save)
  (let ((default-directory (or compilation-directory default-directory))
    (command (eval compile-command)))
    (when edit-command
      (setq command (compilation-read-command (or (car compilation-arguments)
      (if compilation-arguments (setcar compilation-arguments command)))
    (apply 'compilation-start (or compilation-arguments (list command)))))

See also the doc-string for save-some-buffers -- "Optional argument (the prefix) non-nil means save all with no questions."

save-some-buffers is an interactive compiled Lisp function in

It is bound to C-x s.

(save-some-buffers &optional ARG PRED)

Save some modified file-visiting buffers.  Asks user about each one.
You can answer `y' to save, `n' not to save, `C-r' to look at the
buffer in question with `view-buffer' before deciding or `d' to
view the differences using `diff-buffer-with-file'.

This command first saves any buffers where `buffer-save-without-query' is
non-nil, without asking.

Optional argument (the prefix) non-nil means save all with no questions.
Optional second argument PRED determines which buffers are considered:
If PRED is nil, all the file-visiting buffers are considered.
If PRED is t, then certain non-file buffers will also be considered.
If PRED is a zero-argument function, it indicates for each buffer whether
to consider it or not when called with that buffer current.

See `save-some-buffers-action-alist' if you want to
change the additional actions you can take on files.
  • For the impatient: I put (setq compilation-ask-about-save nil) into my .emacs and it works. Aug 20, 2014 at 9:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .