From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Yves Baumes Newsgroups: gmane.emacs.help Subject: Re: How to follow the end of *Messages* buffer in Emacs? Date: Sat, 10 Nov 2012 16:55:37 +0100 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1352575133 31899 80.91.229.3 (10 Nov 2012 19:18:53 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 10 Nov 2012 19:18:53 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: martin rudalics Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Nov 10 20:19:04 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 1TXGa7-0008AI-Cz for geh-help-gnu-emacs@m.gmane.org; Sat, 10 Nov 2012 20:19:03 +0100 Original-Received: from localhost ([::1]:43063 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TXGZx-0007q1-Rl for geh-help-gnu-emacs@m.gmane.org; Sat, 10 Nov 2012 14:18:53 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:45076) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TXDPP-0000cL-JL for help-gnu-emacs@gnu.org; Sat, 10 Nov 2012 10:55:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TXDPM-0002cL-FI for help-gnu-emacs@gnu.org; Sat, 10 Nov 2012 10:55:47 -0500 Original-Received: from mail-we0-f169.google.com ([74.125.82.169]:51300) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TXDPM-0002c3-8R for help-gnu-emacs@gnu.org; Sat, 10 Nov 2012 10:55:44 -0500 Original-Received: by mail-we0-f169.google.com with SMTP id u3so2606268wey.0 for ; Sat, 10 Nov 2012 07:55:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:message-id:user-agent :mime-version:content-type; bh=pW8pjVVa82s6x5UNnAYh1KzyXsXmz9JN+gULR4yJ0CI=; b=DAY88zPOvVJ+Bey9zVJVLEj0QXx1pQfywX1jmURvjlvpbgIKpX4SGlf6MUAhaig4po uA36pTVQnG3MsyDXD4FOSI8Llth73DTjBlfSdQK8RjxFyhU6VMZ8wx71Cl3PLtlfKS+c HcgguhfWuDLLb6KpZUxtbLfEZnzrwVPky0sIZmfAoZ3eSoiszbyYRglEKfKtM0l5Ycgo JL8V4ljeh75Od4jCZVQE7bYK0hM7GXIXr1IDj5qqschxkX1ecKXiRkwga9AcwMy3QHLW /OMn6I7PzG3Qq6/TuxWwe3rDpTyFlBJ839bYmzg6gewPpA4HARRK5unS8MA+4S+YPhbr FXMw== Original-Received: by 10.216.71.20 with SMTP id q20mr5793287wed.172.1352562943041; Sat, 10 Nov 2012 07:55:43 -0800 (PST) Original-Received: from mac-mini-de-yves-baumes.local.localhost (rke75-2-82-66-91-208.fbx.proxad.net. [82.66.91.208]) by mx.google.com with ESMTPS id i6sm6770280wix.5.2012.11.10.07.55.40 (version=SSLv3 cipher=OTHER); Sat, 10 Nov 2012 07:55:42 -0800 (PST) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (darwin) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 74.125.82.169 X-Mailman-Approved-At: Sat, 10 Nov 2012 14:18:49 -0500 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:87633 Archived-At: martin rudalics 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