]> code.delx.au - gnu-emacs/blobdiff - lisp/autorevert.el
Update docs for `customize-mode'
[gnu-emacs] / lisp / autorevert.el
index 37ee8eedcfde0f4ca11167a2fd2d236b59bdcc22..b8693dfb2106864b3b0d01e5154c72f3e6df60c2 100644 (file)
@@ -1,8 +1,8 @@
 ;;; autorevert.el --- revert buffers when files on disk change  -*- lexical-binding:t -*-
 
-;; Copyright (C) 1997-1999, 2001-2015 Free Software Foundation, Inc.
+;; Copyright (C) 1997-1999, 2001-2016 Free Software Foundation, Inc.
 
-;; Author: Anders Lindgren <andersl@andersl.com>
+;; Author: Anders Lindgren
 ;; Keywords: convenience
 ;; Created: 1997-06-01
 ;; Date: 1999-11-30
@@ -458,7 +458,11 @@ specifies in the mode line."
   :global t :group 'auto-revert :lighter global-auto-revert-mode-text
   (auto-revert-set-timer)
   (if global-auto-revert-mode
-      (auto-revert-buffers)
+      (progn
+        ;; Disable file notification because it could use too many resources.
+        ;; See Bug#22814.
+        (setq auto-revert-use-notify nil)
+        (auto-revert-buffers))
     (dolist (buf (buffer-list))
       (with-current-buffer buf
        (when auto-revert-use-notify
@@ -570,37 +574,54 @@ no more reverts are possible until the next call of
       ;; 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 (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 w/o 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.
-             (when (/= auto-revert-buffers-counter-lockedout
-                       auto-revert-buffers-counter)
-               (auto-revert-handler)
-               (setq auto-revert-buffers-counter-lockedout
-                     auto-revert-buffers-counter))
-
-             ;; No need to check other buffers.
-             (cl-return))))))))
+
+      (if (eq action 'stopped)
+          ;; File notification has stopped.  Continue with polling.
+          (cl-dolist (buffer buffers)
+            (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 w/o a file, like dired.
+                     (null buffer-file-name))
+                (auto-revert-notify-rm-watch)
+                (setq-local auto-revert-use-notify nil))))
+
+        ;; 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 (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 w/o 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.
+                (when (/= auto-revert-buffers-counter-lockedout
+                          auto-revert-buffers-counter)
+                  (auto-revert-handler)
+                  (setq auto-revert-buffers-counter-lockedout
+                        auto-revert-buffers-counter))
+
+                ;; No need to check other buffers.
+                (cl-return)))))))))
 
 (defun auto-revert-active-p ()
   "Check if auto-revert is active (in current buffer or globally)."
@@ -647,8 +668,8 @@ This is an internal function used by Auto-Revert Mode."
                  (not (eq revert 'fast)))
         (message "Reverting buffer `%s'." (buffer-name)))
       ;; 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 to
-      ;; tail a file.
+      ;; 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
@@ -663,7 +684,10 @@ This is an internal function used by Auto-Revert Mode."
         ;; 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))
-          (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes)))
+          ;; 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)
@@ -671,7 +695,7 @@ This is an internal function used by Auto-Revert Mode."
     ;; `preserve-modes' avoids changing the (minor) modes.  But we do
     ;; want to reset the mode for VC, so we do it manually.
     (when (or revert auto-revert-check-vc-info)
-      (vc-find-file-hook))))
+      (vc-refresh-state))))
 
 (defun auto-revert-tail-handler (size)
   (let ((modified (buffer-modified-p))