]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix Bug#33194
authorMichael Albinus <michael.albinus@gmx.de>
Sun, 4 Nov 2018 11:51:39 +0000 (12:51 +0100)
committerMichael Albinus <michael.albinus@gmx.de>
Sun, 4 Nov 2018 11:51:39 +0000 (12:51 +0100)
* lisp/autorevert.el (auto-revert-notify-add-watch):
Handle buffers with same descriptor properly.
(auto-revert-notify-handler): Handle all buffers with same
descriptor.  (Bug#33194)

* lisp/filenotify.el (file-notify-callback): Simplify.

lisp/autorevert.el
lisp/filenotify.el

index fc3469e03df6fb0d116c10a5d5a1291ee77f2baa..2cf5b427ea3f261bf9250abec5a107b131cad03a 100644 (file)
@@ -515,32 +515,43 @@ will use an up-to-date value of `auto-revert-interval'"
 
 (defun auto-revert-notify-add-watch ()
   "Enable file notification for current buffer's associated file."
-  ;; We can assume that `buffer-file-name' and
-  ;; `auto-revert-notify-watch-descriptor' are non-nil.
+  ;; We can assume that `auto-revert-notify-watch-descriptor' is nil.
   (unless (or auto-revert-notify-watch-descriptor
               (string-match auto-revert-notify-exclude-dir-regexp
                            (expand-file-name default-directory))
              (file-symlink-p (or buffer-file-name default-directory)))
-    (setq auto-revert-notify-watch-descriptor
-         (ignore-errors
-           (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))))
-    (when auto-revert-notify-watch-descriptor
-      (setq auto-revert-notify-modified-p t)
-      (puthash
-      auto-revert-notify-watch-descriptor
-       (cons (current-buffer)
-            (gethash auto-revert-notify-watch-descriptor
-                     auto-revert-notify-watch-descriptor-hash-list))
+    ;; Check, whether this has been activated already.
+    (let ((file (if buffer-file-name
+                   (expand-file-name buffer-file-name default-directory)
+                 (expand-file-name default-directory))))
+      (maphash
+       (lambda (key _value)
+         (when (and
+                (equal (file-notify--watch-absolute-filename
+                        (gethash key file-notify-descriptors))
+                       (directory-file-name file))
+                (equal (file-notify--watch-callback
+                        (gethash key file-notify-descriptors))
+                       'auto-revert-notify-handler))
+         (setq auto-revert-notify-watch-descriptor key)))
        auto-revert-notify-watch-descriptor-hash-list)
-      (add-hook 'kill-buffer-hook #'auto-revert-notify-rm-watch nil t))))
+      ;; Create a new watch if needed.
+      (unless auto-revert-notify-watch-descriptor
+        (setq auto-revert-notify-watch-descriptor
+             (ignore-errors
+               (file-notify-add-watch
+                file
+                 (if buffer-file-name '(change attribute-change) '(change))
+                 'auto-revert-notify-handler))))
+      (when auto-revert-notify-watch-descriptor
+        (setq auto-revert-notify-modified-p t)
+        (puthash
+         auto-revert-notify-watch-descriptor
+         (cons (current-buffer)
+              (gethash auto-revert-notify-watch-descriptor
+                       auto-revert-notify-watch-descriptor-hash-list))
+         auto-revert-notify-watch-descriptor-hash-list)
+        (add-hook 'kill-buffer-hook #'auto-revert-notify-rm-watch nil t)))))
 
 ;; If we have file notifications, we want to update the auto-revert buffers
 ;; immediately when a notification occurs. Since file updates can happen very
@@ -626,10 +637,7 @@ no more reverts are possible until the next call of
                           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)))))))))
+                        auto-revert-buffers-counter))))))))))
 
 (defun auto-revert-active-p ()
   "Check if auto-revert is active (in current buffer or globally)."
index 59a8c0e88aa2f6fed4684c6cd12579b9a61d5d50..a133f9ea7eca8c4627ea5effbe68b29c7d451577 100644 (file)
@@ -45,11 +45,11 @@ could use another implementation.")
                (:constructor nil)
                (:constructor
                 file-notify--watch-make (directory filename callback)))
-  ;; Watched directory
+  ;; Watched directory.
   directory
   ;; Watched relative filename, nil if watching the directory.
   filename
-  ;; Function to propagate events to
+  ;; Function to propagate events to.
   callback)
 
 (defun file-notify--watch-absolute-filename (watch)
@@ -242,11 +242,10 @@ EVENT is the cadr of the event in `file-notify-handle-event'
             ;;(message
             ;;"file-notify-callback %S %S %S %S %S"
             ;;desc action file file1 watch)
-            (if file1
-                (funcall (file-notify--watch-callback watch)
-                         `(,desc ,action ,file ,file1))
-              (funcall (file-notify--watch-callback watch)
-                       `(,desc  ,action ,file))))
+            (funcall (file-notify--watch-callback watch)
+                     (if file1
+                         `(,desc ,action ,file ,file1)
+                       `(,desc ,action ,file))))
 
           ;; Send `stopped' event.
           (when (or stopped