how to silently "Save All Buffers" in Emacs?
emacs
Solution
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)
Problem
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?