unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* autorevert.el
@ 2004-03-02 23:19 Luc Teirlinck
  2004-03-03 13:24 ` autorevert.el Stefan Monnier
  0 siblings, 1 reply; 46+ messages in thread
From: Luc Teirlinck @ 2004-03-02 23:19 UTC (permalink / raw)


This is an amended copy of something I sent to emacs-devel on
Thursday.  I do not expect the original to ever arrive.

Any objections to me applying the patch below?  I have been using it
without any problems for two weeks now.

The purpose is to be able to autorevert dired buffers without
excessive CPU-usage and without continuously being overshouted by
revert messages when trying to use the minibuffer.

If one customizes dired in the "wrong" way (say, not using the "a"
switch) or uses the "wrong" dired functionality (for instance, listing
subdirectories) this is currently not possible (without my patch
applied).

Also, without my patch applied, various other dired functionality, for
instance dired-undo, no longer properly works if one tries to
auto-revert dired buffers.

There is one addition to the patch I proposed (but did not install)
two weeks ago.  That is the new user-option
`auto-revert-no-secondary-messages' which allows to suppress the usual
"Reading directory %s...done" type messages.  The default is nil, do
not suppress them.  Without this option or with the option set to nil,
one still (even after applying my previous patch) can get overshouted
in the minibuffer while, say, bootstrapping or stuff like that.  With
the variable set to t, one can visit every single directory and
subdirectory in the Emacs CVS tree, so they all will get updated, and
then bootstrap (or do similar stuff that continuously updates the
directories), without any minibuffer-overshouting or CPU-usage
problems.

===File ~/autorevert.el-diff================================
*** autorevert.el.~1.21.~	Mon Feb 16 20:04:45 2004
--- autorevert.el	Thu Feb 26 20:43:07 2004
***************
*** 158,164 ****
  When non-nil, both file buffers and buffers with a custom
  `revert-buffer-function' are reverted by Global Auto-Revert Mode.
  
! Use this option with care since it could lead to excessive reverts."
    :group 'auto-revert
    :type 'boolean)
  
--- 158,178 ----
  When non-nil, both file buffers and buffers with a custom
  `revert-buffer-function' are reverted by Global Auto-Revert Mode.
  
! Use this option with care since it could lead to excessive reverts.
! Note also that for some non-file buffers the check whether the
! buffer needs updating may be imperfect, due to efficiency
! considerations, and may not take all information listed in the
! buffer into account.  Hence, a non-nil value for this option does
! not necessarily make manual updates useless for non-file buffers."
!   :group 'auto-revert
!   :type 'boolean)
! 
! (defcustom auto-revert-no-secondary-messages nil
!   "If non-nil, Auto-Revert Mode suppresses secondary revert messages.
! These are messages generated by a non-file buffer's `revert-buffer-function'.
! This variable only works for buffers whose`revert-buffer-function'
! supports it.  To suppress revert messages generated by Auto-Revert Mode
! itself, use `auto-revert-verbose'."
    :group 'auto-revert
    :type 'boolean)
  
***************
*** 260,312 ****
         (not (memq major-mode
  		  global-auto-revert-ignore-modes)))))
  
