emacs-devel
[Top][All Lists]
Advanced

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

Re: Clarification about auto-revert-mode and inotify


From: Dima Kogan
Subject: Re: Clarification about auto-revert-mode and inotify
Date: Tue, 21 Oct 2014 10:59:29 -0700

Stefan Monnier <address@hidden> writes:

>> NEWS; does this mean simply that auto-revert is more efficient?
>
> Indeed, IIUC the current auto-revert-mode implementation only uses the
> file-notification code to reduce the amount of polling, but the revert
> itself is still only performed from the 5s timer.
>
> I don't think there's a strong technical reason for that,

OK.

I'm attaching a prototype patch to fix this. It updates the buffer
immediately when a change is detected, unless the previous such update
happened very recently. If it DID happen very recently, the normal
timer-based update kicks in later.

Is such a patch reasonable? If so, I'll add the proper comments and
docstrings, and resubmit it.

dima

diff --git a/lisp/autorevert.el b/lisp/autorevert.el
index f1074e2..00e1664 100644
--- a/lisp/autorevert.el
+++ b/lisp/autorevert.el
@@ -531,6 +533,15 @@ will use an up-to-date value of `auto-revert-interval'"
       ;; Fallback to file checks.
       (set (make-local-variable 'auto-revert-use-notify) nil))))
 
+
+
+(defvar auto-revert-notify-lockout-timer nil
+  "Lockout timer used by Auto-Revert Mode.")
+(make-variable-buffer-local 'auto-revert-notify-lockout-timer)
+
+(defvar auto-revert-notify-lockout-interval 3
+  "Lockout interval for the notify timers")
+
 (defun auto-revert-notify-handler (event)
   "Handle an EVENT returned from file notification."
   (with-demoted-errors
@@ -566,6 +577,15 @@ 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)
+
+                (unless (timerp auto-revert-notify-lockout-timer)
+                  (auto-revert-handler 1)
+
+                  (setq auto-revert-notify-lockout-timer
+                        (run-with-timer auto-revert-notify-lockout-interval 
nil                                        
+                                        (lambda ()
+                                          (setq 
auto-revert-notify-lockout-timer nil)))))
+                
                 ;; No need to check other buffers.
                 (cl-return)))))))))
 

reply via email to

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