In emacs, can I set up the *Messages* buffer so that it tails?

前端 未结 6 735
借酒劲吻你
借酒劲吻你 2021-01-07 22:42

Basically I want the *Messages* buffer to always scroll to the bottom when a new message arrives.

Can I do that?

6条回答
  •  滥情空心
    2021-01-07 23:09

    Here's an amendment over Peter's / Trey's solutions

    (defun modi/messages-auto-tail (&rest _)
      "Make *Messages* buffer auto-scroll to the end after each message."
      (let* ((buf-name "*Messages*")
             ;; Create *Messages* buffer if it does not exist
             (buf (get-buffer-create buf-name)))
        ;; Activate this advice only if the point is _not_ in the *Messages* buffer
        ;; to begin with. This condition is required; otherwise you will not be
        ;; able to use `isearch' and other stuff within the *Messages* buffer as
        ;; the point will keep moving to the end of buffer :P
        (when (not (string= buf-name (buffer-name)))
          ;; Go to the end of buffer in all *Messages* buffer windows that are
          ;; *live* (`get-buffer-window-list' returns a list of only live windows).
          (dolist (win (get-buffer-window-list buf-name nil :all-frames))
            (with-selected-window win
              (goto-char (point-max))))
          ;; Go to the end of the *Messages* buffer even if it is not in one of
          ;; the live windows.
          (with-current-buffer buf
            (goto-char (point-max))))))
    (advice-add 'message :after #'modi/messages-auto-tail)
    

提交回复
热议问题