Merge from emacs--rel--22
[bpt/emacs.git] / lisp / autorevert.el
index 5220f3f..f1e5b14 100644 (file)
@@ -276,9 +276,9 @@ the list of old buffers.")
   "Position of last known end of file.")
 
 (add-hook 'find-file-hook
-         (lambda ()
-           (set (make-local-variable 'auto-revert-tail-pos)
-                (nth 7 (file-attributes buffer-file-name)))))
+         (lambda ()
+           (set (make-local-variable 'auto-revert-tail-pos)
+                (nth 7 (file-attributes buffer-file-name)))))
 
 ;; Functions:
 
@@ -334,7 +334,7 @@ Use `auto-revert-mode' for changes other than appends!"
       (auto-revert-tail-mode 0)
       (error "This buffer is not visiting a file"))
     (if (and (buffer-modified-p)
-            (not auto-revert-tail-pos) ; library was loaded only after finding file
+            (zerop auto-revert-tail-pos) ; library was loaded only after finding file
             (not (y-or-n-p "Buffer is modified, so tail offset may be wrong.  Proceed? ")))
        (auto-revert-tail-mode 0)
       ;; a-r-tail-pos stores the size of the file at the time of the
@@ -348,11 +348,11 @@ Use `auto-revert-mode' for changes other than appends!"
       ;; revert, then you might miss some output then happened
       ;; between visiting the file and activating a-r-t-mode.
       (and (zerop auto-revert-tail-pos)
-          (not (verify-visited-file-modtime (current-buffer)))
-          (y-or-n-p "File changed on disk, content may be missing.  \
+           (not (verify-visited-file-modtime (current-buffer)))
+           (y-or-n-p "File changed on disk, content may be missing.  \
 Perform a full revert? ")
-          ;; Use this (not just revert-buffer) for point-preservation.
-          (auto-revert-handler))
+           ;; Use this (not just revert-buffer) for point-preservation.
+           (auto-revert-handler))
       ;; else we might reappend our own end when we save
       (add-hook 'before-save-hook (lambda () (auto-revert-tail-mode 0)) nil t)
       (or (local-variable-p 'auto-revert-tail-pos) ; don't lose prior position
@@ -463,20 +463,21 @@ This is an internal function used by Auto-Revert Mode."
 (defun auto-revert-tail-handler ()
   (let ((size (nth 7 (file-attributes buffer-file-name)))
        (modified (buffer-modified-p))
-       buffer-read-only                ; ignore
+       (inhibit-read-only t)           ; Ignore.
        (file buffer-file-name)
-       buffer-file-name)               ; ignore that file has changed
+       (buffer-file-name nil))         ; Ignore that file has changed.
     (when (> size auto-revert-tail-pos)
+      (run-hooks 'before-revert-hook)
       (undo-boundary)
       (save-restriction
        (widen)
        (save-excursion
          (goto-char (point-max))
          (insert-file-contents file nil auto-revert-tail-pos size)))
-      (run-mode-hooks 'after-revert-hook)
+      (run-hooks 'after-revert-hook)
       (undo-boundary)
       (setq auto-revert-tail-pos size)
-      (set-buffer-modified-p modified)))
+      (restore-buffer-modified-p modified)))
   (set-visited-file-modtime))
 
 (defun auto-revert-buffers ()
@@ -550,5 +551,5 @@ the timer when no buffers need to be checked."
 
 (run-hooks 'auto-revert-load-hook)
 
-;;; arch-tag: f6bcb07b-4841-477e-9e44-b18678e58876
+;; arch-tag: f6bcb07b-4841-477e-9e44-b18678e58876
 ;;; autorevert.el ends here