undo-tree-save-history
calls write-region
. In this example, we suppress the Wrote ...
message entirely using an :around
advice. Here are the steps used to verify the answer works as advertised:
STEP 1: Launch a recent public release of Emacs 26.3 -- without any user-configuration, aka emacs -Q
STEP 2: Download the library undo-tree, which was last updated 01/29/2020 from the following link: https://elpa.gnu.org/packages/undo-tree-0.7.4.el
STEP 3: From within Emacs, open the newly downloaded und-tree library file and then type M-x eval-buffer
STEP 4: Create a new file-visiting-buffer by typing M-x find-file
or its keyboard shortcut equivalent C-x C-f
and give it a filename using a path to a working directory (where there is nothing of critical importance); e.g., ~/Desktop/scratch.el
. Assuming that the file was new, there will be a message in the echo-area as follows: (New file)
. Now, write the file to the hard-drive by typing M-x save-buffer
or use the keyboard shortcut equivalent of C-x C-s
. The message in the echo area at this point will be something similar to: Wrote /Users/HOME/Desktop/scratch.el
Step 5: Copy the following snippets in the code-block directly below and paste them into the file-visiting-buffer described in the step immediately above; e.g., paste everything into the file-visiting-buffer ~/Desktop/scratch.el
. Now, type M-x eval-buffer
. Do NOT save the file at this time -- i.e., leave the file-visiting-buffer in a modified state.
(global-undo-tree-mode 1)
(setq undo-tree-auto-save-history t)
(setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo")))
(defun my-undo-tree-save-history (undo-tree-save-history &rest args)
(let ((message-log-max nil)
(inhibit-message t))
(apply undo-tree-save-history args)))
(advice-add 'undo-tree-save-history :around 'my-undo-tree-save-history)
(global-set-key [f5] (lambda ()
(interactive)
(let ((message-log-max nil)
(inhibit-message t))
(save-some-buffers t))))
STEP 6: At this point in time, the file-visiting-buffer (e.g., ~/Desktop/scratch.el
) should still be in a modified state. Now, let us test out the newly defined keyboard shortcut by pressing the f5
key. Watch the mode-line closely -- i.e., when we press the f5
key, the far-left of the mode-line will change from modified -:**-
to unmodified -:---
. However, we should not have seen anything appearing in the echo area related to pressing the above-mentioned key.
STEP 7: Switch to the *Messages*
buffer and see what is there:
For information about GNU Emacs and the GNU system, type C-h C-a.
You can run the command ‘eval-buffer’ with M-x ev-b RET
(New file)
Wrote /Users/HOME/Desktop/scratch.el
Mark set
You can run the command ‘eval-buffer’ with M-x ev-b RET