When I save my any file I am working on I always see following message, I believe this is related to my unto-tree configuration.

Wrote /home/alper/.emacs.d/undo/.!home!alper!current_folder!__init__.py.~undo-tree~

[Q] Is it possible suppress this message (saving undo-tree) somehow?

My config file:

(global-undo-tree-mode 1)
(setq undo-tree-auto-save-history t)
(setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo")))

(defmacro with-suppressed-message (&rest body)
  "Suppress new messages temporarily in the echo area and the `*Messages*' buffer while BODY is evaluated."
  (declare (indent 0))
  (let ((message-log-max nil))
    `(with-temp-message (or (current-message) "") ,@body)))

(defun save-all ()
  ;(save-some-buffers t)
  (with-suppressed-message (save-some-buffers t))
  (message "")


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 ()
                       (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
  • I have added the code but still I am facing with the same issue :-( Should I remove (setq undo-tree-auto-save-history t)? – alper Aug 4 '20 at 1:54
  • Sorry there were problems with the initial tests -- when you get a chance, please feel free to try out the latest revised answer. – lawlist Aug 4 '20 at 4:50
  • Thank you for depth answer. I cannot use F* keys in emacs. Can I bind [f5]'s behavior into C-x C-s ? I have defined the functions as follows: gist.github.com/avatar-lavventura/… // I have tried with my emacs --daemon and it works – alper Aug 4 '20 at 12:36
  • 1
    Here is an example of how to rebind C-x C-s to your liking and also demonstrates how to convert my lambda example into a separate function: (defun my-save-all () "My doc-string." (interactive) (let ((message-log-max nil) (inhibit-message t)) (save-some-buffers t))) (define-key ctl-x-map "\C-s" 'my-save-all) – lawlist Aug 4 '20 at 13:03

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.