all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Luc Teirlinck <teirllm@dms.auburn.edu>
Cc: eliz@elta.co.il, emacs-devel@gnu.org
Subject: Re: autorevert.el
Date: Sat, 20 Mar 2004 22:19:11 -0600 (CST)	[thread overview]
Message-ID: <200403210419.i2L4JBp29471@raven.dms.auburn.edu> (raw)
In-Reply-To: <jwvr7vp4bl4.fsf-monnier+emacs@asado.iro.umontreal.ca> (message from Stefan Monnier on 19 Mar 2004 01:06:53 -0500)

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))
  \f
  (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))
! 
  \f
  (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
============================================================

  parent reply	other threads:[~2004-03-21  4:19 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-02 23:19 autorevert.el Luc Teirlinck
2004-03-03 13:24 ` autorevert.el Stefan Monnier
2004-03-04  5:08   ` autorevert.el Luc Teirlinck
2004-03-04 20:43     ` autorevert.el Stefan Monnier
2004-03-05  4:00       ` autorevert.el Luc Teirlinck
2004-03-13  3:10         ` autorevert.el Luc Teirlinck
2004-03-13 11:29           ` autorevert.el Kai Grossjohann
2004-03-14 23:15           ` autorevert.el Stefan Monnier
2004-03-15  0:08             ` autorevert.el Luc Teirlinck
2004-03-15  2:58               ` autorevert.el Stefan Monnier
2004-03-15  7:04               ` autorevert.el Eli Zaretskii
2004-03-16  4:56                 ` autorevert.el Luc Teirlinck
2004-03-16 19:40                   ` autorevert.el Eli Zaretskii
2004-03-19  4:48                     ` autorevert.el Luc Teirlinck
2004-03-19  6:06                       ` autorevert.el Stefan Monnier
2004-03-21  2:42                         ` autorevert.el Luc Teirlinck
2004-03-23 15:26                           ` autorevert.el Stefan Monnier
2004-03-24  4:20                             ` autorevert.el Luc Teirlinck
2004-03-24  4:25                               ` autorevert.el Luc Teirlinck
2004-03-21  4:19                         ` Luc Teirlinck [this message]
2004-03-19 10:19                     ` autorevert.el Kim F. Storm
2004-03-19 14:46                       ` autorevert.el Eli Zaretskii
2004-03-21  3:26                         ` autorevert.el Luc Teirlinck
2004-03-21  6:46                           ` autorevert.el Eli Zaretskii
2004-03-22  2:44                             ` autorevert.el Luc Teirlinck
2004-03-22  6:51                               ` autorevert.el Eli Zaretskii
2004-03-22 19:39                                 ` autorevert.el Luc Teirlinck
2004-03-23 19:40                                   ` autorevert.el Eli Zaretskii
2004-03-23 20:09                                     ` autorevert.el Stefan Monnier
2004-03-24  4:10                                     ` autorevert.el Luc Teirlinck
2004-03-24  6:58                                       ` autorevert.el Eli Zaretskii
2004-03-24 18:03                                         ` autorevert.el Stefan Monnier
2004-03-25  6:56                                           ` autorevert.el Eli Zaretskii
2004-03-25 17:01                                             ` autorevert.el Stefan Monnier
2004-03-24 18:56                                         ` autorevert.el Luc Teirlinck
2004-03-25  6:20                                         ` autorevert.el Luc Teirlinck
2004-03-25  6:49                                           ` autorevert.el Luc Teirlinck
2004-03-25  7:21                                           ` autorevert.el Eli Zaretskii
2004-03-22 19:47                                 ` autorevert.el Luc Teirlinck
2004-03-22 16:23                               ` autorevert.el Stefan Monnier
2004-03-23  4:24                                 ` autorevert.el Eli Zaretskii
2004-03-21 19:22                           ` autorevert.el Richard Stallman
2004-03-16  5:06                 ` autorevert.el Luc Teirlinck
2004-03-05  4:25       ` autorevert.el Luc Teirlinck
2004-03-05  5:55       ` autorevert.el Luc Teirlinck
2004-03-04  5:34   ` autorevert.el Luc Teirlinck

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=200403210419.i2L4JBp29471@raven.dms.auburn.edu \
    --to=teirllm@dms.auburn.edu \
    --cc=eliz@elta.co.il \
    --cc=emacs-devel@gnu.org \
    /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.