0

This question already has an answer here:

I'm attempting to suppress certain minibuffer messages, but can't seem to get my configuration to work. There are two stack exchange answers that address this (here and here) and both suggest using a let-binding.

For instance, I've tried running emacs -Q and in the *scratch* buffer using this:

(let ((inhibit-message t))
  (message "End of buffer"))

Then, I evaluate the expression with C-x C-e and cursor down, but I still see End of buffer in the minibuffer. What seems even stranger to me is that running C-x C-e in the first place also caused the string to appear in the minibuffer even though inhibit-message is locally non-nil.

On a related note, I don't understand on a theoretical level how the let form would achieve the desired affect here. As I understand it, when the let expression is encountered inhibit-message is locally bound to t and then the message function is called with the string argument, which would have no effect on the minibuffer since inhibit-message is non-nil (which is apparently wrong because C-x C-e causes the message to appear). However, when this same message is called another time, I don't see why the message should be suppressed. This expression doesn't cause all calls to (message "End of buffer") to be evaluated within this let does it? If so, how does it? Am I missing the mechanism entirely?

marked as duplicate by Drew, DoMiNeLa10 Apr 12 at 16:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I don't understand how this is a duplicate of the linked question. My main question here is how to inhibit certain annoying messages from appearing in the minibuffer. The part about the operation of C-x C-e and let was a side question asked to better understand how the primary goal could be achieved. – MattHusz Apr 12 at 17:47
3

Your confusion is on account of using C-xC-e

C-x C-e runs the command eval-last-sexp (found in global-map), which is an interactive compiled Lisp function in ‘elisp-mode.el’.

It is bound to C-x C-e.

(eval-last-sexp EVAL-LAST-SEXP-ARG-INTERNAL)

Evaluate sexp before point; print value in the echo area. Interactively, with a non ‘-’ prefix argument, print output into current buffer.

What you are seeing in the echo area is not the normal message display (which was inhibited), but the return value of the form you have evaluated:

(let ((inhibit-message t))
  (message "End of buffer"))

In this case the return value will be that of the final form of the let expression, which is the call to message:

message is a built-in function in ‘C source code’.

(message FORMAT-STRING &rest ARGS)

Display a message at the bottom of the screen. The message also goes into the ‘Messages’ buffer, if ‘message-log-max’ is non-nil. (In keyboard macros, that’s all it does.) Return the message.

As indicated by the eval-last-sexp docstring, if you use a prefix arg the return value will be inserted into the buffer rather than displayed in the echo area; so you can test this with:

C-uC-xC-e


On a related note, I don't understand on a theoretical level how the let form would achieve the desired affect here.

We don't know what your desired effect is.

As I understand it, when the let expression is encountered inhibit-message is locally bound to t and then the message function is called with the string argument, which would have no effect on the minibuffer since inhibit-message is non-nil [...] However, when this same message is called another time, I don't see why the message should be suppressed. This expression doesn't cause all calls to (message "End of buffer") to be evaluated within this let does it?

I think you've understood correctly.

(let ((inhibit-message t))
  (message "End of buffer"))

affects that one single call to message

If you subsequently call (message "End of buffer") outside of that let form, that subsequent message is not inhibited.

  • My desired effect is that I'd like to prevent End of buffer from ever being displayed in the minibuffer, but allow it to display in the *Messages* buffer, per normal. If this won't do that, is there another way to achieve that effect? – MattHusz Apr 12 at 8:47
  • To do that with inhibit-message you'd need to cause it to be non-nil whenever the code which generated that message was evaluated. – phils Apr 12 at 8:49
  • 2
    @MattHusz See this answer – muffinmad Apr 12 at 8:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.