Emacsで*Messages*バッファを自動スクロール

ネタ元はstackoverflowのIn emacs, can I set up the *Messages* buffer so that it tails?です。

たいへん便利だったので、日本語で検索するひと用に紹介しておきます。

(defun modi/messages-auto-tail (&rest _)
 "Make *Messages* buffer auto-scroll to the end after each message."
 (let* ((buf-name "*Messages*")
        (buf (get-buffer-create buf-name)))
   (when (not (string= buf-name (buffer-name)))
     (dolist (win (get-buffer-window-list buf-name nil :all-frames))
       (with-selected-window win
         (goto-char (point-max))))
     (with-current-buffer buf
       (goto-char (point-max))))))
(advice-add 'message :after #'modi/messages-auto-tail)

ジャンル: Emacs