1

In this example, the message isn't shown, but it's still logged (message-log-max is ignored).

(let ((inhibit-message t)
      (message-log-max nil))
  (hs-minor-mode))

The text Showing all blocks ... done is shown in the *Messages* buffer.


However, this overrides message-log-max as expected.

(let ((inhibit-message t)
      (message-log-max-orig message-log-max))
  (setq message-log-max nil)
  (hs-minor-mode)
  (setq message-log-max message-log-max-orig))

Why isn't the first example working? I've found let-binding message-log-max works in other contexts.

1 Answer 1

1

(You can just replace your (hs-minor-mode) to show the same effect, BTW.)

You're getting fooled by the echoing of the result of evaluation provided by a command such as C-x C-e or M-:.

Calls to message etc. within the let are NOT logged. But if you use something like C-x C-e to evaluate your code then that command echoes the result of evaluating, and that echoing happens after the let.

In your second example, what gets echoed by C-x C-e is the result of evaluating the last sexp in the let, which is the second setq, which produces a numeric result (probably 1000). That is, for the second example, you see 1000 logged, but not your message -- because the call to message (or hs-minor-mode) is not the last thing evaluated, so the message isn't returned as a result and isn't echoed by C-x C-e.

3
  • Note sure about C-x C-e or M-: - this is running from a (add-hook 'after-change-major-mode-hook (lambda () ... )) (from my init file).
    – ideasman42
    Commented Jan 31, 2022 at 5:55
  • Are you sure what you think is happening is happening? What happens if you add another sexp after your call to hs-minor-mode' in your first snippet? E.g. M-: (let ((inhibit-message t) (message-log-max nil)) (message "AA") 42)` shows only 42 in *Messages*, as that's the result of evaluating.
    – Drew
    Commented Jan 31, 2022 at 14:54
  • 1
    (BTW, it's generally better to use named, not anonymous, functions in hooks.)
    – Drew
    Commented Jan 31, 2022 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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