Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / doc / emacs / arevert-xtra.texi
CommitLineData
6f585e44 1@c This is part of the Emacs manual.
73b0cd50 2@c Copyright (C) 2004-2011
82ec412e 3@c Free Software Foundation, Inc.
6f585e44
EZ
4@c See file emacs.texi for copying conditions.
5@c
c5184807
EZ
6@c This file is included either in emacs-xtra.texi (when producing the
7@c printed version) or in the main Emacs manual (for the on-line version).
8@node Autorevert
75962ab7 9@section Auto Reverting Non-File Buffers
c5184807 10
82ec412e 11Global Auto Revert Mode normally only reverts file buffers. There are
c5184807 12two ways to auto-revert certain non-file buffers: enabling Auto Revert
82ec412e
GM
13Mode in those buffers (using @kbd{M-x auto-revert-mode}); and setting
14@code{global-auto-revert-non-file-buffers} non-@code{nil}. The latter
c5184807 15enables Auto Reverting for all types of buffers for which it is
82ec412e 16implemented (listed in the menu below).
c5184807
EZ
17
18Like file buffers, non-file buffers should normally not revert while
19you are working on them, or while they contain information that might
20get lost after reverting. Therefore, they do not revert if they are
21``modified''. This can get tricky, because deciding when a non-file
22buffer should be marked modified is usually more difficult than for
23file buffers.
24
25Another tricky detail is that, for efficiency reasons, Auto Revert
26often does not try to detect all possible changes in the buffer, only
27changes that are ``major'' or easy to detect. Hence, enabling
28auto-reverting for a non-file buffer does not always guarantee that
82ec412e 29all information in the buffer is up-to-date, and does not necessarily
c5184807
EZ
30make manual reverts useless.
31
82ec412e 32At the other extreme, certain buffers automatically revert every
c5184807
EZ
33@code{auto-revert-interval} seconds. (This currently only applies to
34the Buffer Menu.) In this case, Auto Revert does not print any
35messages while reverting, even when @code{auto-revert-verbose} is
36non-@code{nil}.
37
38The details depend on the particular types of buffers and are
39explained in the corresponding sections.
40
41@menu
75962ab7
GM
42* Auto Reverting the Buffer Menu:: Auto Revert of the Buffer Menu.
43* Auto Reverting Dired:: Auto Revert of Dired buffers.
44* Supporting additional buffers:: How to add more Auto Revert support.
c5184807
EZ
45@end menu
46
47@node Auto Reverting the Buffer Menu
48@subsection Auto Reverting the Buffer Menu
49
50If auto-reverting of non-file buffers is enabled, the Buffer Menu
51automatically reverts every @code{auto-revert-interval} seconds,
52whether there is a need for it or not. (It would probably take longer
53to check whether there is a need than to actually revert.)
54
55If the Buffer Menu inappropriately gets marked modified, just revert
56it manually using @kbd{g} and auto-reverting will resume. However, if
57you marked certain buffers to get deleted or to be displayed, you have
58to be careful, because reverting erases all marks. The fact that
59adding marks sets the buffer's modified flag prevents Auto Revert from
60automatically erasing the marks.
61
62@node Auto Reverting Dired
63@subsection Auto Reverting Dired buffers
64
65Auto-reverting Dired buffers currently works on GNU or Unix style
66operating systems. It may not work satisfactorily on some other
67systems.
68
69Dired buffers only auto-revert when the file list of the buffer's main
82ec412e
GM
70directory changes (e.g. when a new file is added). They do not
71auto-revert when information about a particular file changes
72(e.g. when the size changes) or when inserted subdirectories change.
73To be sure that @emph{all} listed information is up to date, you have
74to manually revert using @kbd{g}, @emph{even} if auto-reverting is
c5184807
EZ
75enabled in the Dired buffer. Sometimes, you might get the impression
76that modifying or saving files listed in the main directory actually
77does cause auto-reverting. This is because making changes to a file,
82ec412e 78or saving it, very often causes changes in the directory itself; for
c5184807
EZ
79instance, through backup files or auto-save files. However, this is
80not guaranteed.
81
82If the Dired buffer is marked modified and there are no changes you
83want to protect, then most of the time you can make auto-reverting
84resume by manually reverting the buffer using @kbd{g}. There is one
85exception. If you flag or mark files, you can safely revert the
86buffer. This will not erase the flags or marks (unless the marked
87file has been deleted, of course). However, the buffer will stay
88modified, even after reverting, and auto-reverting will not resume.
89This is because, if you flag or mark files, you may be working on the
90buffer and you might not want the buffer to change without warning.
91If you want auto-reverting to resume in the presence of marks and
92flags, mark the buffer non-modified using @kbd{M-~}. However, adding,
93deleting or changing marks or flags will mark it modified again.
94
82ec412e
GM
95Remote Dired buffers are not auto-reverted (because it may be slow).
96Neither are Dired buffers for which you used shell wildcards or file
97arguments to list only some of the files. @samp{*Find*} and
98@samp{*Locate*} buffers do not auto-revert either.
c5184807
EZ
99
100@node Supporting additional buffers
101@subsection Adding Support for Auto-Reverting additional Buffers.
102
103This section is intended for Elisp programmers who would like to add
104support for auto-reverting new types of buffers.
105
106To support auto-reverting the buffer must first of all have a
107@code{revert-buffer-function}. @xref{Definition of
108revert-buffer-function,, Reverting, elisp, the Emacs Lisp Reference Manual}.
109
110In addition, it @emph{must} have a @code{buffer-stale-function}.
111
112@defvar buffer-stale-function
113The value of this variable is a function to check whether a non-file
114buffer needs reverting. This should be a function with one optional
115argument @var{noconfirm}. The function should return non-@code{nil}
116if the buffer should be reverted. The buffer is current when this
117function is called.
118
119While this function is mainly intended for use in auto-reverting, it
120could be used for other purposes as well. For instance, if
121auto-reverting is not enabled, it could be used to warn the user that
122the buffer needs reverting. The idea behind the @var{noconfirm}
123argument is that it should be @code{t} if the buffer is going to be
124reverted without asking the user and @code{nil} if the function is
125just going to be used to warn the user that the buffer is out of date.
126In particular, for use in auto-reverting, @var{noconfirm} is @code{t}.
127If the function is only going to be used for auto-reverting, you can
128ignore the @var{noconfirm} argument.
129
130If you just want to automatically auto-revert every
82ec412e 131@code{auto-revert-interval} seconds (like the Buffer Menu), use:
c5184807
EZ
132
133@example
134(set (make-local-variable 'buffer-stale-function)
135 #'(lambda (&optional noconfirm) 'fast))
136@end example
137
138@noindent
139in the buffer's mode function.
140
141The special return value @samp{fast} tells the caller that the need
142for reverting was not checked, but that reverting the buffer is fast.
143It also tells Auto Revert not to print any revert messages, even if
144@code{auto-revert-verbose} is non-@code{nil}. This is important, as
145getting revert messages every @code{auto-revert-interval} seconds can
146be very annoying. The information provided by this return value could
147also be useful if the function is consulted for purposes other than
148auto-reverting.
149@end defvar
150
151Once the buffer has a @code{revert-buffer-function} and a
152@code{buffer-stale-function}, several problems usually remain.
153
154The buffer will only auto-revert if it is marked unmodified. Hence,
155you will have to make sure that various functions mark the buffer
156modified if and only if either the buffer contains information that
82ec412e 157might be lost by reverting, or there is reason to believe that the user
c5184807
EZ
158might be inconvenienced by auto-reverting, because he is actively
159working on the buffer. The user can always override this by manually
160adjusting the modified status of the buffer. To support this, calling
161the @code{revert-buffer-function} on a buffer that is marked
162unmodified should always keep the buffer marked unmodified.
163
164It is important to assure that point does not continuously jump around
165as a consequence of auto-reverting. Of course, moving point might be
166inevitable if the buffer radically changes.
167
168You should make sure that the @code{revert-buffer-function} does not
82ec412e
GM
169print messages that unnecessarily duplicate Auto Revert's own messages,
170displayed if @code{auto-revert-verbose} is @code{t}, and effectively
171override a @code{nil} value for @code{auto-revert-verbose}. Hence,
172adapting a mode for auto-reverting often involves getting rid of such
173messages. This is especially important for buffers that automatically
174revert every @code{auto-revert-interval} seconds.
c5184807 175
82ec412e
GM
176If the new auto-reverting is part of Emacs, you should mention it
177in the documentation string of @code{global-auto-revert-non-file-buffers}.
c5184807
EZ
178
179@ifinfo
82ec412e 180Similarly, you should add a node to this chapter's menu. This node
c5184807
EZ
181@end ifinfo
182@ifnotinfo
82ec412e 183Similarly, you should add a section to this chapter. This section
c5184807
EZ
184@end ifnotinfo
185should at the very least make clear whether enabling auto-reverting
186for the buffer reliably assures that all information in the buffer is
187completely up to date (or will be after @code{auto-revert-interval}
188seconds).