1

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?

  • What command are you using to save files? – Gilles 'SO- stop being evil' Jul 25 at 6:35
  • Dear Algebra, my first approach had a catch (see the edited answer). I've corrected that. Please adopt the changes in your init file. – Tobias Jul 25 at 9:32
2

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)

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.