Just clear the minibuffer afterward.
Don't need to suppress, just clear the minibuffer afterward, if you just don't want to see the message showing in minibuffer.
(defun clear-message ()
(message nil))
(advice-add 'real-auto-save-buffers :after 'clear-message)
;; replace `real-auto-save-buffers' with the function whose messages
;; should not show in the minibuffer.
From the manual of message
:
If the first argument is nil or the empty string, the function clears
any existing message;
Basically, what (message nil)
does is clearing the current message from the echo area, and it doesn't affect the messages in *Messages*
. It works out well when you don't want to see the annoying messages keep showing in the minibuffer.
And, a good thing is, when you are editing the minibuffer (e.g M-x
or find-file
) and a message shows up, normally you need to type something to make the message disappear. If (message nil)
is called, the message will disappear immediately and you can see the original content of the minibufer.
In general, if you don't want to see a particular function showing messages in the minibuffer, you don't need to suppress the messages when it is called, just call (message nil)
afterward to clear the current message in minibuffer.
Bonus: if you really want to suppress the messages...
Replacing the message
function temporarily is much more straight forward:
(defmacro no-message (&rest body)
"Eval BODY, with `message' doing nothing."
`(cl-letf (((symbol-function 'message)
(lambda (&rest args)
nil)))
(progn ,@body)))
(no-message
(message "meaningless") ; do nothing
(print [1 2 3]) ; not affected
(save-buffer)) ; won't display messages in minibuffer
(let (message-log-max) (save-buffer))
to disable all messages duringsave-buffer
. – xuchunyang Aug 13 '15 at 7:40