Function: auto-revert-notify-handler
auto-revert-notify-handler is a byte-compiled function defined in
autorevert.el.gz.
Signature
(auto-revert-notify-handler EVENT)
Documentation
Handle an EVENT returned from file notification.
Source Code
;; Defined in /usr/src/emacs/lisp/autorevert.el.gz
(defun auto-revert-notify-handler (event)
"Handle an EVENT returned from file notification."
(with-demoted-errors "Error while auto-reverting: %S"
(let* ((descriptor (car event))
(action (nth 1 event))
(file (nth 2 event))
(file1 (nth 3 event)) ;; Target of `renamed'.
(buffer (alist-get descriptor auto-revert--buffer-by-watch-descriptor
nil nil #'equal)))
;; Check, that event is meant for us.
(cl-assert descriptor)
;; Since we watch a directory, a file name must be returned.
(cl-assert (stringp file))
(when (eq action 'renamed) (cl-assert (stringp file1)))
(when auto-revert-debug
(message "auto-revert-notify-handler %S" event))
(when (buffer-live-p buffer)
(if (eq action 'stopped)
;; File notification has stopped. Continue with polling.
(with-current-buffer buffer
(when (or
;; A buffer associated with a file.
(and (stringp buffer-file-name)
(string-equal
(file-name-nondirectory file)
(file-name-nondirectory buffer-file-name)))
;; A buffer without a file, like dired.
(null buffer-file-name))
(auto-revert-notify-rm-watch)
;; Restart the timer if it wasn't running.
(unless auto-revert-timer
(auto-revert-set-timer))))
(with-current-buffer buffer
(when (or
;; A buffer associated with a file.
(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)))))
;; A buffer without a file, like dired.
(and (null buffer-file-name)
(memq action '(created renamed deleted))))
;; Mark buffer modified.
(setq auto-revert-notify-modified-p t)
;; Revert the buffer now if we're not locked out.
(unless auto-revert--lockout-timer
(auto-revert-handler)
(setq auto-revert--lockout-timer
(run-with-timer
auto-revert--lockout-interval nil
#'auto-revert--end-lockout buffer))))))))))