;;; autorevert.el --- revert buffers when files on disk change
-;; Copyright (C) 1997-1999, 2001-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1997-1999, 2001-2014 Free Software Foundation, Inc.
;; Author: Anders Lindgren <andersl@andersl.com>
;; Keywords: convenience
(defun auto-revert-notify-add-watch ()
"Enable file notification for current buffer's associated file."
- (when (string-match auto-revert-notify-exclude-dir-regexp
- (expand-file-name default-directory))
+ ;; We can assume that `buffer-file-name' and
+ ;; `auto-revert-use-notify' are non-nil.
+ (when (or (string-match auto-revert-notify-exclude-dir-regexp
+ (expand-file-name default-directory))
+ (file-symlink-p buffer-file-name))
;; Fallback to file checks.
(set (make-local-variable 'auto-revert-use-notify) nil))
- (when (and buffer-file-name auto-revert-use-notify
- (not auto-revert-notify-watch-descriptor))
+ (when (not auto-revert-notify-watch-descriptor)
(setq auto-revert-notify-watch-descriptor
(ignore-errors
(file-notify-add-watch
(defun auto-revert-notify-handler (event)
"Handle an EVENT returned from file notification."
- (ignore-errors
+ (with-demoted-errors
(let* ((descriptor (car event))
(action (nth 1 event))
(file (nth 2 event))
;; Check, that event is meant for us.
(cl-assert descriptor)
;; We do not handle `deleted', because nothing has to be refreshed.
- (cl-assert (memq action '(attribute-changed changed created renamed)) t)
- ;; Since we watch a directory, a file name must be returned.
- (cl-assert (stringp file))
- (when (eq action 'renamed) (cl-assert (stringp file1)))
- ;; Loop over all buffers, in order to find the intended one.
- (dolist (buffer buffers)
- (when (buffer-live-p buffer)
- (with-current-buffer buffer
- (when (and (stringp buffer-file-name)
- (or
- (and (memq action '(attribute-changed changed created))
- (string-equal
- (file-name-nondirectory file)
- (file-name-nondirectory buffer-file-name)))
- (and (eq action 'renamed)
- (string-equal
- (file-name-nondirectory file1)
- (file-name-nondirectory buffer-file-name)))))
- ;; Mark buffer modified.
- (setq auto-revert-notify-modified-p t)
- ;; No need to check other buffers.
- (cl-return))))))))
+ (unless (eq action 'deleted)
+ (cl-assert (memq action '(attribute-changed changed created renamed))
+ t)
+ ;; Since we watch a directory, a file name must be returned.
+ (cl-assert (stringp file))
+ (when (eq action 'renamed) (cl-assert (stringp file1)))
+ ;; Loop over all buffers, in order to find the intended one.
+ (cl-dolist (buffer buffers)
+ (when (buffer-live-p buffer)
+ (with-current-buffer buffer
+ (when (and (stringp buffer-file-name)
+ (or
+ (and (memq action '(attribute-changed changed
+ created))
+ (string-equal
+ (file-name-nondirectory file)
+ (file-name-nondirectory buffer-file-name)))
+ (and (eq action 'renamed)
+ (string-equal
+ (file-name-nondirectory file1)
+ (file-name-nondirectory buffer-file-name)))))
+ ;; Mark buffer modified.
+ (setq auto-revert-notify-modified-p t)
+ ;; No need to check other buffers.
+ (cl-return)))))))))
(defun auto-revert-active-p ()
"Check if auto-revert is active (in current buffer or globally)."
(setq size
(nth 7 (file-attributes
buffer-file-name)))))
- (and (file-readable-p buffer-file-name)
- (not (verify-visited-file-modtime buffer)))))
+ (funcall (or buffer-stale-function
+ #'buffer-stale--default-function)
+ t)))
(and (or auto-revert-mode
global-auto-revert-non-file-buffers)
- revert-buffer-function
- (boundp 'buffer-stale-function)
- (functionp buffer-stale-function)
- (funcall buffer-stale-function t))))
+ (funcall (or buffer-stale-function
+ #'buffer-stale--default-function)
+ t))))
eob eoblist)
(setq auto-revert-notify-modified-p nil)
(when revert
are checked.
Non-file buffers that have a custom `revert-buffer-function' and
-a `buffer-stale-function' are reverted either when Auto-Revert
+`buffer-stale-function' are reverted either when Auto-Revert
Mode is active in that buffer, or when the variable
`global-auto-revert-non-file-buffers' is non-nil and Global
Auto-Revert Mode is active.