Function: auto-revert-handler
auto-revert-handler is a byte-compiled function defined in
autorevert.el.gz.
Signature
(auto-revert-handler)
Documentation
Revert current buffer, if appropriate.
This is an internal function used by Auto-Revert Mode.
Source Code
;; Defined in /usr/src/emacs/lisp/autorevert.el.gz
(defun auto-revert-handler ()
"Revert current buffer, if appropriate.
This is an internal function used by Auto-Revert Mode."
(when auto-revert-debug
(message "auto-revert-handler %S" (current-buffer)))
(let* ((buffer (current-buffer)) size
;; Tramp caches the file attributes. Setting
;; `remote-file-name-inhibit-cache' forces Tramp to reread
;; the values.
(remote-file-name-inhibit-cache t)
(revert
(and (or auto-revert-remote-files
(not (file-remote-p default-directory)))
(or (not auto-revert-notify-watch-descriptor)
auto-revert-notify-modified-p)
(not (memq (current-buffer) inhibit-auto-revert-buffers))
(if (and buffer-file-name auto-revert-tail-mode)
(and (file-readable-p buffer-file-name)
(/= auto-revert-tail-pos
(setq size
(file-attribute-size
(file-attributes buffer-file-name)))))
(and (or auto-revert-mode auto-revert--global-mode)
(funcall (or buffer-stale-function
#'buffer-stale--default-function)
t)))))
eob eoblist)
(when (timerp auto-revert--lockout-timer)
(cancel-timer auto-revert--lockout-timer)
(setq auto-revert--lockout-timer nil))
(when revert
(when (and auto-revert-verbose
(not (eq revert 'fast)))
(message "Reverting buffer `%s'" (buffer-name)))
(setq auto-revert-notify-modified-p nil
auto-revert--last-time (current-time))
;; If point (or a window point) is at the end of the buffer, we
;; want to keep it at the end after reverting. This allows one
;; to tail a file.
(when buffer-file-name
(setq eob (eobp))
(walk-windows
(lambda (window)
(and (eq (window-buffer window) buffer)
(= (window-point window) (point-max))
(push window eoblist)))
'no-mini t))
(if auto-revert-tail-mode
(auto-revert-tail-handler size)
;; Bind buffer-read-only in case user has done C-x C-q, so as
;; not to forget that. This gives undesirable results when
;; the file's mode changes, but that is less common.
(let ((buffer-read-only buffer-read-only))
;; Bug#23276: When the file has been deleted, keep the
;; buffer unchanged.
(ignore-errors
(revert-buffer 'ignore-auto 'dont-ask 'preserve-modes))))
(when buffer-file-name
(when eob (goto-char (point-max)))
(dolist (window eoblist)
(set-window-point window (point-max)))))
;; `preserve-modes' avoids changing the (minor) modes. But we do
;; want to reset the mode for VC, so we do it manually.
(when (and (not auto-revert-tail-mode) (or revert auto-revert-check-vc-info))
(let ((revert-buffer-in-progress t))
(vc-refresh-state)))))