bug-gnu-emacs
[Top][All Lists]
Advanced

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

[patch] 21.3 autorevert.el -- Dired and VC buffer handling fix


From: Jari Aalto+mail.emacs
Subject: [patch] 21.3 autorevert.el -- Dired and VC buffer handling fix
Date: Mon, 26 Jan 2004 20:53:03 +0200

    The process for checking Dired and VC buffer is too "heavy".
    I moved the new functionality to idle timer which gives
    more smoother operation. See doc comments in the patch.

    This assumes that the other patches by me to autorevert.el 
    has been applied.

    Jari


2004-01-26 Mon  Jari Aalto  <jari.aalto <AT> poboxes.com>

        * autorevert.el
        (auto-revert-set-timer): Added idle timer.
        (auto-revert-idle-timer): New.
        (auto-revert-idle-timer-interval): New user variable.
        (auto-revert-buffers-when-idle): New.
        (auto-revert-buffers): New stripped down function
        (auto-revert-buffers-1): Renamed. Was `auto-revert-buffers'.
        (auto-revert-buffers-1): Added new parameter `function-list'.


Index: autorevert.el
===================================================================
RCS file: 
/cygdrive/h/data/version-control/cvsroot/emacs/gnu-emacs/lisp213/autorevert.el,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -IId: -b -w -u -r1.5 -r1.6
--- autorevert.el       25 Jan 2004 14:40:42 -0000      1.5
+++ autorevert.el       26 Jan 2004 18:30:25 -0000      1.6
@@ -64,6 +64,25 @@
 ;; Mode in all C mode buffers:
 ;;
 ;; (add-hook 'c-mode-hook 'turn-on-auto-revert-mode)
+;;
+;; Notes:
+;;
+;; There are two auto revert processes. This first one is meant
+;; for functions that are light. meaning, that checking the revert
+;; status of the buffer can be done fast. Usually this is the case
+;; for normal file buffers, whose modification time can be comared
+;; to time on disk.
+;;
+;; However, chekcing dired buffers requires, that the whole
+;; directory on disk (each file) is compared to the content
+;; of dired buffer. This is time consuming and "heavy".
+;; similarly checking version controlled buffers an their
+;; need for revert takes time, because e.g. for CVS, a
+;; separate control file CVS/Entries must be consulted.
+;;
+;; The light process is ran with `run-with-timer' and the
+;; heavy process is ran with `run-with-idle-timer'. So only
+;; if Emacs has spare time, the "heavy" reverts are noticed.
 
 ;;; Code:
 
@@ -122,6 +141,15 @@
   :group 'auto-revert
   :type 'integer)
 
