aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2017-07-02 11:41:58 +0200
committerMichael Albinus2017-07-02 11:41:58 +0200
commitc7e7eb323cdd04c6295b01a271d6a5e5f7464ef6 (patch)
tree5ca1628d531c19835a3c48e296136a67ddb01a5d
parent3269a585c4e6772af0d0e32729cfebf2662a5ba6 (diff)
downloademacs-c7e7eb323cdd04c6295b01a271d6a5e5f7464ef6.tar.gz
emacs-c7e7eb323cdd04c6295b01a271d6a5e5f7464ef6.zip
Fix Bug#27502
* 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.
-rw-r--r--lisp/autorevert.el56
1 files changed, 30 insertions, 26 deletions
diff --git a/lisp/autorevert.el b/lisp/autorevert.el
index 79291624523..a15386aa1af 100644
--- a/lisp/autorevert.el
+++ b/lisp/autorevert.el
@@ -319,10 +319,12 @@ the list of old buffers.")
319(defvar auto-revert-tail-pos 0 319(defvar auto-revert-tail-pos 0
320 "Position of last known end of file.") 320 "Position of last known end of file.")
321 321
322(defun auto-revert-find-file-function ()
323 (setq-local auto-revert-tail-pos
324 (nth 7 (file-attributes buffer-file-name))))
325
322(add-hook 'find-file-hook 326(add-hook 'find-file-hook
323 (lambda () 327 #'auto-revert-find-file-function)
324 (setq-local auto-revert-tail-pos
325 (nth 7 (file-attributes buffer-file-name)))))
326 328
327(defvar auto-revert-notify-watch-descriptor-hash-list 329(defvar auto-revert-notify-watch-descriptor-hash-list
328 (make-hash-table :test 'equal) 330 (make-hash-table :test 'equal)
@@ -341,6 +343,11 @@ This has been reported by a file notification event.")
341 343
342;; Functions: 344;; Functions:
343 345
346(defun auto-revert-remove-current-buffer ()
347 "Remove dead buffer from `auto-revert-buffer-list'."
348 (setq auto-revert-buffer-list
349 (delq (current-buffer) auto-revert-buffer-list)))
350
344;;;###autoload 351;;;###autoload
345(define-minor-mode auto-revert-mode 352(define-minor-mode auto-revert-mode
346 "Toggle reverting buffer when the file changes (Auto-Revert Mode). 353 "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."
364 (push (current-buffer) auto-revert-buffer-list) 371 (push (current-buffer) auto-revert-buffer-list)
365 (add-hook 372 (add-hook
366 'kill-buffer-hook 373 'kill-buffer-hook
367 (lambda () 374 #'auto-revert-remove-current-buffer
368 (setq auto-revert-buffer-list
369 (delq (current-buffer) auto-revert-buffer-list)))
370 nil t)) 375 nil t))
371 (when auto-revert-use-notify (auto-revert-notify-rm-watch)) 376 (when auto-revert-use-notify (auto-revert-notify-rm-watch))
372 (setq auto-revert-buffer-list 377 (auto-revert-remove-current-buffer))
373 (delq (current-buffer) auto-revert-buffer-list)))
374 (auto-revert-set-timer) 378 (auto-revert-set-timer)
375 (when auto-revert-mode 379 (when auto-revert-mode
376 (auto-revert-buffers) 380 (auto-revert-buffers)
@@ -786,24 +790,24 @@ the timer when no buffers need to be checked."
786 (not (and auto-revert-stop-on-user-input 790 (not (and auto-revert-stop-on-user-input
787 (input-pending-p)))) 791 (input-pending-p))))
788 (let ((buf (car bufs))) 792 (let ((buf (car bufs)))
789 (if (buffer-live-p buf) 793 (with-current-buffer buf
790 (with-current-buffer buf 794 (if (buffer-live-p buf)
791 ;; Test if someone has turned off Auto-Revert Mode in a 795 (progn
792 ;; non-standard way, for example by changing major mode. 796 ;; Test if someone has turned off Auto-Revert Mode
793 (if (and (not auto-revert-mode) 797 ;; in a non-standard way, for example by changing
794 (not auto-revert-tail-mode) 798 ;; major mode.
795 (memq buf auto-revert-buffer-list)) 799 (if (and (not auto-revert-mode)
796 (setq auto-revert-buffer-list 800 (not auto-revert-tail-mode)
797 (delq buf auto-revert-buffer-list))) 801 (memq buf auto-revert-buffer-list))
798 (when (auto-revert-active-p) 802 (auto-revert-remove-current-buffer))
799 ;; Enable file notification. 803 (when (auto-revert-active-p)
800 (when (and auto-revert-use-notify 804 ;; Enable file notification.
801 (not auto-revert-notify-watch-descriptor)) 805 (when (and auto-revert-use-notify
802 (auto-revert-notify-add-watch)) 806 (not auto-revert-notify-watch-descriptor))
803 (auto-revert-handler))) 807 (auto-revert-notify-add-watch))
804 ;; Remove dead buffer from `auto-revert-buffer-list'. 808 (auto-revert-handler)))
805 (setq auto-revert-buffer-list 809 ;; Remove dead buffer from `auto-revert-buffer-list'.
806 (delq buf auto-revert-buffer-list)))) 810 (auto-revert-remove-current-buffer))))
807 (setq bufs (cdr bufs))) 811 (setq bufs (cdr bufs)))
808 (setq auto-revert-remaining-buffers bufs) 812 (setq auto-revert-remaining-buffers bufs)
809 ;; Check if we should cancel the timer. 813 ;; Check if we should cancel the timer.