From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Luc Teirlinck Newsgroups: gmane.emacs.devel Subject: Re: autorevert.el Date: Sat, 20 Mar 2004 22:19:11 -0600 (CST) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200403210419.i2L4JBp29471@raven.dms.auburn.edu> References: <200403022319.i22NJbG01259@raven.dms.auburn.edu> <200403040508.i2458W811551@raven.dms.auburn.edu> <200403050400.i2540VQ21715@raven.dms.auburn.edu> <200403130310.i2D3A8w28676@raven.dms.auburn.edu> <200403150008.i2F083x04382@raven.dms.auburn.edu> <200403160456.i2G4uVL14097@raven.dms.auburn.edu> <2427-Tue16Mar2004214034+0200-eliz@elta.co.il> <200403190448.i2J4mxQ12087@raven.dms.auburn.edu> NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1079842989 15414 80.91.224.253 (21 Mar 2004 04:23:09 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 21 Mar 2004 04:23:09 +0000 (UTC) Cc: eliz@elta.co.il, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Sun Mar 21 05:23:01 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1B4uUH-0000bs-00 for ; Sun, 21 Mar 2004 05:23:01 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1B4uUG-0003ka-00 for ; Sun, 21 Mar 2004 05:23:01 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B4uSv-00052y-UD for emacs-devel@quimby.gnus.org; Sat, 20 Mar 2004 23:21:37 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1B4uSr-00052r-9X for emacs-devel@gnu.org; Sat, 20 Mar 2004 23:21:33 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1B4uSL-00050p-60 for emacs-devel@gnu.org; Sat, 20 Mar 2004 23:21:32 -0500 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B4uSK-00050k-Ts for emacs-devel@gnu.org; Sat, 20 Mar 2004 23:21:00 -0500 Original-Received: from raven.dms.auburn.edu (raven.dms.auburn.edu [131.204.53.29]) by manatee.dms.auburn.edu (8.12.10/8.12.10) with ESMTP id i2L4KsKt013156; Sat, 20 Mar 2004 22:20:54 -0600 (CST) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.6+Sun/8.11.6) id i2L4JBp29471; Sat, 20 Mar 2004 22:19:11 -0600 (CST) X-Authentication-Warning: raven.dms.auburn.edu: teirllm set sender to teirllm@dms.auburn.edu using -f Original-To: monnier@iro.umontreal.ca In-reply-to: (message from Stefan Monnier on 19 Mar 2004 01:06:53 -0500) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:20659 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:20659 Below is my patch to make the Buffer Menu autorevert. Without an auto-revert-flag type variable to tell functions that they are called by auto-revert, making the Buffer Menu auto-revertable, without intolerable side effects, requires two changes that affect non auto-revert users. But I believe that these changes are positive anyway and one can even be considered to be a bug fix. The most important change is the following. If you currently update a Buffer Menu that lists only file visiting buffers, the updated version lists the usual Buffer Menu including non-file buffers. I believe this is a bug regardless of any auto-revert stuff. Updating and toggling file-buffers-only status are unrelated decisions. The patch below would make the `g' command keep the file-buffers-only status unchanged and would add a new binding `T' that explicitly toggles the file-buffers-only status. The second change is that `g' would keep point at the same position (integer value: markers are useless, because `g' erases the original contents). This is necessary for auto-revert, because otherwise point keeps jumping to the beginning of the buffer, which is intolerable if the buffer-menu is selected and one is working in it. But I believe that even without auto-revert being enabled, one often just types `g' to make sure the Buffer Menu is up to date. If it is up to date, one does not want point to move. Note that with my patch, auto-reverting will still make point move if the Buffer Menu is shown in a non-selected window. But in that case, the Buffer Menu will _really_ change if one switches to it, so that the old value of point would be meaningless anyway. My code unconditionally auto-reverts the Buffer Menu (if there is one) every auto-revert-interval seconds. However, I did not notice any measurable CPU usage with auto-revert-interval set to its default value of 5 seconds. ===File ~/buff-menu-diff==================================== *** buff-menu.el.~1.63.~ Tue Sep 2 07:30:05 2003 --- buff-menu.el Sat Mar 20 19:37:33 2004 *************** *** 99,104 **** --- 99,114 ---- (defvar Buffer-menu-mode-map nil "Local keymap for `Buffer-menu-mode' buffers.") + (defvar Buffer-menu-files-only nil + "Non-nil if the current buffer-menu lists only file buffers. + This variable determines whether reverting the buffer lists only + file buffers. It affects both manual reverting and reverting by + Auto Revert Mode.") + + (make-variable-buffer-local 'Buffer-menu-files-only) + + (defvar buffer-stale-function) + (if Buffer-menu-mode-map () (setq Buffer-menu-mode-map (make-keymap)) *************** *** 131,136 **** --- 141,147 ---- (define-key Buffer-menu-mode-map "b" 'Buffer-menu-bury) (define-key Buffer-menu-mode-map "g" 'Buffer-menu-revert) (define-key Buffer-menu-mode-map "V" 'Buffer-menu-view) + (define-key Buffer-menu-mode-map "T" 'Buffer-menu-toggle-files-only) (define-key Buffer-menu-mode-map [mouse-2] 'Buffer-menu-mouse-select) ) *************** *** 167,179 **** \\[Buffer-menu-backup-unmark] -- back up a line and remove marks. \\[Buffer-menu-toggle-read-only] -- toggle read-only status of buffer on this line. \\[Buffer-menu-revert] -- update the list of buffers. \\[Buffer-menu-bury] -- bury the buffer listed on this line." (kill-all-local-variables) (use-local-map Buffer-menu-mode-map) (setq major-mode 'Buffer-menu-mode) (setq mode-name "Buffer Menu") ! (make-local-variable 'revert-buffer-function) ! (setq revert-buffer-function 'Buffer-menu-revert-function) (setq truncate-lines t) (setq buffer-read-only t) (run-hooks 'buffer-menu-mode-hook)) --- 178,193 ---- \\[Buffer-menu-backup-unmark] -- back up a line and remove marks. \\[Buffer-menu-toggle-read-only] -- toggle read-only status of buffer on this line. \\[Buffer-menu-revert] -- update the list of buffers. + \\[Buffer-menu-toggle-files-only] -- toggle whether the menu diplays only file buffers. \\[Buffer-menu-bury] -- bury the buffer listed on this line." (kill-all-local-variables) (use-local-map Buffer-menu-mode-map) (setq major-mode 'Buffer-menu-mode) (setq mode-name "Buffer Menu") ! (set (make-local-variable 'revert-buffer-function) ! 'Buffer-menu-revert-function) ! (set (make-local-variable 'buffer-stale-function) ! #'(lambda (&optional noconfirm) t)) (setq truncate-lines t) (setq buffer-read-only t) (run-hooks 'buffer-menu-mode-hook)) *************** *** 184,190 **** (revert-buffer)) (defun Buffer-menu-revert-function (ignore1 ignore2) ! (list-buffers)) (defun Buffer-menu-buffer (error-if-non-existent-p) "Return buffer described by this line of buffer menu." --- 198,218 ---- (revert-buffer)) (defun Buffer-menu-revert-function (ignore1 ignore2) ! ;; We can not use save-excursion here. The buffer gets erased. ! (let ((old-point (point))) ! (list-buffers-noselect Buffer-menu-files-only) ! (goto-char old-point))) ! ! (defun Buffer-menu-toggle-files-only (arg) ! "Toggle whether the current buffer-menu diplays only file buffers. ! With a positive ARF diplay only file buffers. With zero or ! negative ARG, display other buffers as well." ! (interactive "P") ! (setq Buffer-menu-files-only ! (cond ((not arg) (not Buffer-menu-files-only)) ! ((> (prefix-numeric-value arg) 0) t))) ! (revert-buffer)) ! (defun Buffer-menu-buffer (error-if-non-existent-p) "Return buffer described by this line of buffer menu." *************** *** 662,667 **** --- 690,697 ---- ;; current buffer is not displayed for some reason. (and desired-point (goto-char desired-point)) + (setq Buffer-menu-files-only files-only) + (set-buffer-modified-p nil) (current-buffer)))) ;;; arch-tag: e7dfcfc9-6cb2-46e4-bf55-8ef1936d83c6 ============================================================