Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to silently "Save All Buffers" in Emacs?

Tags:

emacs

How do I create a command to "Silently Save All Buffers" in Aquamacs Emacs?

I found the command save-some-buffers which is nice, but the problem is that it prompts me, separately, to confirm every buffer I want to save.

Through Googling I found some documentation on a variable called save-silently-p but that doesn't seem to exist (in Aquamacs version 2.4, i.e. Emacs 23.3.50.1).

So how do I get it to save all buffers silently without prompting?

like image 389
incandescentman Avatar asked Mar 06 '13 17:03

incandescentman


People also ask

How do I close all buffers in Emacs?

M-x kill-matching-buffers. Offer to kill all buffers matching a regular expression. C-x k ( kill-buffer ) kills one buffer, whose name you specify in the minibuffer. The default, used if you type just RET in the minibuffer, is to kill the current buffer.

What is the Emacs command to save a file?

1) Saving Files in Emacs Emacs allows you to save the contents to the current buffers by hitting the keys Ctrl + x followed by Ctrl + s. Users can also save the current buffer to some other file name by hitting the keys Ctrl + x, followed by Ctrl + w.

What are buffers in Emacs?

Buffers in Emacs editing are objects that have distinct names and hold text that can be edited. Buffers appear to Lisp programs as a special data type. You can think of the contents of a buffer as a string that you can extend; insertions and deletions may occur in any part of the buffer.


3 Answers

There's no need to set any custom variables, you simply:

C-u C-x s

Or in long-hand:

Ctrl+u Ctrl+x s

In addition you can just do, C-x s and press ! at the prompt answer yes to for all saveable file buffers. Which isn't strictly silent, but it's still very fast/unobstrusive. (credit: @phils)

like image 140
ocodo Avatar answered Oct 23 '22 05:10

ocodo


If you pass non-nil to save-some-buffers it will save all files without prompting, so you can do something like

(defun save-all () (interactive) (save-some-buffers t))
(global-set-key (kbd "C-S") 'save-all)
like image 31
Brian Burns Avatar answered Oct 23 '22 05:10

Brian Burns


In this example, the first argument is set to a non-nil value -- "[o]ptional argument (the prefix) non-nil means save all with no questions." Although it could be just plain old t, I chose to make up a more meaningful symbol to remind myself of what it stands for -- i.e., 'no-confirm. If I wanted to receive a confirmation dialog, then I would instead use nil for the first argument. See the doc-string -- M-x describe-function RET save-some-buffers RET -- for additional information regarding how this function behaves depending upon whether the first argument is nil or non-nil.

The example below uses save-some-buffers with a custom zero argument function for the second argument -- i.e, PRED -- to choose which buffers should be saved. The doc-string for save-some-buffers states that the second argument -- i.e., PRED -- may be one of three possibilities -- (1) If PRED is nil, all the file-visiting buffers are considered; (2) If PRED is t, then certain non-file buffers will also be considered; or (3) If PRED is a zero-argument function, it indicates for each buffer whether to consider it or not when called with that buffer current.

The example uses a keyboard shortcut of f5, but the user is free to call this custom function interactively -- M-x my-save-some-buffers -- or assign a different keyboard shortcut entirely. There are a few possible matches that have been hard-coded, and the user is free to add/remove/modify the conditions:

•  file-visiting-buffer + the file name matches the value of the variable abbrev-file-name.

• file-visiting-buffer + the major-mode is latex-mode from the built-in tex-mode.el -- not AUCTeX.

• file-visiting-buffer + the major-mode is markdown-mode.

• file-visiting-buffer + the major-mode is emacs-lisp-mode.

• file-visiting-buffer + the derived-mode is org-mode.

(defun my-save-some-buffers ()
(interactive)
  (save-some-buffers 'no-confirm (lambda ()
    (cond
      ((and buffer-file-name (equal buffer-file-name abbrev-file-name)))
      ((and buffer-file-name (eq major-mode 'latex-mode)))
      ((and buffer-file-name (eq major-mode 'markdown-mode)))
      ((and buffer-file-name (eq major-mode 'emacs-lisp-mode)))
      ((and buffer-file-name (derived-mode-p 'org-mode)))))))

(global-set-key [f5] 'my-save-some-buffers)
like image 5
lawlist Avatar answered Oct 23 '22 06:10

lawlist