]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix Bug#27502
authorMichael Albinus <michael.albinus@gmx.de>
Sun, 2 Jul 2017 09:41:58 +0000 (11:41 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Sun, 2 Jul 2017 09:41:58 +0000 (11:41 +0200)
* lisp/autorevert.el (auto-revert-find-file-function): New defun.
(find-file-hook): Use it.  (Bug#27502)
(auto-revert-remove-current-buffer): New defun.
(auto-revert-mode, auto-revert-buffers): Use it.

lisp/autorevert.el

index 79291624523d184ff3ea86fb179213486a49fded..a15386aa1af82035e3ec0cf7d92c6ea2228c07e4 100644 (file)
@@ -319,10 +319,12 @@ the list of old buffers.")
 (defvar auto-revert-tail-pos 0
   "Position of last known end of file.")
 
+(defun auto-revert-find-file-function ()
+  (setq-local auto-revert-tail-pos
+              (nth 7 (file-attributes buffer-file-name))))
+
 (add-hook 'find-file-hook
-         (lambda ()
-           (setq-local auto-revert-tail-pos
-                        (nth 7 (file-attributes buffer-file-name)))))
+         #'auto-revert-find-file-function)
 
 (defvar auto-revert-notify-watch-descriptor-hash-list
   (make-hash-table :test 'equal)
@@ -341,6 +343,11 @@ This has been reported by a file notification event.")
 
 ;; Functions:
 
+(defun auto-revert-remove-current-buffer ()
+  "Remove dead buffer from `auto-revert-buffer-list'."
+  (setq auto-revert-buffer-list
+        (delq (current-buffer) auto-revert-buffer-list)))
+
 ;;;###autoload
 (define-minor-mode auto-revert-mode
   "Toggle reverting buffer when the file changes (Auto-Revert Mode).
@@ -364,13 +371,10 @@ without being changed in the part that is already in the buffer."
         (push (current-buffer) auto-revert-buffer-list)
         (add-hook
          'kill-buffer-hook
-         (lambda ()
-           (setq auto-revert-buffer-list
-                 (delq (current-buffer) auto-revert-buffer-list)))
+         #'auto-revert-remove-current-buffer
          nil t))
     (when auto-revert-use-notify (auto-revert-notify-rm-watch))
-    (setq auto-revert-buffer-list
-         (delq (current-buffer) auto-revert-buffer-list)))
+    (auto-revert-remove-current-buffer))
   (auto-revert-set-timer)
   (when auto-revert-mode
     (auto-revert-buffers)
@@ -786,24 +790,24 @@ the timer when no buffers need to be checked."
                  (not (and auto-revert-stop-on-user-input
                            (input-pending-p))))
        (let ((buf (car bufs)))
-          (if (buffer-live-p buf)
-             (with-current-buffer buf
-               ;; Test if someone has turned off Auto-Revert Mode in a
-               ;; non-standard way, for example by changing major mode.
-               (if (and (not auto-revert-mode)
-                        (not auto-revert-tail-mode)
-                        (memq buf auto-revert-buffer-list))
-                   (setq auto-revert-buffer-list
-                         (delq buf auto-revert-buffer-list)))
-               (when (auto-revert-active-p)
-                 ;; Enable file notification.
-                 (when (and auto-revert-use-notify
-                            (not auto-revert-notify-watch-descriptor))
-                   (auto-revert-notify-add-watch))
-                 (auto-revert-handler)))
-           ;; Remove dead buffer from `auto-revert-buffer-list'.
-           (setq auto-revert-buffer-list
-                 (delq buf auto-revert-buffer-list))))
+          (with-current-buffer buf
+            (if (buffer-live-p buf)
+                (progn
+                  ;; Test if someone has turned off Auto-Revert Mode
+                  ;; in a non-standard way, for example by changing
+                  ;; major mode.
+                  (if (and (not auto-revert-mode)
+                           (not auto-revert-tail-mode)
+                           (memq buf auto-revert-buffer-list))
+                      (auto-revert-remove-current-buffer))
+                  (when (auto-revert-active-p)
+                    ;; Enable file notification.
+                    (when (and auto-revert-use-notify
+                               (not auto-revert-notify-watch-descriptor))
+                      (auto-revert-notify-add-watch))
+                    (auto-revert-handler)))
+              ;; Remove dead buffer from `auto-revert-buffer-list'.
+              (auto-revert-remove-current-buffer))))
        (setq bufs (cdr bufs)))
       (setq auto-revert-remaining-buffers bufs)
       ;; Check if we should cancel the timer.