To suppress messages in the code you write:
- problem of let-binding
inhibit-message to nil: current message is still cleared.
message-log-max to nil if you want to disable message logging in
(You can write a wrapper as suggested in @Haruyasu Ueda's answer)
To suppress messages from any single function:
(defun suppress-message-advice-around (fun &rest args)
(with-temp-message (or (current-message) "")
(apply fun args))))
;; example: suppress any messages from `save-buffer'
(advice-add 'save-buffer :around 'suppress-message-advice-around)
(advice-remove 'save-buffer 'suppress-message-advice-around)
(If you want to know where does a message come from: use
the original answer
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 ()
(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
If the first argument is nil or the empty string, the function clears
any existing message;
(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
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.
if you want to suppress the messages
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)
(message "meaningless") ; do nothing
(print [1 2 3]) ; not affected
(save-buffer)) ; won't display messages in minibuffer