]> git.eshelyaron.com Git - emacs.git/commitdiff
Support file notifications for dired auto-revert
authorMichael Albinus <michael.albinus@gmx.de>
Sat, 21 Feb 2015 12:11:55 +0000 (13:11 +0100)
committerMichael Albinus <michael.albinus@gmx.de>
Sat, 21 Feb 2015 12:11:55 +0000 (13:11 +0100)
* autorevert.el (auto-revert-notify-add-watch)
(auto-revert-notify-handler, auto-revert-buffers): Handle also
buffers without an associated file, like dired buffers.

lisp/ChangeLog
lisp/autorevert.el

index 7f5fb7ddf0dc929257f33861d1a0db382ac157d9..0211458daabbb936d46c9b076311030754e17862 100644 (file)
@@ -1,3 +1,9 @@
+2015-02-21  Michael Albinus  <michael.albinus@gmx.de>
+
+       * autorevert.el (auto-revert-notify-add-watch)
+       (auto-revert-notify-handler, auto-revert-buffers): Handle also
+       buffers without an associated file, like dired buffers.
+
 2015-02-21  Dima Kogan  <dima@secretsauce.net>
 
        * autorevert.el (auto-revert-mode, auto-revert-tail-mode)
index 4dd021e4c76d3930099f2a8ac3db8e9be82168cb..6489a3e04c284b13790dd8473f2fc4228aea491c 100644 (file)
@@ -505,16 +505,22 @@ will use an up-to-date value of `auto-revert-interval'"
   ;; `auto-revert-use-notify' are non-nil.
   (when (or (string-match auto-revert-notify-exclude-dir-regexp
                          (expand-file-name default-directory))
-           (file-symlink-p buffer-file-name))
+           (file-symlink-p (or buffer-file-name default-directory)))
     ;; Fallback to file checks.
     (set (make-local-variable 'auto-revert-use-notify) nil))
 
   (when (not auto-revert-notify-watch-descriptor)
     (setq auto-revert-notify-watch-descriptor
          (ignore-errors
-           (file-notify-add-watch
-            (expand-file-name buffer-file-name default-directory)
-            '(change attribute-change) 'auto-revert-notify-handler)))
+           (if buffer-file-name
+               (file-notify-add-watch
+                (expand-file-name buffer-file-name default-directory)
+                '(change attribute-change)
+                'auto-revert-notify-handler)
+             (file-notify-add-watch
+              (expand-file-name default-directory)
+              '(change)
+              'auto-revert-notify-handler))))
     (if auto-revert-notify-watch-descriptor
        (progn
          (puthash
@@ -563,40 +569,40 @@ no more reverts are possible until the next call of
                             auto-revert-notify-watch-descriptor-hash-list)))
       ;; Check, that event is meant for us.
       (cl-assert descriptor)
-      ;; We do not handle `deleted', because nothing has to be refreshed.
-      (unless (eq action 'deleted)
-        (cl-assert (memq action '(attribute-changed changed created renamed))
-                   t)
-        ;; Since we watch a directory, a file name must be returned.
-        (cl-assert (stringp file))
-        (when (eq action 'renamed) (cl-assert (stringp file1)))
-        ;; Loop over all buffers, in order to find the intended one.
-        (cl-dolist (buffer buffers)
-          (when (buffer-live-p buffer)
-            (with-current-buffer buffer
-              (when (and (stringp buffer-file-name)
-                         (or
-                          (and (memq action '(attribute-changed changed
-                                              created))
-                               (string-equal
-                                (file-name-nondirectory file)
-                                (file-name-nondirectory buffer-file-name)))
-                          (and (eq action 'renamed)
-                               (string-equal
-                                (file-name-nondirectory file1)
-                                (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)))))))))
+      ;; Since we watch a directory, a file name must be returned.
+      (cl-assert (stringp file))
+      (when (eq action 'renamed) (cl-assert (stringp file1)))
+      ;; Loop over all buffers, in order to find the intended one.
+      (cl-dolist (buffer buffers)
+       (when (buffer-live-p buffer)
+         (with-current-buffer buffer
+           (when (or
+                  ;; A buffer associated with a file.
+                  (and (stringp buffer-file-name)
+                       (or
+                        (and (memq action '(attribute-changed changed created))
+                             (string-equal
+                              (file-name-nondirectory file)
+                              (file-name-nondirectory buffer-file-name)))
+                        (and (eq action 'renamed)
+                             (string-equal
+                              (file-name-nondirectory file1)
+                              (file-name-nondirectory buffer-file-name)))))
+                  ;; A buffer w/o a file, like dired.
+                  (and (null buffer-file-name)
+                       (memq action '(created renamed deleted))))
+             ;; 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))))))))
 
 (defun auto-revert-active-p ()
   "Check if auto-revert is active (in current buffer or globally)."
@@ -750,7 +756,7 @@ the timer when no buffers need to be checked."
                          (delq buf auto-revert-buffer-list)))
                (when (auto-revert-active-p)
                  ;; Enable file notification.
-                 (when (and auto-revert-use-notify buffer-file-name
+                 (when (and auto-revert-use-notify
                             (not auto-revert-notify-watch-descriptor))
                    (auto-revert-notify-add-watch))
                  (auto-revert-handler)))