emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

autorevert.el


From: Luc Teirlinck
Subject: autorevert.el
Date: Tue, 2 Mar 2004 17:19:37 -0600 (CST)

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 ----
  
  ;; 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
============================================================




reply via email to

[Prev in Thread] Current Thread [Next in Thread]