]> code.delx.au - gnu-emacs/blobdiff - lisp/autorevert.el
* indent.el (indent-for-tab-command): Fix typo in docstring.
[gnu-emacs] / lisp / autorevert.el
index f1e5b146058012320fe9c96bd4df04e0c7882c87..5eb6fb07f9a3e0c54c7f6c459e5bac9abc49521d 100644 (file)
@@ -1,7 +1,7 @@
 ;;; autorevert.el --- revert buffers when files on disk change
 
 ;; Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 ;; Author: Anders Lindgren <andersl@andersl.com>
 ;; Keywords: convenience
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -21,9 +21,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -416,12 +414,16 @@ will use an up-to-date value of `auto-revert-interval'"
   "Revert current buffer, if appropriate.
 This is an internal function used by Auto-Revert Mode."
   (when (or auto-revert-tail-mode (not (buffer-modified-p)))
-    (let* ((buffer (current-buffer))
+    (let* ((buffer (current-buffer)) size
           (revert
            (or (and buffer-file-name
                     (not (file-remote-p buffer-file-name))
                     (file-readable-p buffer-file-name)
-                    (not (verify-visited-file-modtime buffer)))
+                    (if auto-revert-tail-mode
+                        (/= auto-revert-tail-pos
+                           (setq size
+                                 (nth 7 (file-attributes buffer-file-name))))
+                      (not (verify-visited-file-modtime buffer))))
                (and (or auto-revert-mode
                         global-auto-revert-non-file-buffers)
                     revert-buffer-function
@@ -445,7 +447,7 @@ This is an internal function used by Auto-Revert Mode."
                    (push window eoblist)))
           'no-mini t))
        (if auto-revert-tail-mode
-           (auto-revert-tail-handler)
+           (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.
@@ -460,20 +462,22 @@ This is an internal function used by Auto-Revert Mode."
       (when (or revert auto-revert-check-vc-info)
        (vc-find-file-hook)))))
 
-(defun auto-revert-tail-handler ()
-  (let ((size (nth 7 (file-attributes buffer-file-name)))
-       (modified (buffer-modified-p))
+(defun auto-revert-tail-handler (size)  
+  (let ((modified (buffer-modified-p))
        (inhibit-read-only t)           ; Ignore.
        (file buffer-file-name)
        (buffer-file-name nil))         ; Ignore that file has changed.
-    (when (> size auto-revert-tail-pos)
+    (when (/= auto-revert-tail-pos size)
       (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)))
+         (insert-file-contents file nil
+                               (and (< auto-revert-tail-pos size)
+                                    auto-revert-tail-pos)
+                               size)))
       (run-hooks 'after-revert-hook)
       (undo-boundary)
       (setq auto-revert-tail-pos size)
@@ -524,7 +528,7 @@ the timer when no buffers need to be checked."
                  (not (and auto-revert-stop-on-user-input
                            (input-pending-p))))
        (let ((buf (car bufs)))
-         (if (buffer-name buf)         ; Buffer still alive?
+          (if (buffer-live-p buf)
              (with-current-buffer buf
                ;; Test if someone has turned off Auto-Revert Mode in a
                ;; non-standard way, for example by changing major mode.