I want to use commands/keybindings to quickly view and scroll recent messages in the echo area, without visiting the Messages buffer. For example, suppose I received messages:

Time is 15:00:01
Time is 15:00:03
Time is 15:00:04
  • echo area displays: Time is 15:00:04
  • press key (eg. M-p)
  • echo area displays: Time is 15:00:03
  • press key (eg. M-n)
  • echo area displays: Time is 15:00:04

1 Answer 1


Here is a rudimentary attempt at such a thing,

(defun my:peek-messages (clear)
  (interactive "P")
  (when (or (not (bound-and-true-p my:messages-stack)) clear)
      (butlast (split-string
        (with-current-buffer "*Messages*"
          (buffer-string)) "\n"))))
  (let ((message-log-max nil))
    (message (car (last my:messages-stack))))
  (setq my:messages-stack (butlast my:messages-stack)))

Bind this to M-p and it does what you want. Now, there is a caveat. To make the function start displaying from the last message again, you have to C-u M-p. I. e., set the prefix argument.

  • 1
    I should be able to implement M-n having seen this. Nice use of (message-log-max nil) to stop messages being duplicated in the Messages buffer
    – user615536
    Dec 18, 2023 at 12:58

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.