+(defcustom auto-revert-idle-timer-interval 60
+  "Time, in seconds, between Auto-Revert Mode file checks.
+This second timer should be more than 30 seconds, because the revert
+proecess installed here will do disk reads to check status
+of dired and VC controlled files."
+  :group 'auto-revert
+  :type 'integer)
+
+
 (defcustom auto-revert-stop-on-user-input t
   "When non-nil Auto-Revert Mode stops checking files on user input."
   :group 'auto-revert
@@ -191,6 +219,17 @@
 
 ;; Internal variables:
 
+(defvar auto-revert-check-functions
+  '(auto-revert-buffer-p)
+  "List of functions to ask for revert status of buffer.
+The functions are called in order and irst function to return t
+indicates that buffer should be included in revert list.")
+
+(defvar auto-revert-check-idle-functions
+  '(auto-revert-buffer-dired-p
+    auto-revert-buffer-vc-p)
+  "Same as `auto-revert-check-functions' but for idle timer.")
+
 (defvar auto-revert-buffer-list '()
   "List of buffers in Auto-Revert Mode.
 
@@ -203,6 +242,9 @@
 (defvar auto-revert-timer nil
   "Timer used by Auto-Revert Mode.")
 
+(defvar auto-revert-idle-timer nil
+  "Timer used by Auto-Revert Mode.")
+
 (defvar auto-revert-remaining-buffers '()
   "Buffers not checked when user input stopped execution.")
 
@@ -274,11 +316,21 @@
   "Restart or cancel the timer."
   (if (timerp auto-revert-timer)
       (cancel-timer auto-revert-timer))
-  (if (or global-auto-revert-mode auto-revert-buffer-list)
-      (setq auto-revert-timer (run-with-timer auto-revert-interval
+  (if (timerp auto-revert-idle-timer)
+      (cancel-timer auto-revert-idle-timer))
+  (cond
+   ((or global-auto-revert-mode auto-revert-buffer-list)
+    (setq auto-revert-timer
+          (run-with-timer auto-revert-interval
                                               auto-revert-interval
                                               'auto-revert-buffers))
-    (setq auto-revert-timer nil)))
+    (setq auto-revert-idle-timer
+          (run-with-idle-timer
+           auto-revert-idle-timer-interval
+           auto-revert-idle-timer-interval
+           'auto-revert-buffers-when-idle)))
+   (t
+    (setq auto-revert-timer nil))))
 
 (defun auto-revert-active-p ()
   "Check if auto-revert is active (in current buffer or globally)."
@@ -324,14 +376,19 @@
       (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
+(defun auto-revert-buffer-dired-p ()
+  "Check if current dired buffer should be reverted."
+  ;;  - 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 (eq major-mode 'dired-mode)
+  (eq major-mode 'dired-mode))
+
+(defun auto-revert-buffer-vc-p ()
+  "Check if current VC buffer should be reverted."
       (and (not (buffer-modified-p))
-           (auto-revert-vc-buffer-p))
+       (auto-revert-vc-buffer-p)))
+
+(defun auto-revert-buffer-p ()
+  "Check if current buffer should be reverted."
       (and (not (buffer-modified-p))
            (if (buffer-file-name)
                (and (file-readable-p (buffer-file-name))
@@ -339,7 +396,7 @@
              (and revert-buffer-function
                   (or (and global-auto-revert-mode
                            global-auto-revert-non-file-buffers)
-                      auto-revert-mode))))))
+                  auto-revert-mode)))))
 
 (defun auto-revert-vc-cvs-file-version (file)
   "Get version of FILE by reading control file on disk."
@@ -417,8 +474,9 @@
       (if auto-revert-verbose
           (message "Reverting buffer `%s'." (buffer-name))))))
 
-(defun auto-revert-buffers ()
+(defun auto-revert-buffers-1 (function-list)
   "Revert buffers as specified by Auto-Revert and Global Auto-Revert Mode.
+Run each function in FUNCTION-LIST to test if buffer should be reverted.
 
 Should `global-auto-revert-mode' be active all file buffers are checked.
 
@@ -469,7 +527,9 @@
                   (setq auto-revert-buffer-list
                         (delq buf auto-revert-buffer-list)))
               (when (and (auto-revert-active-p)
-                         (auto-revert-buffer-p))
+                         function-list
+                         (run-hook-with-args-until-success
+                          function-list))
                 (auto-revert-handler)))
           ;; Remove dead buffer from `auto-revert-buffer-list'.
           (setq auto-revert-buffer-list
@@ -482,8 +542,13 @@
       (cancel-timer auto-revert-timer)
       (setq auto-revert-timer nil))))
 
+(defun auto-revert-buffers ()
+  "Call `auto-revert-buffers-1' with ┬┤auto-revert-check-functions'."
+  (auto-revert-buffers-1 'auto-revert-check-functions))
 
-;; The end:
+(defun auto-revert-buffers-when-idle ()
+  "Call `auto-revert-buffers-1' with ┬┤auto-revert-check-idle-functions'."
+  (auto-revert-buffers-1 'auto-revert-check-idle-functions))
 
 (unless (assq 'auto-revert-mode minor-mode-alist)
   (push '(auto-revert-mode auto-revert-mode-text)






reply via email to

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