4

Every time, I save files, it prompts that

save files ..? (y, n !)

There are few cases that saving files are mistake operations.

How could disable the confirmation prompts?

Wizard
  • 1,251
  • 6
  • 17

1 Answers1

3

I assume you actually use save-some-buffers bound to the key sequence C-x s.

EDIT:

My first suggestion to add (setq-default buffer-save-without-query t) to your init file has a catch. Emacs tries to save also modfied non-file buffers with this setting and you are asked to input file names for such buffers.

It is better to keep the default value nil of buffer-save-without-query and to change the buffer local value in file buffers to t:

(defun set-buffer-save-without-query ()
  "Set `buffer-save-without-query' to t."
  (unless (variable-binding-locus 'buffer-save-without-query)
    (setq buffer-save-without-query t)))

(add-hook #'find-file-hook #'set-buffer-save-without-query)

;; The following avoids being ask to allow the file local
;; setting of `buffer-save-without-query'.
;; IMHO it is not a big risk:
;; The malicious code that must not be saved
;; should never be allowed to enter Emacs in the first place.
(put 'buffer-save-without-query 'safe-local-variable #'booleanp)

The doc string of buffer-save-without-query says:

Automatically becomes buffer-local when set.

Non-nil means `save-some-buffers' should save this buffer without asking.

If you have some buffer for which saving accidently is desastrous you can buffer-locally set buffer-save-without-query to nil. Your changes are not overwritten by set-buffer-save-without-query.

You can set buffer-save-without-query with file-local variables or in some mode hook.

Example for file-local settings: Add the following lines at the end of the file (you can also comment them out if that is important):

Local Variables:
buffer-save-without-query: nil
End:

Example for a mode hook:

(defun my-query-when-save ()
  "Set `buffer-save-without-query' to nil for this buffer."
  (setq buffer-save-without-query nil))

(add-hook 'emacs-lisp-mode-hook #'my-query-when-save)
Tobias
  • 33,167
  • 1
  • 37
  • 77