emacs-devel
[Top][All Lists]
Advanced

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

Re: autorevert.el


From: Luc Teirlinck
Subject: Re: autorevert.el
Date: Sat, 20 Mar 2004 20:42:28 -0600 (CST)

Stefan Monnier wrote:

   Please install your autorevert-stale-function (or whatever the
   name) patch as soon as it's ready.  All it has to do is to get rid
   of the current autorevert-dired horror.

Here is the proposed patch.  I actually took a look at the code
duplication in the current code and there appeared to be quite some.
My patch gets rid of one more function.

I _did_ get rid of my auto-revert-flag variable.  However, I am not
sure that as people try to make more and more modes suitable for
auto-reverting the need for that variable will not arise again.  If
people would object against the modifications I made to the
revert-buffer-functions of dired (silencing the revert message) or the
buffer-menu (see a later message), then I would need it right now.

Some things about the *-stale-function may be up for debate.  I
called it buffer-stale-function and gave it an optional argument
telling it that it is called by auto-revert or something else that
does not ask for confirmation.  The idea is that the same function
also could be useful to warn the user that the buffer is stale, if
auto-revert mode is _not_ enabled.  Since here the user makes an
explicit decision, the behavior could be different for remote files
and other time confusing stuff.  So the function would (like
revert-buffer-function) not necessarily be auto-revert specific.
Alternatively, one could make it an auto-revert specific function,
call it auto-revert-stale-function and get rid of the optional argument.

I will send supporting patches for dired.el and buff-menu.el separately.

===File ~/autorevert-diff===================================
diff -c /home/teirllm/autorevert.old.el 
/home/teirllm/emacscvsdir/emacs/lisp/autorevert.el
*** /home/teirllm/autorevert.old.el     Sat Mar 20 19:01:28 2004
--- /home/teirllm/emacscvsdir/emacs/lisp/autorevert.el  Sat Mar 20 18:56:29 2004
***************
*** 172,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."
    :group 'auto-revert
    :type 'boolean)
  
--- 172,183 ----
  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)
  
***************
*** 193,198 ****
--- 198,215 ----
  This variable becomes buffer local when set in any fashion.")
  (make-variable-buffer-local 'global-auto-revert-ignore-buffer)
  
+ (defvar buffer-stale-function nil
+   "Function to check whether a non-file buffer needs reverting.
+ This should be a function with one optional argument NOCONFIRM.
+ Auto Revert Mode sets NOCONFIRM to t.  The function should return
+ non-nil if the buffer should be reverted.  The buffer is current
+ when this function is called.
+ 
+ The idea behind the NOCONFIRM argument is that the same function
+ can also be used to ask the user whether the buffer should be
+ reverted.  In such a situation one has to be less careful about,
+ say, reverting remote files, than if the function ia called at
+ regular intervals by Auto Revert Mode.")
  
  ;; Internal variables:
  
***************
*** 272,332 ****
         (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))))
-            (and revert-buffer-function
-                 (or (and global-auto-revert-mode
-                          global-auto-revert-non-file-buffers)
-                     auto-revert-mode))))))
- 
  (defun auto-revert-vc-cvs-file-version (file)
    "Get version of FILE by reading control file on disk."
    (let* ((control "CVS/Entries")
--- 289,294 ----
***************
*** 383,407 ****
  
  (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)
!       (setq revert 'vc)))
!      ((or (buffer-file-name)
!         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.
--- 345,371 ----
  
  (defun auto-revert-handler ()
    "Revert current buffer."
!   (unless (buffer-modified-p)
!     (let (revert)
!       (cond
!        ((auto-revert-vc-buffer-p)
!       (when (auto-revert-handler-vc)
!         (setq revert 'vc)))
!        ((or (and (buffer-file-name)
!                (file-readable-p (buffer-file-name))
!                (not (verify-visited-file-modtime (current-buffer))))
!           (and global-auto-revert-non-file-buffers
!                revert-buffer-function
!                (boundp 'buffer-stale-function)
!                (functionp buffer-stale-function)
!                (funcall buffer-stale-function t)))
        (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.
***************
*** 453,460 ****
                       (memq buf auto-revert-buffer-list))
                  (setq auto-revert-buffer-list
                        (delq buf auto-revert-buffer-list)))
!             (when (and (auto-revert-active-p)
!                        (auto-revert-buffer-p))
                (auto-revert-handler)
                ;; `preserve-modes' avoids changing the (minor) modes.  But we
                ;; do want to reset the mode for VC, so we do it explicitly.
--- 417,423 ----
                       (memq buf auto-revert-buffer-list))
                  (setq auto-revert-buffer-list
                        (delq buf auto-revert-buffer-list)))
!             (when (auto-revert-active-p)
                (auto-revert-handler)
                ;; `preserve-modes' avoids changing the (minor) modes.  But we
                ;; do want to reset the mode for VC, so we do it explicitly.

Diff finished.  Sat Mar 20 19:30:15 2004
============================================================




reply via email to

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