Fix minor mode docstrings for the new meaning of a nil ARG.
[bpt/emacs.git] / lisp / autorevert.el
index 2cca9b0..817aaff 100644 (file)
@@ -1,7 +1,6 @@
 ;;; autorevert.el --- revert buffers when files on disk change
 
-;; Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1997-1999, 2001-2011 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 +20,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:
 
@@ -68,6 +65,7 @@
 ;; change by growing at the end.  It only appends the new output,
 ;; instead of reverting the entire buffer.  It does so even if the
 ;; buffer contains unsaved changes.  (Because they will not be lost.)
+;; Auto Revert Tail Mode works also for remote files.
 
 ;; Usage:
 ;;
@@ -118,12 +116,12 @@ Global Auto-Revert Mode applies to all buffers."
 ;;; What's this?: ;; Autoload for the benefit of `make-mode-line-mouse-sensitive'.
 ;;; What's this?: ;;;###autoload
 (defvar auto-revert-mode nil
-  "*Non-nil when Auto-Revert Mode is active.
+  "Non-nil when Auto-Revert Mode is active.
 Never set this variable directly, use the command `auto-revert-mode' instead.")
 (put 'auto-revert-mode 'permanent-local t)
 
 (defvar auto-revert-tail-mode nil
-  "*Non-nil when Auto-Revert Tail Mode is active.
+  "Non-nil when Auto-Revert Tail Mode is active.
 Never set this variable directly, use the command
 `auto-revert-tail-mode' instead.")
 (put 'auto-revert-tail-mode 'permanent-local t)
@@ -209,10 +207,13 @@ would only waste precious space."
 When non-nil, both file buffers and buffers with a custom
 `revert-buffer-function' and a `buffer-stale-function' are
 reverted by Global Auto-Revert mode.  These include the Buffer
-List buffer, and Dired buffers showing complete local
-directories.  Dired buffers do not auto-revert as a result of
-changes in subdirectories or in the contents, size, modes, etc.,
-of files.  You may still sometimes want to revert them manually.
+List buffer displayed by `buffer-menu', and Dired buffers showing
+complete local directories.  The Buffer List buffer reverts every
+`auto-revert-interval' seconds; Dired buffers when the file list of
+the main directory changes.  Dired buffers do not auto-revert as
+a result of changes in subdirectories, or in the contents, size,
+modes, etc., of files.  You may still sometimes want to revert
+them manually.
 
 Use this option with care since it could lead to excessive auto-reverts.
 For more information, see Info node `(emacs)Autorevert'."
@@ -253,8 +254,7 @@ buffers.  CPU usage depends on the version control system."
   :version "22.1")
 
 (defvar global-auto-revert-ignore-buffer nil
-  "*When non-nil, Global Auto-Revert Mode will not revert this buffer.
-
+  "When non-nil, Global Auto-Revert Mode will not revert this buffer.
 This variable becomes buffer local when set in any fashion.")
 (make-variable-buffer-local 'global-auto-revert-ignore-buffer)
 
@@ -284,10 +284,15 @@ the list of old buffers.")
 
 ;;;###autoload
 (define-minor-mode auto-revert-mode
-  "Toggle reverting buffer when file on disk changes.
+  "Toggle reverting buffer when the file changes (Auto Revert mode).
+With a prefix argument ARG, enable Auto Revert mode if ARG is
+positive, and disable it otherwise.  If called from Lisp, enable
+the mode if ARG is omitted or nil.
+
+Auto Revert mode is a minor mode that affects only the current
+buffer.  When enabled, it reverts the buffer when the file on
+disk changes.
 
-With arg, turn Auto Revert mode on if and only if arg is positive.
-This is a minor mode that affects only the current buffer.
 Use `global-auto-revert-mode' to automatically revert all buffers.
 Use `auto-revert-tail-mode' if you know that the file will only grow
 without being changed in the part that is already in the buffer."
@@ -314,14 +319,16 @@ This function is designed to be added to hooks, for example:
 
 ;;;###autoload
 (define-minor-mode auto-revert-tail-mode
-  "Toggle reverting tail of buffer when file on disk grows.
-With arg, turn Tail mode on if arg is positive, otherwise turn it off.
+  "Toggle reverting tail of buffer when the file grows.
+With a prefix argument ARG, enable Auto-Revert Tail mode if ARG
+is positive, and disable it otherwise.  If called from Lisp,
+enable the mode if ARG is omitted or nil.
 
-When Tail mode is enabled, the tail of the file is constantly
-followed, as with the shell command `tail -f'.  This means that
-whenever the file grows on disk (presumably because some
-background process is appending to it from time to time), this is
-reflected in the current buffer.
+When Auto Revert Tail mode is enabled, the tail of the file is
+constantly followed, as with the shell command `tail -f'.  This
+means that whenever the file grows on disk (presumably because
+some background process is appending to it from time to time),
+this is reflected in the current buffer.
 
 You can edit the buffer and turn this mode off and on again as
 you please.  But make sure the background process has stopped
@@ -367,7 +374,7 @@ Perform a full revert? ")
 
 ;;;###autoload
 (defun turn-on-auto-revert-tail-mode ()
-  "Turn on Auto-Revert Tail Mode.
+  "Turn on Auto-Revert Tail mode.
 
 This function is designed to be added to hooks, for example:
   (add-hook 'my-logfile-mode-hook 'turn-on-auto-revert-tail-mode)"
@@ -376,11 +383,24 @@ This function is designed to be added to hooks, for example:
 
 ;;;###autoload
 (define-minor-mode global-auto-revert-mode
-  "Revert any buffer when file on disk changes.
-
-With arg, turn Auto Revert mode on globally if and only if arg is positive.
-This is a minor mode that affects all buffers.
-Use `auto-revert-mode' to revert a particular buffer."
+  "Toggle Global Auto Revert mode.
+With a prefix argument ARG, enable Global Auto Revert mode if ARG
+is positive, and disable it otherwise.  If called from Lisp,
+enable the mode if ARG is omitted or nil.
+
+Global Auto Revert mode is a global minor mode that reverts any
+buffer associated with a file when the file changes on disk.  Use
+`auto-revert-mode' to revert a particular buffer.
+
+If `global-auto-revert-non-file-buffers' is non-nil, this mode
+may also revert some non-file buffers, as described in the
+documentation of that variable.  It ignores buffers with modes
+matching `global-auto-revert-ignore-modes', and buffers with a
+non-nil vale of `global-auto-revert-ignore-buffer'.
+
+This function calls the hook `global-auto-revert-mode-hook'.
+It displays the text that `global-auto-revert-mode-text'
+specifies in the mode line."
   :global t :group 'auto-revert :lighter global-auto-revert-mode-text
   (auto-revert-set-timer)
   (when global-auto-revert-mode
@@ -419,13 +439,18 @@ This is an internal function used by Auto-Revert Mode."
     (let* ((buffer (current-buffer)) size
           (revert
            (or (and buffer-file-name
-                    (not (file-remote-p buffer-file-name))
                     (file-readable-p buffer-file-name)
                     (if auto-revert-tail-mode
-                        (/= auto-revert-tail-pos
-                           (setq size
-                                 (nth 7 (file-attributes buffer-file-name))))
-                      (not (verify-visited-file-modtime buffer))))
+                        ;; Tramp caches the file attributes.  Setting
+                        ;; `remote-file-name-inhibit-cache' forces Tramp
+                        ;; to reread the values.
+                        (let ((remote-file-name-inhibit-cache t))
+                          (/= auto-revert-tail-pos
+                              (setq size
+                                    (nth 7 (file-attributes
+                                            buffer-file-name)))))
+                      (and (not (file-remote-p buffer-file-name))
+                           (not (verify-visited-file-modtime buffer)))))
                (and (or auto-revert-mode
                         global-auto-revert-non-file-buffers)
                     revert-buffer-function
@@ -443,10 +468,10 @@ This is an internal function used by Auto-Revert Mode."
        (when buffer-file-name
          (setq eob (eobp))
          (walk-windows
-          #'(lambda (window)
-              (and (eq (window-buffer window) buffer)
-                   (= (window-point window) (point-max))
-                   (push window eoblist)))
+          (lambda (window)
+            (and (eq (window-buffer window) buffer)
+                 (= (window-point window) (point-max))
+                 (push window eoblist)))
           'no-mini t))
        (if auto-revert-tail-mode
            (auto-revert-tail-handler size)
@@ -464,7 +489,7 @@ 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 (size)  
+(defun auto-revert-tail-handler (size)
   (let ((modified (buffer-modified-p))
        (inhibit-read-only t)           ; Ignore.
        (file buffer-file-name)
@@ -530,7 +555,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.
@@ -557,5 +582,4 @@ the timer when no buffers need to be checked."
 
 (run-hooks 'auto-revert-load-hook)
 
-;; arch-tag: f6bcb07b-4841-477e-9e44-b18678e58876
 ;;; autorevert.el ends here