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