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.

ideasman42
  • 8,375
  • 1
  • 28
  • 105

1 Answers1

0

(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.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • 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 Jan 31 '22 at 05: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 Jan 31 '22 at 14:54
  • 1
    (BTW, it's generally better to use named, not anonymous, functions in hooks.) – Drew Jan 31 '22 at 14:55