emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 12ab957: auto-revert-mode can now revert immediatel


From: Michael Albinus
Subject: [Emacs-diffs] master 12ab957: auto-revert-mode can now revert immediately in response to a change event
Date: Thu, 19 Feb 2015 20:36:28 +0000

branch: master
commit 12ab9571935d79c69ffab0fb1ea3f6e20f475860
Author: Dima Kogan <address@hidden>
Commit: Michael Albinus <address@hidden>

    auto-revert-mode can now revert immediately in response to a change event
    
    Fixes: debbugs:18958
    
    * autorevert.el (auto-revert-buffers-counter)
    (auto-revert-buffers-counter-lockedout): New variables.
    (auto-revert-buffers): Increase `auto-revert-buffers-counter'.
    (auto-revert-notify-handler): Apply `auto-revert-handler' if not
    suppressed by lockout.
---
 lisp/ChangeLog     |   16 ++++++++++++----
 lisp/autorevert.el |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index cdcb340..3d15b40 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
+2015-02-19  Dima Kogan  <address@hidden>
+
+       * autorevert.el (auto-revert-buffers-counter)
+       (auto-revert-buffers-counter-lockedout): New variables.
+       (auto-revert-buffers): Increase `auto-revert-buffers-counter'.
+       (auto-revert-notify-handler): Apply `auto-revert-handler' if not
+       suppressed by lockout.  (Bug#18958)
+
 2015-02-19  Stefan Monnier  <address@hidden>
 
        * emacs-lisp/eieio-opt.el (eieio-help-class): `eieio-class-parents'
@@ -29,7 +37,7 @@
        * files.el (find-alternate-file, abort-if-file-too-large, write-file)
        (set-visited-file-name):
        * emacs-lisp/lisp.el (kill-backward-up-list):
-       Use user-error instead of error. (Bug#14480)
+       Use user-error instead of error.  (Bug#14480)
 
 2015-02-18  Stefan Monnier  <address@hidden>
 
@@ -45,12 +53,12 @@
        * emacs-lisp/easy-mmode.el (define-minor-mode): Process macro
        arguments correctly. (Bug#19685)
        (define-minor-mode): Clarify docstring.
-       Clarify mode switch messages for minor modes. (Bug#19690)
+       Clarify mode switch messages for minor modes.  (Bug#19690)
 
 2015-02-16  Kelly Dean  <address@hidden>
 
        * emacs-lisp/package-x.el (package-upload-buffer-internal):
-       Create valid tar files. (Bug#19536)
+       Create valid tar files.  (Bug#19536)
 
 2015-02-16  Kelly Dean  <address@hidden>
 
@@ -60,7 +68,7 @@
 2015-02-16  Kelly Dean  <address@hidden>
 
        * help-mode.el (help-do-xref): Prevent duplicated display of Info
-       buffer, and prevent interference with existing buffer. (Bug#13190)
+       buffer, and prevent interference with existing buffer.  (Bug#13190)
 
 2015-02-16  Fabián Ezequiel Gallina  <address@hidden>
 
diff --git a/lisp/autorevert.el b/lisp/autorevert.el
index 8c8c617..02cef24 100644
--- a/lisp/autorevert.el
+++ b/lisp/autorevert.el
@@ -531,6 +531,30 @@ will use an up-to-date value of `auto-revert-interval'"
       ;; Fallback to file checks.
       (set (make-local-variable 'auto-revert-use-notify) nil))))
 
+;; If we have file notifications, we want to update the auto-revert buffers
+;; immediately when a notification occurs. Since file updates can happen very
+;; often, we want to skip some revert operations so that we don't spend all our
+;; time reverting the buffer.
+;;
+;; We do this by reverting immediately in response to the first in a flurry of
+;; notifications. We suppress subsequent notifications until the next time
+;; `auto-revert-buffers' is called (this happens on a timer with a period set 
by
+;; `auto-revert-interval').
+(defvar auto-revert-buffers-counter 1
+  "Incremented each time `auto-revert-buffers' is called")
+(defvar-local auto-revert-buffers-counter-lockedout 0
+  "Buffer-local value to indicate whether we should immediately
+update the buffer on a notification event or not. If
+
+  (= auto-revert-buffers-counter-lockedout
+     auto-revert-buffers-counter)
+
+then the updates are locked out, and we wait until the next call
+of `auto-revert-buffers' to revert the buffer. If no lockout is
+present, then we revert immediately and set the lockout, so that
+no more reverts are possible until the next call of
+`auto-revert-buffers'")
+
 (defun auto-revert-notify-handler (event)
   "Handle an EVENT returned from file notification."
   (with-demoted-errors
@@ -566,6 +590,14 @@ will use an up-to-date value of `auto-revert-interval'"
                                 (file-name-nondirectory buffer-file-name)))))
                 ;; Mark buffer modified.
                 (setq auto-revert-notify-modified-p t)
+
+                ;; Revert the buffer now if we're not locked out
+                (when (/= auto-revert-buffers-counter-lockedout
+                          auto-revert-buffers-counter)
+                  (auto-revert-handler)
+                  (setq auto-revert-buffers-counter-lockedout
+                        auto-revert-buffers-counter))
+
                 ;; No need to check other buffers.
                 (cl-return)))))))))
 
@@ -686,6 +718,10 @@ are checked first the next time this function is called.
 This function is also responsible for removing buffers no longer in
 Auto-Revert mode from `auto-revert-buffer-list', and for canceling
 the timer when no buffers need to be checked."
+
+  (setq auto-revert-buffers-counter
+        (1+ auto-revert-buffers-counter))
+
   (save-match-data
     (let ((bufs (if global-auto-revert-mode
                    (buffer-list)



reply via email to

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