all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yves Baumes <ybaumes@gmail.com>
To: martin rudalics <rudalics@gmx.at>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to follow the end of *Messages* buffer in Emacs?
Date: Sat, 10 Nov 2012 16:55:37 +0100	[thread overview]
Message-ID: <m2fw4hlafa.fsf@gmail.com> (raw)
In-Reply-To: mailman.12681.1352548591.855.help-gnu-emacs@gnu.org

martin rudalics <rudalics@gmx.at> writes:

>> 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
>> lines. 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 is
>> quite annoying and disruptive.
>
> Can you please tell us when and how this happens.  Here, when I display
> *Messages* in a window, I always see the last line but maybe something
> about my setup is peculiar.

I've tried and I think I've been able to reproduce. Let's split the
frame in two windows only, one for the *scratch* and the other for
*Messages*. From here you have a few lines only in the *Messages*
buffer. And untill now, every new lines introduced because of a command
output is followed. Moreover, I can see the "ghost" cursor at the end of
the buffer and it follows every *Messages* buffer updates.

Then, from the *scratch* buffer, I call the describe-variable key
sequence ( C-h v xxx ). The current buffer being *scratch*, the
*Messages* buffer will be replaced with the *help* buffer.

After finishing to read the description I want to quit it, because I
want the *Messages* buffer to come back. For that, I do: C-x o, thus
switching to the focus to the *Help* buffer, and I just type in 'q' to
quit it and instantly focus back to the *scratch* buffer.

But: When I look into the *Messages* buffer, the "ghost" cursor is no
longer at the same place. It has moved in the middle of the buffer. From
there, the window position relative to the buffer remains the same.

(Hum.. I am being over-descriptive here, but I am trying to compensate
my low level in english)

>> 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 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.
>
> The (goto-char (point-max)) just sets `point' in that buffer.  It does
> not care whether the buffer is currently displayed in a window.  You
> have to use something like
>
>   (walk-windows
>    (lambda (w)
>      (when (eq (window-buffer w) (current-buffer))
>        (set-window-point w (point-max))))))

Ok, I suppose that, indeed, set-window-point is more appropriate.

I've been able to make the whole stuff work, thanks to the various
remarks. Since I was trying to automate the whole stuff I decided not to
go in the macro direction. Here is the code:

(defun tail-f-msgs ()
  "Go to the enf of Messages buffer."
  (let ((msg-window (get-buffer-window "*Messages*")))
    (if msg-window
        (with-current-buffer (window-buffer msg-window)
          (set-window-point msg-window (point-max))))))

;; Make the Messages buffer stick to the end.
(add-hook 'post-command-hook 'tail-f-msgs)

Of course with that the *Messages* buffer is no longer editable, or you
can browse it to see older lines. Next fix: make a variable to the
follow mode.


> within that function.
>
> martin



       reply	other threads:[~2012-11-10 15:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.12681.1352548591.855.help-gnu-emacs@gnu.org>
2012-11-10 15:55 ` Yves Baumes [this message]
     [not found] ` <m2bof5l4lx.fsf@gmail.com>
2012-11-10 18:51   ` How to follow the end of *Messages* buffer in Emacs? martin rudalics
     [not found]   ` <mailman.12702.1352573476.855.help-gnu-emacs@gnu.org>
2012-11-10 19:56     ` Yves Baumes
2012-11-10 21:02       ` martin rudalics
     [not found]       ` <mailman.12713.1352581388.855.help-gnu-emacs@gnu.org>
2012-11-10 22:00         ` Yves Baumes
2012-11-12  9:56           ` martin rudalics
2012-11-10 22:24         ` Yves Baumes
2012-11-11 17:25     ` Stefan Monnier
2012-11-12  9:57 martin rudalics
  -- strict thread matches above, loose matches on Subject: below --
2012-11-10 11:56 martin rudalics
2012-11-09 22:52 Yves Baumes
2012-11-10  6:39 ` B. T. Raven
2012-11-10 10:07 ` Peter Dyballa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2fw4hlafa.fsf@gmail.com \
    --to=ybaumes@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.