From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.help Subject: Re: How to follow the end of *Messages* buffer in Emacs? Date: Sat, 10 Nov 2012 19:51:00 +0100 Message-ID: <509EA214.6030902@gmx.at> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1352573478 19718 80.91.229.3 (10 Nov 2012 18:51:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 10 Nov 2012 18:51:18 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Yves Baumes Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Nov 10 19:51:28 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TXG9Q-0005N8-2N for geh-help-gnu-emacs@m.gmane.org; Sat, 10 Nov 2012 19:51:28 +0100 Original-Received: from localhost ([::1]:34892 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TXG9G-0000jC-RK for geh-help-gnu-emacs@m.gmane.org; Sat, 10 Nov 2012 13:51:18 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:41500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TXG9A-0000i3-0z for help-gnu-emacs@gnu.org; Sat, 10 Nov 2012 13:51:15 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TXG96-0002Ww-VB for help-gnu-emacs@gnu.org; Sat, 10 Nov 2012 13:51:11 -0500 Original-Received: from mailout-de.gmx.net ([213.165.64.23]:52808) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1TXG96-0002Wq-LN for help-gnu-emacs@gnu.org; Sat, 10 Nov 2012 13:51:08 -0500 Original-Received: (qmail invoked by alias); 10 Nov 2012 18:51:07 -0000 Original-Received: from 62-47-50-62.adsl.highway.telekom.at (EHLO [62.47.50.62]) [62.47.50.62] by mail.gmx.net (mp069) with SMTP; 10 Nov 2012 19:51:07 +0100 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX19nGRZN9phnzeEbzGLoE/ghbvy9YMGMYJ6N/z9/8+ Q28lBVHSYfpKUQ In-Reply-To: X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 213.165.64.23 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:87632 Archived-At: > 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) If only everyone were as over-descriptive as you. The behavior you see is due to `quit-window' restoring the previous position of `window-point' for that window. This clearly backfires for the *Messages* buffer. Please file a bug report with your description. As an aside: The problem also happens with `switch-to-prev-buffer' and `switch-to-next-buffer' and it happens for all sorts of buffers where text is asynchronously inserted at the end as with shell buffers and the like. > 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. This would be tedious. We have to fix this in the window code. More precisely, we need a buffer local variable which when set and `window-point' equals `point-max' for that buffer at the time of saving the buffer's window's `window-point' (in your case that would be the time when the help buffer is displayed) we would store nil in the corresponding slot. When restoring the buffer in the window (via `quit-window' in your case) and we find that that slot contains nil, we'd use the buffer's `point' as new position of `window-point'. Thanks in advance for the bug report, martin