More tweaks of skeleton documentation wrt \n behavior at bol/eol.
[bpt/emacs.git] / lisp / autorevert.el
index 978a834..f1074e2 100644 (file)
@@ -1,6 +1,6 @@
 ;;; 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
@@ -504,13 +504,15 @@ will use an up-to-date value of `auto-revert-interval'"
 
 (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
@@ -531,7 +533,7 @@ will use an up-to-date value of `auto-revert-interval'"
 
 (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))
@@ -541,28 +543,31 @@ will use an up-to-date value of `auto-revert-interval'"
       ;; 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)."
@@ -667,7 +672,7 @@ Should `auto-revert-mode' be active in some buffers, those buffers
 are checked.
 
 Non-file buffers that have a custom `revert-buffer-function' and
-`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.