Possible Duplicate:
In emacs, can I set up the *Messages* buffer so that it tails?
I am playing with Elisp, and I find convenient to have the *Messages* buffer always open in a window in my frame.
I discovered recently that sometimes the buffer stops following the last line in the file. If I want to see the last appended lines in this buffer, I need to go in the buffer and jump to the end manually, with M->. Which quite annoying and disruptive.
I am trying to reproduce the “tail -f” command line, in a buffer. Of course 'auto-revert-tail-mode complains that the *Messages* is not a visited file… As a consequence, this mode does not want to work. But it gave me the idea to add a function hook when the buffer is modified. That function would jump to (point-max) each time that buffer is modified.
Here is my own attempt, invoked from *Messages* buffer, with M-::
(add-hook 'after-change-functions (lambda (s e l) (goto-char (point-max)) nil) nil t)
But it does not work. The (point) remains in the same place while I see the buffer is growing… The lambda function does not produce any error, otherwise it would have been removed from the 'after-change-functions hook and C-h k 'after-change-functions shows it is present.
Any better suggestions?
Modifying the point position from
after-change-functionsis very dangerous anyway because it can break some types of edit to the buffer (for example, Emacs compresses multiple consecutive messages with the same content). However, for your purposes thepost-command-hookis more than sufficient and much safer, so you can just use this:The hook will make sure the point in
*Messages*is at the end of buffer after every command, unless you’re currently editing the*Messagesbuffer itself.