Emacs: mute messages (“echo area”)

elispemacslisp

I do lots of automatizing in Emacs, by stacking commands that I know from using manually. That is a method I recommend, because it doesn't take much effort: you use Emacs as you ordinarily would, and now and then it pops to your head, "hey, I'm always using those commands in succession, why don't I just merge them?" All the more simple since you know the commands, by name or shortcut.

One problem, though, is that when you stack commands, you get lots of messages flashing by in the "echo area" (same place as the minibuffer). Those messages don't make any sense, as everything going on below (the functions invoked) is (should be) transparent to the user.

So, could you mute it, and then unmute it? Take a look below:

(defun invisible-pretty-mail ()
  "Automatize `pretty-mail'."
  (interactive)
  ; (mute-echo-area)
  (rmail-edit-current-message)
  (pretty-mail) ; lots of replace-string, replace-regexp, etc. here
                ; that will flood messages
  (rmail-cease-edit)
  ; (unmute-echo-area)
  )

Edit in response to sds' answer:

I'm very much aware of those notes you refer to, as they are very common in the Emacs help system.

While your advice is not incorrect in general, let us examine this particular situation in greater detail: 1) There is an Elisp function in .emacs. 2) It uses commands that the person who setup the function is very familiar with, so it is very readable and maintainable. 3) The function works exactly as intended, with 4) the one drawback that it echos too many messages.

Now, in this situation, would you really suggest a complete rewrite of that function (and many others), using altogether different commands, commands that may or may not exist, as a possible way of reducing messages, which we won't even know will happen?

Edit: An example (that works), after the help I got from Drew.

(defun test-suppress-msgs ()
  (interactive)
  (let ((log-size message-log-max))
    (setq message-log-max nil)
    (message "This message is suppressed.")
    (setq message-log-max log-size)
    (message "This is echoed, and logged.") ))

Best Answer

Binding message-log-max to nil suppresses messages for the duration of the (dynamic) binding.

Binding echo-keystrokes to 0 suppresses echoing of keystrokes.

Starting with Emacs 25.1, you can also bind (or set) variable inhibit-message to non-nil, to prevent most echo-area messages (but not prevent those messages from being logged in buffer *Messages*).

Related Question