- (defun auto-revert-list-diff (a b)
-   "Check if strings in list A differ from list B."
-   (when (and a b)
-     (setq a (sort a 'string-lessp))
-     (setq b (sort b 'string-lessp))
-     (let (elt1 elt2)
-       (catch 'break
- 	(while (and (setq elt1 (and a (pop a)))
- 		    (setq elt2 (and b (pop b))))
- 	  (if (not (string= elt1 elt2))
- 	      (throw 'break t)))))))
- 
- (defun auto-revert-dired-file-list ()
-   "Return list of dired files."
-   (let (file list)
-     (save-excursion
-       (goto-char (point-min))
-       (while (not (eobp))
- 	(if (setq file (dired-get-filename t t))
- 	    (push file list))
- 	(forward-line 1)))
-     list))
- 
- (defun auto-revert-dired-changed-p ()
-   "Check if dired buffer has changed."
-   (when (and (stringp dired-directory)
- 	     ;;	  Exclude remote buffers, would be too slow for user
- 	     ;;	  modem, timeouts, network lag ... all is possible
- 	     (not (string-match "@" dired-directory))
- 	     (file-directory-p dired-directory))
-     (let ((files (directory-files dired-directory))
- 	  (dired (auto-revert-dired-file-list)))
-       (or (not (eq (length files) (length dired)))
- 	  (auto-revert-list-diff files dired)))))
- 
  (defun auto-revert-buffer-p ()
    "Check if current buffer should be reverted."
!   ;;  - Always include dired buffers to list.  It would be too expensive
    ;;  to test the "revert" status here each time timer launches.
-   ;;  - Same for VC buffers.
    (or (and (eq major-mode 'dired-mode)
  	   (or (and global-auto-revert-mode
  		    global-auto-revert-non-file-buffers)
! 	       auto-revert-mode))
!       (and (not (buffer-modified-p))
  	   (auto-revert-vc-buffer-p))
!       (and (not (buffer-modified-p))
  	   (if (buffer-file-name)
  	       (and (file-readable-p (buffer-file-name))
  		    (not (verify-visited-file-modtime (current-buffer))))
--- 274,305 ----
         (not (memq major-mode
  		  global-auto-revert-ignore-modes)))))
  
  (defun auto-revert-buffer-p ()
    "Check if current buffer should be reverted."
!   ;;  - Always include VC buffers to list.  It would be too expensive
    ;;  to test the "revert" status here each time timer launches.
    (or (and (eq major-mode 'dired-mode)
  	   (or (and global-auto-revert-mode
  		    global-auto-revert-non-file-buffers)
! 	       auto-revert-mode)
! 	   (not (buffer-modified-p))
! 	   (stringp dired-directory)
! 	   ;; Exclude remote buffers, would be too slow for user
! 	   ;; modem, timeouts, network lag ... all is possible
! 	   (not (string-match "@" dired-directory))
! 	   (file-directory-p dired-directory)
!            (file-readable-p dired-directory)
! 	   (not (let ((attributes (file-attributes dired-directory))
! 		      (modtime (visited-file-modtime)))
! 		  (or (eq modtime 0)
! 		      (not (eq (car attributes) t))
! 		      (and (= (car (nth 5 attributes)) (car modtime))
! 			   (= (nth 1 (nth 5 attributes)) (cdr modtime)))))))
!       (and (not (eq major-mode 'dired-mode))
! 	   (not (buffer-modified-p))
  	   (auto-revert-vc-buffer-p))
!       (and (not (eq major-mode 'dired-mode))
! 	   (not (buffer-modified-p))
  	   (if (buffer-file-name)
  	       (and (file-readable-p (buffer-file-name))
  		    (not (verify-visited-file-modtime (current-buffer))))
***************
*** 369,382 ****
  	  ;; TODO:
  	  ))))))
  
  (defun auto-revert-handler ()
    "Revert current buffer."
    (let (revert)
      (cond
       ((eq major-mode 'dired-mode)
        ;;  Dired includes revert-buffer-function
!       (when (and revert-buffer-function
! 		 (auto-revert-dired-changed-p))
  	(setq revert t)))
       ((auto-revert-vc-buffer-p)
        (when (auto-revert-handler-vc)
--- 362,379 ----
  	  ;; TODO:
  	  ))))))
  
+ (defvar auto-revert-flag nil
+   "Bound to t by `auto-revert-handler'.
+ If non-nil, the current function was called as part of auto-reverting
+ a buffer.  This is used to implement `auto-revert-no-secondary-messages'.")
+ 
  (defun auto-revert-handler ()
    "Revert current buffer."
    (let (revert)
      (cond
       ((eq major-mode 'dired-mode)
        ;;  Dired includes revert-buffer-function
!       (when revert-buffer-function
  	(setq revert t)))
       ((auto-revert-vc-buffer-p)
        (when (auto-revert-handler-vc)
***************
*** 385,395 ****
  	  revert-buffer-function)
        (setq revert t)))
      (when revert
!       (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes)
!       (if (eq revert 'vc)
! 	  (vc-mode-line buffer-file-name))
!       (if auto-revert-verbose
! 	  (message "Reverting buffer `%s'." (buffer-name))))))
  
  (defun auto-revert-buffers ()
    "Revert buffers as specified by Auto-Revert and Global Auto-Revert Mode.
--- 382,393 ----
  	  revert-buffer-function)
        (setq revert t)))
      (when revert
!       (let ((auto-revert-flag t))
! 	(revert-buffer 'ignore-auto 'dont-ask 'preserve-modes)
! 	(if (eq revert 'vc)
! 	    (vc-mode-line buffer-file-name))
! 	(if auto-revert-verbose
! 	    (message "Reverting buffer `%s'." (buffer-name)))))))
  
  (defun auto-revert-buffers ()
    "Revert buffers as specified by Auto-Revert and Global Auto-Revert Mode.
============================================================

===File ~/dired-diff========================================
*** dired.el.~1.272.~	Tue Feb  3 15:42:36 2004
--- dired.el	Thu Feb 26 20:04:48 2004
***************
*** 618,623 ****
--- 618,625 ----
  \f
  ;; Read in a new dired buffer
  
+ (defvar auto-revert-flag)
+ 
  ;; dired-readin differs from dired-insert-subdir in that it accepts
  ;; wildcards, erases the buffer, and builds the subdir-alist anew
  ;; (including making it buffer-local and clearing it first).
***************
*** 634,640 ****
        ;; based on dired-directory, e.g. with ange-ftp to a SysV host
        ;; where ls won't understand -Al switches.
        (run-hooks 'dired-before-readin-hook)
!       (message "Reading directory %s..." dirname)
        (if (consp buffer-undo-list)
  	  (setq buffer-undo-list nil))
        (let (buffer-read-only
--- 636,645 ----
        ;; based on dired-directory, e.g. with ange-ftp to a SysV host
        ;; where ls won't understand -Al switches.
        (run-hooks 'dired-before-readin-hook)
!       (unless (and (boundp 'auto-revert-flag)
! 		   auto-revert-flag
! 		   auto-revert-no-secondary-messages)
! 	(message "Reading directory %s..." dirname))
        (if (consp buffer-undo-list)
  	  (setq buffer-undo-list nil))
        (let (buffer-read-only
***************
*** 643,649 ****
  	(widen)
  	(erase-buffer)
  	(dired-readin-insert))
!       (message "Reading directory %s...done" dirname)
        (goto-char (point-min))
        ;; Must first make alist buffer local and set it to nil because
        ;; dired-build-subdir-alist will call dired-clear-alist first
--- 648,657 ----
  	(widen)
  	(erase-buffer)
  	(dired-readin-insert))
!       (unless (and (boundp 'auto-revert-flag)
! 		   auto-revert-flag
! 		   auto-revert-no-secondary-messages)
! 	(message "Reading directory %s...done" dirname))
        (goto-char (point-min))
        ;; Must first make alist buffer local and set it to nil because
        ;; dired-build-subdir-alist will call dired-clear-alist first
============================================================

^ permalink raw reply	[flat|nested] 46+ messages in thread

end of thread, other threads:[~2004-03-25 17:01 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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                         ` autorevert.el Luc Teirlinck
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

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).