'kill-buffer-hook
#'auto-revert-remove-current-buffer
nil t))
- (when auto-revert-use-notify (auto-revert-notify-rm-watch))
+ (when auto-revert-notify-watch-descriptor (auto-revert-notify-rm-watch))
(auto-revert-remove-current-buffer))
(auto-revert-set-timer)
(when auto-revert-mode
(auto-revert-buffers)
(dolist (buf (buffer-list))
(with-current-buffer buf
- (when auto-revert-use-notify
+ (when auto-revert-notify-watch-descriptor
(auto-revert-notify-rm-watch))))))
(defun auto-revert-set-timer ()
(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-use-notify' are non-nil.
- (if (or (string-match auto-revert-notify-exclude-dir-regexp
- (expand-file-name default-directory))
- (file-symlink-p (or buffer-file-name default-directory)))
-
- ;; Fallback to file checks.
- (setq-local auto-revert-use-notify nil)
-
- (when (not auto-revert-notify-watch-descriptor)
- (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)
+ ;; `auto-revert-notify-watch-descriptor' are non-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 default-directory)
- '(change)
- 'auto-revert-notify-handler))))
- (if auto-revert-notify-watch-descriptor
- (progn
- (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))
- ;; Fallback to file checks.
- (setq-local auto-revert-use-notify nil)))))
+ (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))
+ 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
(file-name-nondirectory buffer-file-name)))
;; A buffer w/o a file, like dired.
(null buffer-file-name)))
- (auto-revert-notify-rm-watch)
- (setq-local auto-revert-use-notify nil))))
+ (auto-revert-notify-rm-watch))))
;; Loop over all buffers, in order to find the intended one.
(cl-dolist (buffer buffers)
"Check if auto-revert is active (in current buffer or globally)."
(or auto-revert-mode
auto-revert-tail-mode
- (and
- global-auto-revert-mode
- (not global-auto-revert-ignore-buffer)
- (not (memq major-mode
- global-auto-revert-ignore-modes)))))
+ (and global-auto-revert-mode
+ (not global-auto-revert-ignore-buffer)
+ (not (memq major-mode global-auto-revert-ignore-modes)))))
(defun auto-revert-handler ()
"Revert current buffer, if appropriate.
(if buffer-file-name
(and (or auto-revert-remote-files
(not (file-remote-p buffer-file-name)))
- (or (not auto-revert-use-notify)
+ (or (not auto-revert-notify-watch-descriptor)
auto-revert-notify-modified-p)
(if auto-revert-tail-mode
(and (file-readable-p buffer-file-name)
:tags '(:expensive-test)
(let ((tmpfile (make-temp-file "auto-revert-test"))
- buf)
+ buf desc)
(unwind-protect
(progn
(write-region "any text" nil tmpfile nil 'no-message)
(sleep-for 1)
(auto-revert-mode 1)
(should auto-revert-mode)
+ (setq desc auto-revert-notify-watch-descriptor)
;; Remove file while reverting. We simulate this by
;; modifying `before-revert-hook'.
(should (string-match "any text" (buffer-string)))
;; With w32notify, the 'stopped' events are not sent.
(or (eq file-notify--library 'w32notify)
- (should-not auto-revert-use-notify))
+ (should-not auto-revert-notify-watch-descriptor))
;; Once the file has been recreated, the buffer shall be
;; reverted.
(auto-revert--wait-for-revert buf))
;; Check, that the buffer has been reverted.
(should (string-match "another text" (buffer-string)))
+ ;; When file notification is used, it must be reenabled
+ ;; after recreation of the file. We cannot expect that
+ ;; the descriptor is the same, so we just check the
+ ;; existence.
+ (should (eq (null desc) (null auto-revert-notify-watch-descriptor)))
;; An empty file shall still be reverted.
(ert-with-message-capture auto-revert--messages