emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master e9e807e: Don't remove notify descriptor that is alr


From: Mattias Engdegård
Subject: [Emacs-diffs] master e9e807e: Don't remove notify descriptor that is already gone
Date: Mon, 15 Apr 2019 04:33:38 -0400 (EDT)

branch: master
commit e9e807e9317ca7aa99a5dd220ee8586f8f4331bf
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>

    Don't remove notify descriptor that is already gone
    
    * lisp/autorevert.el (auto-revert-use-notify, auto-revert-mode,
    global-auto-revert-mode, auto-revert-notify-rm-watch,
    auto-revert-notify-add-watch, auto-revert-notify-handler,
    auto-revert-notify-rm-watch-callback):
    Don't remove a notify descriptor after receiving a `stopped' notification
    event, because the descriptor is then already gone and any attempt to
    remove it causes a recursive call to `auto-revert-notify-handler'.
---
 lisp/autorevert.el | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/lisp/autorevert.el b/lisp/autorevert.el
index 4fb865e..1dc2f0e 100644
--- a/lisp/autorevert.el
+++ b/lisp/autorevert.el
@@ -287,7 +287,7 @@ You should set this variable through Custom."
           (dolist (buf (buffer-list))
             (with-current-buffer buf
               (when (symbol-value 'auto-revert-notify-watch-descriptor)
-                (auto-revert-notify-rm-watch))))))
+                (auto-revert-notify-rm-watch t))))))
   :initialize 'custom-initialize-default
   :version "24.4")
 
@@ -371,7 +371,7 @@ without being changed in the part that is already in the 
buffer."
          'kill-buffer-hook
          #'auto-revert-remove-current-buffer
          nil t))
-    (when auto-revert-notify-watch-descriptor (auto-revert-notify-rm-watch))
+    (when auto-revert-notify-watch-descriptor (auto-revert-notify-rm-watch t))
     (auto-revert-remove-current-buffer))
   (auto-revert-set-timer)
   (when auto-revert-mode
@@ -480,7 +480,7 @@ specifies in the mode line."
     (dolist (buf (buffer-list))
       (with-current-buffer buf
        (when auto-revert-notify-watch-descriptor
-         (auto-revert-notify-rm-watch))))))
+         (auto-revert-notify-rm-watch t))))))
 
 (defun auto-revert-set-timer ()
   "Restart or cancel the timer used by Auto-Revert Mode.
@@ -497,8 +497,10 @@ will use an up-to-date value of `auto-revert-interval'"
                            auto-revert-interval
                            'auto-revert-buffers))))
 
-(defun auto-revert-notify-rm-watch ()
-  "Disable file notification for current buffer's associated file."
+(defun auto-revert-notify-rm-watch (remove-descriptor)
+  "Disable file notification for current buffer's associated file.
+If REMOVE-DESCRIPTOR is non-nil, remove the corresponding notification
+descriptor; otherwise assume that it has already been removed."
   (when auto-revert-notify-watch-descriptor
     (maphash
      (lambda (key value)
@@ -507,13 +509,19 @@ will use an up-to-date value of `auto-revert-interval'"
         (if value
             (puthash key value auto-revert-notify-watch-descriptor-hash-list)
           (remhash key auto-revert-notify-watch-descriptor-hash-list)
-          (ignore-errors
-            (file-notify-rm-watch auto-revert-notify-watch-descriptor)))))
+           (when remove-descriptor
+            (ignore-errors
+              (file-notify-rm-watch auto-revert-notify-watch-descriptor))))))
      auto-revert-notify-watch-descriptor-hash-list)
-    (remove-hook 'kill-buffer-hook #'auto-revert-notify-rm-watch t))
+    (remove-hook 'kill-buffer-hook #'auto-revert-notify-rm-watch-callback t))
   (setq auto-revert-notify-watch-descriptor nil
        auto-revert-notify-modified-p nil))
 
+(defun auto-revert-notify-rm-watch-callback ()
+  "Disable file notification for current buffer's associated file,
+and remove the notification descriptor."
+  (auto-revert-notify-rm-watch t))
+
 (defun auto-revert-notify-add-watch ()
   "Enable file notification for current buffer's associated file."
   ;; We can assume that `auto-revert-notify-watch-descriptor' is nil.
@@ -553,7 +561,8 @@ will use an up-to-date value of `auto-revert-interval'"
               (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)))))
+        (add-hook 'kill-buffer-hook #'auto-revert-notify-rm-watch-callback
+                  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
@@ -609,7 +618,9 @@ no more reverts are possible until the next call of
                                 (file-name-nondirectory buffer-file-name)))
                           ;; A buffer w/o a file, like dired.
                           (null buffer-file-name)))
-                (auto-revert-notify-rm-watch))))
+                ;; Since we got a `stopped' event, the notification descriptor
+                ;; is already gone; don't try to remove it.
+                (auto-revert-notify-rm-watch nil))))
 
         ;; Loop over all buffers, in order to find the intended one.
         (cl-dolist (buffer buffers)



reply via email to

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