root/trunk/man/files.texi

Revision 4220, 122.6 kB (checked in by miyoshi, 8 months ago)

Sync up with Emacs22.2.

Line 
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 1999, 2000,
3 @c   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node Files, Buffers, Keyboard Macros, Top
6 @chapter File Handling
7 @cindex files
8
9   The operating system stores data permanently in named @dfn{files}, so
10 most of the text you edit with Emacs comes from a file and is ultimately
11 stored in a file.
12
13   To edit a file, you must tell Emacs to read the file and prepare a
14 buffer containing a copy of the file's text.  This is called
15 @dfn{visiting} the file.  Editing commands apply directly to text in the
16 buffer; that is, to the copy inside Emacs.  Your changes appear in the
17 file itself only when you @dfn{save} the buffer back into the file.
18
19   In addition to visiting and saving files, Emacs can delete, copy,
20 rename, and append to files, keep multiple versions of them, and operate
21 on file directories.
22
23 @menu
24 * File Names::          How to type and edit file-name arguments.
25 * Visiting::            Visiting a file prepares Emacs to edit the file.
26 * Saving::              Saving makes your changes permanent.
27 * Reverting::           Reverting cancels all the changes not saved.
28 @ifnottex
29 * Autorevert::          Auto Reverting non-file buffers.
30 @end ifnottex
31 * Auto Save::           Auto Save periodically protects against loss of data.
32 * File Aliases::        Handling multiple names for one file.
33 * Version Control::     Version control systems (RCS, CVS and SCCS).
34 * Directories::         Creating, deleting, and listing file directories.
35 * Comparing Files::     Finding where two files differ.
36 * Diff Mode::           Mode for editing file differences.
37 * Misc File Ops::       Other things you can do on files.
38 * Compressed Files::    Accessing compressed files.
39 * File Archives::       Operating on tar, zip, jar etc. archive files.
40 * Remote Files::        Accessing files on other sites.
41 * Quoted File Names::   Quoting special characters in file names.
42 * File Name Cache::     Completion against a list of files you often use.
43 * File Conveniences::   Convenience Features for Finding Files.
44 * Filesets::            Handling sets of files.
45 @end menu
46
47 @node File Names
48 @section File Names
49 @cindex file names
50
51   Most Emacs commands that operate on a file require you to specify the
52 file name.  (Saving and reverting are exceptions; the buffer knows which
53 file name to use for them.)  You enter the file name using the
54 minibuffer (@pxref{Minibuffer}).  @dfn{Completion} is available
55 (@pxref{Completion}) to make it easier to specify long file names.  When
56 completing file names, Emacs ignores those whose file-name extensions
57 appear in the variable @code{completion-ignored-extensions}; see
58 @ref{Completion Options}.
59
60   For most operations, there is a @dfn{default file name} which is used
61 if you type just @key{RET} to enter an empty argument.  Normally the
62 default file name is the name of the file visited in the current buffer;
63 this makes it easy to operate on that file with any of the Emacs file
64 commands.
65
66 @vindex default-directory
67   Each buffer has a default directory which is normally the same as the
68 directory of the file visited in that buffer.  When you enter a file
69 name without a directory, the default directory is used.  If you specify
70 a directory in a relative fashion, with a name that does not start with
71 a slash, it is interpreted with respect to the default directory.  The
72 default directory is kept in the variable @code{default-directory},
73 which has a separate value in every buffer.
74
75 @findex cd
76 @findex pwd
77   The command @kbd{M-x pwd} displays the current buffer's default
78 directory, and the command @kbd{M-x cd} sets it (to a value read using
79 the minibuffer).  A buffer's default directory changes only when the
80 @code{cd} command is used.  A file-visiting buffer's default directory
81 is initialized to the directory of the file it visits.  If you create
82 a buffer with @kbd{C-x b}, its default directory is copied from that
83 of the buffer that was current at the time.
84
85   For example, if the default file name is @file{/u/rms/gnu/gnu.tasks}
86 then the default directory is normally @file{/u/rms/gnu/}.  If you
87 type just @samp{foo}, which does not specify a directory, it is short
88 for @file{/u/rms/gnu/foo}.  @samp{../.login} would stand for
89 @file{/u/rms/.login}.  @samp{new/foo} would stand for the file name
90 @file{/u/rms/gnu/new/foo}.
91
92 @vindex insert-default-directory
93   The default directory actually appears in the minibuffer when the
94 minibuffer becomes active to read a file name.  This serves two
95 purposes: it @emph{shows} you what the default is, so that you can type
96 a relative file name and know with certainty what it will mean, and it
97 allows you to @emph{edit} the default to specify a different directory.
98 This insertion of the default directory is inhibited if the variable
99 @code{insert-default-directory} is set to @code{nil}.
100
101   Note that it is legitimate to type an absolute file name after you
102 enter the minibuffer, ignoring the presence of the default directory
103 name as part of the text.  The final minibuffer contents may look
104 invalid, but that is not so.  For example, if the minibuffer starts out
105 with @samp{/usr/tmp/} and you add @samp{/x1/rms/foo}, you get
106 @samp{/usr/tmp//x1/rms/foo}; but Emacs ignores everything through the
107 first slash in the double slash; the result is @samp{/x1/rms/foo}.
108 @xref{Minibuffer File}.
109
110 @cindex home directory shorthand
111   You can use @file{~/} in a file name to mean your home directory,
112 or @file{~@var{user-id}/} to mean the home directory of a user whose
113 login name is @code{user-id}@footnote{
114 On MS-Windows and MS-DOS systems, where a user doesn't have a home
115 directory, Emacs replaces @file{~/} with the value of the
116 environment variable @code{HOME}; see @ref{General Variables}.  On
117 these systems, the @file{~@var{user-id}/} construct is supported only
118 for the current user, i.e., only if @var{user-id} is the current
119 user's login name.}.
120
121 @cindex environment variables in file names
122 @cindex expansion of environment variables
123 @cindex @code{$} in file names
124   @anchor{File Names with $}@samp{$} in a file name is used to
125 substitute an environment variable.  The environment variable name
126 consists of all the alphanumeric characters after the @samp{$};
127 alternatively, it can be enclosed in braces after the @samp{$}.  For
128 example, if you have used the shell command @command{export
129 FOO=rms/hacks} to set up an environment variable named @env{FOO}, then
130 you can use @file{/u/$FOO/test.c} or @file{/u/$@{FOO@}/test.c} as an
131 abbreviation for @file{/u/rms/hacks/test.c}.  If the environment
132 variable is not defined, no substitution occurs: @file{/u/$notdefined}
133 stands for itself (assuming the environment variable @env{notdefined}
134 is not defined).
135
136   Note that shell commands to set environment variables affect Emacs
137 only when done before Emacs is started.
138
139   To access a file with @samp{$} in its name, if the @samp{$} causes
140 expansion, type @samp{$$}.  This pair is converted to a single
141 @samp{$} at the same time as variable substitution is performed for a
142 single @samp{$}.  Alternatively, quote the whole file name with
143 @samp{/:} (@pxref{Quoted File Names}).  File names which begin with a
144 literal @samp{~} should also be quoted with @samp{/:}.
145
146 @findex substitute-in-file-name
147   The Lisp function that performs the @samp{$}-substitution is called
148 @code{substitute-in-file-name}.  The substitution is performed only on
149 file names read as such using the minibuffer.
150
151   You can include non-@acronym{ASCII} characters in file names if you set the
152 variable @code{file-name-coding-system} to a non-@code{nil} value.
153 @xref{File Name Coding}.
154
155 @node Visiting
156 @section Visiting Files
157 @cindex visiting files
158 @cindex open file
159
160 @table @kbd
161 @item C-x C-f
162 Visit a file (@code{find-file}).
163 @item C-x C-r
164 Visit a file for viewing, without allowing changes to it
165 (@code{find-file-read-only}).
166 @item C-x C-v
167 Visit a different file instead of the one visited last
168 (@code{find-alternate-file}).
169 @item C-x 4 f
170 Visit a file, in another window (@code{find-file-other-window}).  Don't
171 alter what is displayed in the selected window.
172 @item C-x 5 f
173 Visit a file, in a new frame (@code{find-file-other-frame}).  Don't
174 alter what is displayed in the selected frame.
175 @item M-x find-file-literally
176 Visit a file with no conversion of the contents.
177 @end table
178
179 @cindex files, visiting and saving
180 @cindex saving files
181   @dfn{Visiting} a file means reading its contents into an Emacs
182 buffer so you can edit them.  Emacs makes a new buffer for each file
183 that you visit.  We often say that this buffer ``is visiting'' that
184 file, or that the buffer's ``visited file'' is that file.  Emacs
185 constructs the buffer name from the file name by throwing away the
186 directory, keeping just the name proper.  For example, a file named
187 @file{/usr/rms/emacs.tex} would get a buffer named @samp{emacs.tex}.
188 If there is already a buffer with that name, Emacs constructs a unique
189 name---the normal method is to append @samp{<2>}, @samp{<3>}, and so
190 on, but you can select other methods (@pxref{Uniquify}).
191
192   Each window's mode line shows the name of the buffer that is being displayed
193 in that window, so you can always tell what buffer you are editing.
194
195   The changes you make with editing commands are made in the Emacs
196 buffer.  They do not take effect in the file that you visited, or any
197 permanent place, until you @dfn{save} the buffer.  Saving the buffer
198 means that Emacs writes the current contents of the buffer into its
199 visited file.  @xref{Saving}.
200
201 @cindex modified (buffer)
202   If a buffer contains changes that have not been saved, we say the
203 buffer is @dfn{modified}.  This is important because it implies that
204 some changes will be lost if the buffer is not saved.  The mode line
205 displays two stars near the left margin to indicate that the buffer is
206 modified.
207
208 @kindex C-x C-f
209 @findex find-file
210   To visit a file, use the command @kbd{C-x C-f} (@code{find-file}).  Follow
211 the command with the name of the file you wish to visit, terminated by a
212 @key{RET}.
213
214   The file name is read using the minibuffer (@pxref{Minibuffer}), with
215 defaulting and completion in the standard manner (@pxref{File Names}).
216 While in the minibuffer, you can abort @kbd{C-x C-f} by typing
217 @kbd{C-g}.  File-name completion ignores certain file names; for more
218 about this, see @ref{Completion Options}.
219
220   Your confirmation that @kbd{C-x C-f} has completed successfully is
221 the appearance of new text on the screen and a new buffer name in the
222 mode line.  If the specified file does not exist and you could not
223 create it, or exists but you can't read it, then you get an error,
224 with an error message displayed in the echo area.
225
226   If you visit a file that is already in Emacs, @kbd{C-x C-f} does not make
227 another copy.  It selects the existing buffer containing that file.
228 However, before doing so, it checks whether the file itself has changed
229 since you visited or saved it last.  If the file has changed, Emacs offers
230 to reread it.
231
232 @vindex large-file-warning-threshold
233 @cindex maximum buffer size exceeded, error message
234   If you try to visit a file larger than
235 @code{large-file-warning-threshold} (the default is 10000000, which is
236 about 10 megabytes), Emacs will ask you for confirmation first.  You
237 can answer @kbd{y} to proceed with visiting the file.  Note, however,
238 that Emacs cannot visit files that are larger than the maximum Emacs
239 buffer size, which is around 256 megabytes on 32-bit machines
240 (@pxref{Buffers}).  If you try, Emacs will display an error message
241 saying that the maximum buffer size has been exceeded.
242
243 @cindex file selection dialog
244   On graphical displays there are two additional methods for
245 visiting files.  Firstly, when Emacs is built with a suitable GUI
246 toolkit, commands invoked with the mouse (by clicking on the menu bar
247 or tool bar) use the toolkit's standard File Selection dialog instead
248 of prompting for the file name in the minibuffer.  On Unix and
249 GNU/Linux platforms, Emacs does that when built with GTK, LessTif, and
250 Motif toolkits; on MS-Windows and Mac, the GUI version does that by default.
251 For information on how to customize this, see @ref{Dialog Boxes}.
252
253   Secondly, Emacs supports ``drag and drop''; dropping a file into an
254 ordinary Emacs window visits the file using that window.  However,
255 dropping a file into a window displaying a Dired buffer moves or
256 copies the file into the displayed directory.  For details, see
257 @ref{Drag and Drop}, and @ref{Misc Dired Features}.
258
259 @cindex creating files
260   What if you want to create a new file?  Just visit it.  Emacs displays
261 @samp{(New file)} in the echo area, but in other respects behaves as if
262 you had visited an existing empty file.  If you make any changes and
263 save them, the file is created.
264
265   Emacs recognizes from the contents of a file which end-of-line
266 convention it uses to separate lines---newline (used on GNU/Linux and
267 on Unix), carriage-return linefeed (used on Microsoft systems), or
268 just carriage-return (used on the Macintosh)---and automatically
269 converts the contents to the normal Emacs convention, which is that
270 the newline character separates lines.  This is a part of the general
271 feature of coding system conversion (@pxref{Coding Systems}), and
272 makes it possible to edit files imported from different operating
273 systems with equal convenience.  If you change the text and save the
274 file, Emacs performs the inverse conversion, changing newlines back
275 into carriage-return linefeed or just carriage-return if appropriate.
276
277 @vindex find-file-run-dired
278   If the file you specify is actually a directory, @kbd{C-x C-f} invokes
279 Dired, the Emacs directory browser, so that you can ``edit'' the contents
280 of the directory (@pxref{Dired}).  Dired is a convenient way to view, delete,
281 or operate on the files in the directory.  However, if the variable
282 @code{find-file-run-dired} is @code{nil}, then it is an error to try
283 to visit a directory.
284
285   Files which are actually collections of other files, or @dfn{file
286 archives}, are visited in special modes which invoke a Dired-like
287 environment to allow operations on archive members.  @xref{File
288 Archives}, for more about these features.
289
290 @cindex wildcard characters in file names
291 @vindex find-file-wildcards
292   If the file name you specify contains shell-style wildcard
293 characters, Emacs visits all the files that match it.  (On
294 case-insensitive filesystems, Emacs matches the wildcards disregarding
295 the letter case.)  Wildcards include @samp{?}, @samp{*}, and
296 @samp{[@dots{}]} sequences.  To enter the wild card @samp{?} in a file
297 name in the minibuffer, you need to type @kbd{C-q ?}.  @xref{Quoted
298 File Names}, for information on how to visit a file whose name
299 actually contains wildcard characters.  You can disable the wildcard
300 feature by customizing @code{find-file-wildcards}.
301
302   If you visit a file that the operating system won't let you modify,
303 or that is marked read-only, Emacs makes the buffer read-only too, so
304 that you won't go ahead and make changes that you'll have trouble
305 saving afterward.  You can make the buffer writable with @kbd{C-x C-q}
306 (@code{toggle-read-only}).  @xref{Misc Buffer}.
307
308 @kindex C-x C-r
309 @findex find-file-read-only
310   If you want to visit a file as read-only in order to protect
311 yourself from entering changes accidentally, visit it with the command
312 @kbd{C-x C-r} (@code{find-file-read-only}) instead of @kbd{C-x C-f}.
313
314 @kindex C-x C-v
315 @findex find-alternate-file
316   If you visit a nonexistent file unintentionally (because you typed the
317 wrong file name), use the @kbd{C-x C-v} command
318 (@code{find-alternate-file}) to visit the file you really wanted.
319 @kbd{C-x C-v} is similar to @kbd{C-x C-f}, but it kills the current
320 buffer (after first offering to save it if it is modified).  When
321 @kbd{C-x C-v} reads the file name to visit, it inserts the entire
322 default file name in the buffer, with point just after the directory
323 part; this is convenient if you made a slight error in typing the name.
324
325 @kindex C-x 4 f
326 @findex find-file-other-window
327   @kbd{C-x 4 f} (@code{find-file-other-window}) is like @kbd{C-x C-f}
328 except that the buffer containing the specified file is selected in another
329 window.  The window that was selected before @kbd{C-x 4 f} continues to
330 show the same buffer it was already showing.  If this command is used when
331 only one window is being displayed, that window is split in two, with one
332 window showing the same buffer as before, and the other one showing the
333 newly requested file.  @xref{Windows}.
334
335 @kindex C-x 5 f
336 @findex find-file-other-frame
337   @kbd{C-x 5 f} (@code{find-file-other-frame}) is similar, but opens a
338 new frame, or makes visible any existing frame showing the file you
339 seek.  This feature is available only when you are using a window
340 system.  @xref{Frames}.
341
342 @findex find-file-literally
343   If you wish to edit a file as a sequence of @acronym{ASCII} characters with no special
344 encoding or conversion, use the @kbd{M-x find-file-literally} command.
345 It visits a file, like @kbd{C-x C-f}, but does not do format conversion
346 (@pxref{Formatted Text}), character code conversion (@pxref{Coding
347 Systems}), or automatic uncompression (@pxref{Compressed Files}), and
348 does not add a final newline because of @code{require-final-newline}.
349 If you already have visited the same file in the usual (non-literal)
350 manner, this command asks you whether to visit it literally instead.
351
352 @vindex find-file-hook
353 @vindex find-file-not-found-functions
354   Two special hook variables allow extensions to modify the operation of
355 visiting files.  Visiting a file that does not exist runs the functions
356 in the list @code{find-file-not-found-functions}; this variable holds a list
357 of functions, and the functions are called one by one (with no
358 arguments) until one of them returns non-@code{nil}.  This is not a
359 normal hook, and the name ends in @samp{-functions} rather than @samp{-hook}
360 to indicate that fact.
361
362   Successful visiting of any file, whether existing or not, calls the
363 functions in the list @code{find-file-hook}, with no arguments.
364 This variable is a normal hook.  In the case of a nonexistent file, the
365 @code{find-file-not-found-functions} are run first.  @xref{Hooks}.
366
367   There are several ways to specify automatically the major mode for
368 editing the file (@pxref{Choosing Modes}), and to specify local
369 variables defined for that file (@pxref{File Variables}).
370
371 @node Saving
372 @section Saving Files
373
374   @dfn{Saving} a buffer in Emacs means writing its contents back into the file
375 that was visited in the buffer.
376
377 @menu
378 * Save Commands::       Commands for saving files.
379 * Backup::              How Emacs saves the old version of your file.
380 * Customize Save::      Customizing the saving of files.
381 * Interlocking::        How Emacs protects against simultaneous editing
382                           of one file by two users.
383 * Shadowing: File Shadowing.  Copying files to "shadows" automatically.
384 * Time Stamps::         Emacs can update time stamps on saved files.
385 @end menu
386
387 @node Save Commands
388 @subsection Commands for Saving Files
389
390   These are the commands that relate to saving and writing files.
391
392 @table @kbd
393 @item C-x C-s
394 Save the current buffer in its visited file on disk (@code{save-buffer}).
395 @item C-x s
396 Save any or all buffers in their visited files (@code{save-some-buffers}).
397 @item M-~
398 Forget that the current buffer has been changed (@code{not-modified}).
399 With prefix argument (@kbd{C-u}), mark the current buffer as changed.
400 @item C-x C-w
401 Save the current buffer with a specified file name (@code{write-file}).
402 @item M-x set-visited-file-name
403 Change the file name under which the current buffer will be saved.
404 @end table
405
406 @kindex C-x C-s
407 @findex save-buffer
408   When you wish to save the file and make your changes permanent, type
409 @kbd{C-x C-s} (@code{save-buffer}).  After saving is finished, @kbd{C-x C-s}
410 displays a message like this:
411
412 @example
413 Wrote /u/rms/gnu/gnu.tasks
414 @end example
415
416 @noindent
417 If the selected buffer is not modified (no changes have been made in it
418 since the buffer was created or last saved), saving is not really done,
419 because it would have no effect.  Instead, @kbd{C-x C-s} displays a message
420 like this in the echo area:
421
422 @example
423 (No changes need to be saved)
424 @end example
425
426 @kindex C-x s
427 @findex save-some-buffers
428   The command @kbd{C-x s} (@code{save-some-buffers}) offers to save any
429 or all modified buffers.  It asks you what to do with each buffer.  The
430 possible responses are analogous to those of @code{query-replace}:
431
432 @table @kbd
433 @item y
434 Save this buffer and ask about the rest of the buffers.
435 @item n
436 Don't save this buffer, but ask about the rest of the buffers.
437 @item !
438 Save this buffer and all the rest with no more questions.
439 @c following generates acceptable underfull hbox
440 @item @key{RET}
441 Terminate @code{save-some-buffers} without any more saving.
442 @item .
443 Save this buffer, then exit @code{save-some-buffers} without even asking
444 about other buffers.
445 @item C-r
446 View the buffer that you are currently being asked about.  When you exit
447 View mode, you get back to @code{save-some-buffers}, which asks the
448 question again.
449 @item d
450 Diff the buffer against its corresponding file, so you can see
451 what changes you would be saving.
452 @item C-h
453 Display a help message about these options.
454 @end table
455
456   @kbd{C-x C-c}, the key sequence to exit Emacs, invokes
457 @code{save-some-buffers} and therefore asks the same questions.
458
459 @kindex M-~
460 @findex not-modified
461   If you have changed a buffer but you do not want to save the changes,
462 you should take some action to prevent it.  Otherwise, each time you use
463 @kbd{C-x s} or @kbd{C-x C-c}, you are liable to save this buffer by
464 mistake.  One thing you can do is type @kbd{M-~} (@code{not-modified}),
465 which clears out the indication that the buffer is modified.  If you do
466 this, none of the save commands will believe that the buffer needs to be
467 saved.  (@samp{~} is often used as a mathematical symbol for `not'; thus
468 @kbd{M-~} is `not', metafied.)  You could also use
469 @code{set-visited-file-name} (see below) to mark the buffer as visiting
470 a different file name, one which is not in use for anything important.
471 Alternatively, you can cancel all the changes made since the file was
472 visited or saved, by reading the text from the file again.  This is
473 called @dfn{reverting}.  @xref{Reverting}.  (You could also undo all the
474 changes by repeating the undo command @kbd{C-x u} until you have undone
475 all the changes; but reverting is easier.)  You can also kill the buffer.
476
477 @findex set-visited-file-name
478   @kbd{M-x set-visited-file-name} alters the name of the file that the
479 current buffer is visiting.  It reads the new file name using the
480 minibuffer.  Then it marks the buffer as visiting that file name, and
481 changes the buffer name correspondingly.  @code{set-visited-file-name}
482 does not save the buffer in the newly visited file; it just alters the
483 records inside Emacs in case you do save later.  It also marks the
484 buffer as ``modified'' so that @kbd{C-x C-s} in that buffer
485 @emph{will} save.
486
487 @kindex C-x C-w
488 @findex write-file
489   If you wish to mark the buffer as visiting a different file and save it
490 right away, use @kbd{C-x C-w} (@code{write-file}).  It is
491 equivalent to @code{set-visited-file-name} followed by @kbd{C-x C-s}
492 (except that @kbd{C-x C-w} asks for confirmation if the file exists).
493 @kbd{C-x C-s} used on a buffer that is not visiting a file has the
494 same effect as @kbd{C-x C-w}; that is, it reads a file name, marks the
495 buffer as visiting that file, and saves it there.  The default file name in
496 a buffer that is not visiting a file is made by combining the buffer name
497 with the buffer's default directory (@pxref{File Names}).
498
499   If the new file name implies a major mode, then @kbd{C-x C-w} switches
500 to that major mode, in most cases.  The command
501 @code{set-visited-file-name} also does this.  @xref{Choosing Modes}.
502
503   If Emacs is about to save a file and sees that the date of the latest
504 version on disk does not match what Emacs last read or wrote, Emacs
505 notifies you of this fact, because it probably indicates a problem caused
506 by simultaneous editing and requires your immediate attention.
507 @xref{Interlocking,, Simultaneous Editing}.
508
509 @node Backup
510 @subsection Backup Files
511 @cindex backup file
512 @vindex make-backup-files
513 @vindex vc-make-backup-files
514
515   On most operating systems, rewriting a file automatically destroys all
516 record of what the file used to contain.  Thus, saving a file from Emacs
517 throws away the old contents of the file---or it would, except that
518 Emacs carefully copies the old contents to another file, called the
519 @dfn{backup} file, before actually saving.
520
521   For most files, the variable @code{make-backup-files} determines
522 whether to make backup files.  On most operating systems, its default
523 value is @code{t}, so that Emacs does write backup files.
524
525   For files managed by a version control system (@pxref{Version
526 Control}), the variable @code{vc-make-backup-files} determines whether
527 to make backup files.  By default it is @code{nil}, since backup files
528 are redundant when you store all the previous versions in a version
529 control system.
530 @iftex
531 @xref{General VC Options,,,emacs-xtra, Specialized Emacs Features}.
532 @end iftex
533 @ifnottex
534 @xref{General VC Options}.
535 @end ifnottex
536
537
538   At your option, Emacs can keep either a single backup for each file,
539 or make a series of numbered backup files for each file that you edit.
540
541 @vindex backup-enable-predicate
542 @vindex temporary-file-directory
543 @vindex small-temporary-file-directory
544   The default value of the @code{backup-enable-predicate} variable
545 prevents backup files being written for files in the directories used
546 for temporary files, specified by @code{temporary-file-directory} or
547 @code{small-temporary-file-directory}.
548
549   Emacs makes a backup for a file only the first time the file is saved
550 from one buffer.  No matter how many times you save a file, its backup file
551 continues to contain the contents from before the file was visited.
552 Normally this means that the backup file contains the contents from before
553 the current editing session; however, if you kill the buffer and then visit
554 the file again, a new backup file will be made by the next save.
555
556   You can also explicitly request making another backup file from a
557 buffer even though it has already been saved at least once.  If you save
558 the buffer with @kbd{C-u C-x C-s}, the version thus saved will be made
559 into a backup file if you save the buffer again.  @kbd{C-u C-u C-x C-s}
560 saves the buffer, but first makes the previous file contents into a new
561 backup file.  @kbd{C-u C-u C-u C-x C-s} does both things: it makes a
562 backup from the previous contents, and arranges to make another from the
563 newly saved contents if you save again.
564
565 @menu
566 * One or Many: Numbered Backups. Whether to make one backup file or many.
567 * Names: Backup Names.          How backup files are named.
568 * Deletion: Backup Deletion.    Emacs deletes excess numbered backups.
569 * Copying: Backup Copying.      Backups can be made by copying or renaming.
570 @end menu
571
572 @node Numbered Backups
573 @subsubsection Numbered Backups
574
575 @vindex version-control
576   The choice of single backup file or multiple numbered backup files
577 is controlled by the variable @code{version-control}.  Its possible
578 values are:
579
580 @table @code
581 @item t
582 Make numbered backups.
583 @item nil
584 Make numbered backups for files that have numbered backups already.
585 Otherwise, make single backups.
586 @item never
587 Never make numbered backups; always make single backups.
588 @end table
589
590 @noindent
591 The usual way to set this variable is globally, through your
592 @file{.emacs} file or the customization buffer.  However, you can set
593 @code{version-control} locally in an individual buffer to control the
594 making of backups for that buffer's file.  For example, Rmail mode
595 locally sets @code{version-control} to @code{never} to make sure that
596 there is only one backup for an Rmail file.  @xref{Locals}.
597
598 @cindex @env{VERSION_CONTROL} environment variable
599   If you set the environment variable @env{VERSION_CONTROL}, to tell
600 various GNU utilities what to do with backup files, Emacs also obeys the
601 environment variable by setting the Lisp variable @code{version-control}
602 accordingly at startup.  If the environment variable's value is @samp{t}
603 or @samp{numbered}, then @code{version-control} becomes @code{t}; if the
604 value is @samp{nil} or @samp{existing}, then @code{version-control}
605 becomes @code{nil}; if it is @samp{never} or @samp{simple}, then
606 @code{version-control} becomes @code{never}.
607
608 @node Backup Names
609 @subsubsection Single or Numbered Backups
610
611   When Emacs makes a single backup file, its name is normally
612 constructed by appending @samp{~} to the file name being edited; thus,
613 the backup file for @file{eval.c} would be @file{eval.c~}.
614
615 @vindex make-backup-file-name-function
616 @vindex backup-directory-alist
617   You can change this behavior by defining the variable
618 @code{make-backup-file-name-function} to a suitable function.
619 Alternatively you can customize the variable
620 @code{backup-directory-alist} to specify that files matching certain
621 patterns should be backed up in specific directories.
622
623   A typical use is to add an element @code{("." . @var{dir})} to make
624 all backups in the directory with absolute name @var{dir}; Emacs
625 modifies the backup file names to avoid clashes between files with the
626 same names originating in different directories.  Alternatively,
627 adding, say, @code{("." . ".~")} would make backups in the invisible
628 subdirectory @file{.~} of the original file's directory.  Emacs
629 creates the directory, if necessary, to make the backup.
630
631   If access control stops Emacs from writing backup files under the usual
632 names, it writes the backup file as @file{%backup%~} in your home
633 directory.  Only one such file can exist, so only the most recently
634 made such backup is available.
635
636   If you choose to have a series of numbered backup files, backup file
637 names contain @samp{.~}, the number, and another @samp{~} after the
638 original file name.  Thus, the backup files of @file{eval.c} would be
639 called @file{eval.c.~1~}, @file{eval.c.~2~}, and so on, all the way
640 through names like @file{eval.c.~259~} and beyond.  The variable
641 @code{backup-directory-alist} applies to numbered backups just as
642 usual.
643
644 @node Backup Deletion
645 @subsubsection Automatic Deletion of Backups
646
647   To prevent excessive consumption of disk space, Emacs can delete numbered
648 backup versions automatically.  Generally Emacs keeps the first few backups
649 and the latest few backups, deleting any in between.  This happens every
650 time a new backup is made.
651
652 @vindex kept-old-versions
653 @vindex kept-new-versions
654   The two variables @code{kept-old-versions} and
655 @code{kept-new-versions} control this deletion.  Their values are,
656 respectively, the number of oldest (lowest-numbered) backups to keep
657 and the number of newest (highest-numbered) ones to keep, each time a
658 new backup is made.  The backups in the middle (excluding those oldest
659 and newest) are the excess middle versions---those backups are
660 deleted.  These variables' values are used when it is time to delete
661 excess versions, just after a new backup version is made; the newly
662 made backup is included in the count in @code{kept-new-versions}.  By
663 default, both variables are 2.
664
665 @vindex delete-old-versions
666   If @code{delete-old-versions} is @code{t}, Emacs deletes the excess
667 backup files silently.  If it is @code{nil}, the default, Emacs asks
668 you whether it should delete the excess backup versions.  If it has
669 any other value, then Emacs never automatically deletes backups.
670
671   Dired's @kbd{.} (Period) command can also be used to delete old versions.
672 @xref{Dired Deletion}.
673
674 @node Backup Copying
675 @subsubsection Copying vs.@: Renaming
676
677   Backup files can be made by copying the old file or by renaming it.
678 This makes a difference when the old file has multiple names (hard
679 links).  If the old file is renamed into the backup file, then the
680 alternate names become names for the backup file.  If the old file is
681 copied instead, then the alternate names remain names for the file
682 that you are editing, and the contents accessed by those names will be
683 the new contents.
684
685   The method of making a backup file may also affect the file's owner
686 and group.  If copying is used, these do not change.  If renaming is used,
687 you become the file's owner, and the file's group becomes the default
688 (different operating systems have different defaults for the group).
689
690   Having the owner change is usually a good idea, because then the owner
691 always shows who last edited the file.  Also, the owners of the backups
692 show who produced those versions.  Occasionally there is a file whose
693 owner should not change; it is a good idea for such files to contain
694 local variable lists to set @code{backup-by-copying-when-mismatch}
695 locally (@pxref{File Variables}).
696
697 @vindex backup-by-copying
698 @vindex backup-by-copying-when-linked
699 @vindex backup-by-copying-when-mismatch
700 @vindex backup-by-copying-when-privileged-mismatch
701 @cindex file ownership, and backup
702 @cindex backup, and user-id
703   The choice of renaming or copying is controlled by four variables.
704 Renaming is the default choice.  If the variable
705 @code{backup-by-copying} is non-@code{nil}, copying is used.  Otherwise,
706 if the variable @code{backup-by-copying-when-linked} is non-@code{nil},
707 then copying is used for files that have multiple names, but renaming
708 may still be used when the file being edited has only one name.  If the
709 variable @code{backup-by-copying-when-mismatch} is non-@code{nil}, then
710 copying is used if renaming would cause the file's owner or group to
711 change.  @code{backup-by-copying-when-mismatch} is @code{t} by default
712 if you start Emacs as the superuser.  The fourth variable,
713 @code{backup-by-copying-when-privileged-mismatch}, gives the highest
714 numeric user-id for which @code{backup-by-copying-when-mismatch} will be
715 forced on.  This is useful when low-numbered user-ids are assigned to
716 special system users, such as @code{root}, @code{bin}, @code{daemon},
717 etc., which must maintain ownership of files.
718
719   When a file is managed with a version control system (@pxref{Version
720 Control}), Emacs does not normally make backups in the usual way for
721 that file.  But check-in and check-out are similar in some ways to
722 making backups.  One unfortunate similarity is that these operations
723 typically break hard links, disconnecting the file name you visited from
724 any alternate names for the same file.  This has nothing to do with
725 Emacs---the version control system does it.
726
727 @node Customize Save
728 @subsection Customizing Saving of Files
729
730 @vindex require-final-newline
731   If the value of the variable @code{require-final-newline} is
732 @code{t}, saving or writing a file silently puts a newline at the end
733 if there isn't already one there.  If the value is @code{visit}, Emacs
734 adds a newline at the end of any file that doesn't have one, just
735 after it visits the file.  (This marks the buffer as modified, and you
736 can undo it.)  If the value is @code{visit-save}, that means to add
737 newlines both on visiting and on saving.  If the value is @code{nil},
738 Emacs leaves the end of the file unchanged; if it's neither @code{nil}
739 nor @code{t}, Emacs asks you whether to add a newline.  The default is
740 @code{nil}.
741
742 @vindex mode-require-final-newline
743   Many major modes are designed for specific kinds of files that are
744 always supposed to end in newlines.  These major modes set the
745 variable @code{require-final-newline} according to
746 @code{mode-require-final-newline}.  By setting the latter variable,
747 you can control how these modes handle final newlines.
748
749 @vindex write-region-inhibit-fsync
750   When Emacs saves a file, it invokes the @code{fsync} system call to
751 force the data immediately out to disk.  This is important for safety
752 if the system crashes or in case of power outage.  However, it can be
753 disruptive on laptops using power saving, because it requires the disk
754 to spin up each time you save a file.  Setting
755 @code{write-region-inhibit-fsync} to a non-@code{nil} value disables
756 this synchronization.  Be careful---this means increased risk of data
757 loss.
758
759 @node Interlocking
760 @subsection Protection against Simultaneous Editing
761
762 @cindex file dates
763 @cindex simultaneous editing
764   Simultaneous editing occurs when two users visit the same file, both
765 make changes, and then both save them.  If nobody were informed that
766 this was happening, whichever user saved first would later find that his
767 changes were lost.
768
769   On some systems, Emacs notices immediately when the second user starts
770 to change the file, and issues an immediate warning.  On all systems,
771 Emacs checks when you save the file, and warns if you are about to
772 overwrite another user's changes.  You can prevent loss of the other
773 user's work by taking the proper corrective action instead of saving the
774 file.
775
776 @findex ask-user-about-lock
777 @cindex locking files
778   When you make the first modification in an Emacs buffer that is
779 visiting a file, Emacs records that the file is @dfn{locked} by you.
780 (It does this by creating a symbolic link in the same directory with a
781 different name.)  Emacs removes the lock when you save the changes.  The
782 idea is that the file is locked whenever an Emacs buffer visiting it has
783 unsaved changes.
784
785 @cindex collision
786   If you begin to modify the buffer while the visited file is locked by
787 someone else, this constitutes a @dfn{collision}.  When Emacs detects a
788 collision, it asks you what to do, by calling the Lisp function
789 @code{ask-user-about-lock}.  You can redefine this function for the sake
790 of customization.  The standard definition of this function asks you a
791 question and accepts three possible answers:
792
793 @table @kbd
794 @item s
795 Steal the lock.  Whoever was already changing the file loses the lock,
796 and you gain the lock.
797 @item p
798 Proceed.  Go ahead and edit the file despite its being locked by someone else.
799 @item q
800 Quit.  This causes an error (@code{file-locked}), and the buffer
801 contents remain unchanged---the modification you were trying to make
802 does not actually take place.
803 @end table
804
805   Note that locking works on the basis of a file name; if a file has
806 multiple names, Emacs does not realize that the two names are the same file
807 and cannot prevent two users from editing it simultaneously under different
808 names.  However, basing locking on names means that Emacs can interlock the
809 editing of new files that will not really exist until they are saved.
810
811   Some systems are not configured to allow Emacs to make locks, and
812 there are cases where lock files cannot be written.  In these cases,
813 Emacs cannot detect trouble in advance, but it still can detect the
814 collision when you try to save a file and overwrite someone else's
815 changes.
816
817   If Emacs or the operating system crashes, this may leave behind lock
818 files which are stale, so you may occasionally get warnings about
819 spurious collisions.  When you determine that the collision is spurious,
820 just use @kbd{p} to tell Emacs to go ahead anyway.
821
822   Every time Emacs saves a buffer, it first checks the last-modification
823 date of the existing file on disk to verify that it has not changed since the
824 file was last visited or saved.  If the date does not match, it implies
825 that changes were made in the file in some other way, and these changes are
826 about to be lost if Emacs actually does save.  To prevent this, Emacs
827 displays a warning message and asks for confirmation before saving.
828 Occasionally you will know why the file was changed and know that it does
829 not matter; then you can answer @kbd{yes} and proceed.  Otherwise, you should
830 cancel the save with @kbd{C-g} and investigate the situation.
831
832   The first thing you should do when notified that simultaneous editing
833 has already taken place is to list the directory with @kbd{C-u C-x C-d}
834 (@pxref{Directories}).  This shows the file's current author.  You
835 should attempt to contact him to warn him not to continue editing.
836 Often the next step is to save the contents of your Emacs buffer under a
837 different name, and use @code{diff} to compare the two files.@refill
838
839 @node File Shadowing
840 @subsection Shadowing Files
841 @cindex shadow files
842 @cindex file shadows
843 @findex shadow-initialize
844
845 @table @kbd
846 @item M-x shadow-initialize
847 Set up file shadowing.
848 @item M-x shadow-define-literal-group
849 Declare a single file to be shared between sites.
850 @item M-x shadow-define-regexp-group
851 Make all files that match each of a group of files be shared between hosts.
852 @item M-x shadow-define-cluster @key{RET} @var{name} @key{RET}
853 Define a shadow file cluster @var{name}.
854 @item M-x shadow-copy-files
855 Copy all pending shadow files.
856 @item M-x shadow-cancel
857 Cancel the instruction to shadow some files.
858 @end table
859
860 You can arrange to keep identical @dfn{shadow} copies of certain files
861 in more than one place---possibly on different machines.  To do this,
862 first you must set up a @dfn{shadow file group}, which is a set of
863 identically-named files shared between a list of sites.  The file
864 group is permanent and applies to further Emacs sessions as well as
865 the current one.  Once the group is set up, every time you exit Emacs,
866 it will copy the file you edited to the other files in its group.  You
867 can also do the copying without exiting Emacs, by typing @kbd{M-x
868 shadow-copy-files}.
869
870 To set up a shadow file group, use @kbd{M-x
871 shadow-define-literal-group} or @kbd{M-x shadow-define-regexp-group}.
872 See their documentation strings for further information.
873
874 Before copying a file to its shadows, Emacs asks for confirmation.
875 You can answer ``no'' to bypass copying of this file, this time.  If
876 you want to cancel the shadowing permanently for a certain file, use
877 @kbd{M-x shadow-cancel} to eliminate or change the shadow file group.
878
879 A @dfn{shadow cluster} is a group of hosts that share directories, so
880 that copying to or from one of them is sufficient to update the file
881 on all of them.  Each shadow cluster has a name, and specifies the
882 network address of a primary host (the one we copy files to), and a
883 regular expression that matches the host names of all the other hosts
884 in the cluster.  You can define a shadow cluster with @kbd{M-x
885 shadow-define-cluster}.
886
887 @node Time Stamps
888 @subsection Updating Time Stamps Automatically
889 @cindex time stamps
890 @cindex modification dates
891 @cindex locale, date format
892
893 You can arrange to put a time stamp in a file, so that it will be updated
894 automatically each time you edit and save the file.  The time stamp
895 has to be in the first eight lines of the file, and you should
896 insert it like this:
897
898 @example
899 Time-stamp: <>
900 @end example
901
902 @noindent
903 or like this:
904
905 @example
906 Time-stamp: " "
907 @end example
908
909 @findex time-stamp
910   Then add the hook function @code{time-stamp} to the hook
911 @code{before-save-hook}; that hook function will automatically update
912 the time stamp, inserting the current date and time when you save the
913 file.  You can also use the command @kbd{M-x time-stamp} to update the
914 time stamp manually.  For other customizations, see the Custom group
915 @code{time-stamp}.  Note that non-numeric fields in the time stamp are
916 formatted according to your locale setting (@pxref{Environment}).
917
918 @node Reverting
919 @section Reverting a Buffer
920 @findex revert-buffer
921 @cindex drastic changes
922 @cindex reread a file
923
924   If you have made extensive changes to a file and then change your mind
925 about them, you can get rid of them by reading in the previous version
926 of the file.  To do this, use @kbd{M-x revert-buffer}, which operates on
927 the current buffer.  Since reverting a buffer unintentionally could lose
928 a lot of work, you must confirm this command with @kbd{yes}.
929
930   @code{revert-buffer} tries to position point in such a way that, if
931 the file was edited only slightly, you will be at approximately the
932 same piece of text after reverting as before.  However, if you have made
933 drastic changes, point may wind up in a totally different piece of text.
934
935   Reverting marks the buffer as ``not modified'' until another change is
936 made.
937
938   Some kinds of buffers whose contents reflect data bases other than files,
939 such as Dired buffers, can also be reverted.  For them, reverting means
940 recalculating their contents from the appropriate data base.  Buffers
941 created explicitly with @kbd{C-x b} cannot be reverted; @code{revert-buffer}
942 reports an error when asked to do so.
943
944 @vindex revert-without-query
945   When you edit a file that changes automatically and frequently---for
946 example, a log of output from a process that continues to run---it may be
947 useful for Emacs to revert the file without querying you, whenever you
948 visit the file again with @kbd{C-x C-f}.
949
950   To request this behavior, set the variable @code{revert-without-query}
951 to a list of regular expressions.  When a file name matches one of these
952 regular expressions, @code{find-file} and @code{revert-buffer} will
953 revert it automatically if it has changed---provided the buffer itself
954 is not modified.  (If you have edited the text, it would be wrong to
955 discard your changes.)
956
957 @cindex Global Auto-Revert mode
958 @cindex mode, Global Auto-Revert
959 @cindex Auto-Revert mode
960 @cindex mode, Auto-Revert
961 @findex global-auto-revert-mode
962 @findex auto-revert-mode
963 @findex auto-revert-tail-mode
964
965   You may find it useful to have Emacs revert files automatically when
966 they change.  Three minor modes are available to do this.
967
968   @kbd{M-x global-auto-revert-mode} enables Global Auto-Revert mode,
969 which periodically checks all file buffers and reverts when the
970 corresponding file has changed.  @kbd{M-x auto-revert-mode} enables a
971 local version, Auto-Revert mode, which applies only to the current
972 buffer.
973
974   You can use Auto-Revert mode to ``tail'' a file such as a system
975 log, so that changes made to that file by other programs are
976 continuously displayed.  To do this, just move the point to the end of
977 the buffer, and it will stay there as the file contents change.
978 However, if you are sure that the file will only change by growing at
979 the end, use Auto-Revert Tail mode instead
980 (@code{auto-revert-tail-mode}).  It is more efficient for this.
981
982 @vindex auto-revert-interval
983   The variable @code{auto-revert-interval} controls how often to check
984 for a changed file.  Since checking a remote file is too slow, these
985 modes do not check or revert remote files.
986
987   @xref{VC Mode Line}, for Auto Revert peculiarities in buffers that
988 visit files under version control.
989
990 @ifnottex
991 @include arevert-xtra.texi
992 @end ifnottex
993
994 @node Auto Save
995 @section Auto-Saving: Protection Against Disasters
996 @cindex Auto Save mode
997 @cindex mode, Auto Save
998 @cindex crashes
999
1000   Emacs saves all the visited files from time to time (based on
1001 counting your keystrokes) without being asked, in separate files so as
1002 not to alter the files you actually use.  This is called
1003 @dfn{auto-saving}.  It prevents you from losing more than a limited
1004 amount of work if the system crashes.
1005
1006   When Emacs determines that it is time for auto-saving, it considers
1007 each buffer, and each is auto-saved if auto-saving is enabled for it
1008 and it has been changed since the last time it was auto-saved.  The
1009 message @samp{Auto-saving...} is displayed in the echo area during
1010 auto-saving, if any files are actually auto-saved.  Errors occurring
1011 during auto-saving are caught so that they do not interfere with the
1012 execution of commands you have been typing.
1013
1014 @menu
1015 * Files: Auto Save Files.       The file where auto-saved changes are
1016                                   actually made until you save the file.
1017 * Control: Auto Save Control.   Controlling when and how often to auto-save.
1018 * Recover::                     Recovering text from auto-save files.
1019 @end menu
1020
1021 @node Auto Save Files
1022 @subsection Auto-Save Files
1023
1024   Auto-saving does not normally save in the files that you visited, because
1025 it can be very undesirable to save a program that is in an inconsistent
1026 state when you have made half of a planned change.  Instead, auto-saving
1027 is done in a different file called the @dfn{auto-save file}, and the
1028 visited file is changed only when you request saving explicitly (such as
1029 with @kbd{C-x C-s}).
1030
1031   Normally, the auto-save file name is made by appending @samp{#} to the
1032 front and rear of the visited file name.  Thus, a buffer visiting file
1033 @file{foo.c} is auto-saved in a file @file{#foo.c#}.  Most buffers that
1034 are not visiting files are auto-saved only if you request it explicitly;
1035 when they are auto-saved, the auto-save file name is made by appending
1036 @samp{#} to the front and rear of buffer name, then
1037 adding digits and letters at the end for uniqueness.  For
1038 example, the @samp{*mail*} buffer in which you compose messages to be
1039 sent might be auto-saved in a file named @file{#*mail*#704juu}.  Auto-save file
1040 names are made this way unless you reprogram parts of Emacs to do
1041 something different (the functions @code{make-auto-save-file-name} and
1042 @code{auto-save-file-name-p}).  The file name to be used for auto-saving
1043 in a buffer is calculated when auto-saving is turned on in that buffer.
1044
1045 @cindex auto-save for remote files
1046 @vindex auto-save-file-name-transforms
1047   The variable @code{auto-save-file-name-transforms} allows a degree
1048 of control over the auto-save file name.  It lets you specify a series
1049 of regular expressions and replacements to transform the auto save
1050 file name.  The default value puts the auto-save files for remote
1051 files (@pxref{Remote Files}) into the temporary file directory on the
1052 local machine.
1053
1054   When you delete a substantial part of the text in a large buffer, auto
1055 save turns off temporarily in that buffer.  This is because if you
1056 deleted the text unintentionally, you might find the auto-save file more
1057 useful if it contains the deleted text.  To reenable auto-saving after
1058 this happens, save the buffer with @kbd{C-x C-s}, or use @kbd{C-u 1 M-x
1059 auto-save-mode}.
1060
1061 @vindex auto-save-visited-file-name
1062   If you want auto-saving to be done in the visited file rather than
1063 in a separate auto-save file, set the variable
1064 @code{auto-save-visited-file-name} to a non-@code{nil} value.  In this
1065 mode, there is no real difference between auto-saving and explicit
1066 saving.
1067
1068 @vindex delete-auto-save-files
1069   A buffer's auto-save file is deleted when you save the buffer in its
1070 visited file.  (You can inhibit this by setting the variable
1071 @code{delete-auto-save-files} to @code{nil}.)  Changing the visited
1072 file name with @kbd{C-x C-w} or @code{set-visited-file-name} renames
1073 any auto-save file to go with the new visited name.
1074
1075 @node Auto Save Control
1076 @subsection Controlling Auto-Saving
1077
1078 @vindex auto-save-default
1079 @findex auto-save-mode
1080   Each time you visit a file, auto-saving is turned on for that file's
1081 buffer if the variable @code{auto-save-default} is non-@code{nil} (but not
1082 in batch mode; @pxref{Entering Emacs}).  The default for this variable is
1083 @code{t}, so auto-saving is the usual practice for file-visiting buffers.
1084 Auto-saving can be turned on or off for any existing buffer with the
1085 command @kbd{M-x auto-save-mode}.  Like other minor mode commands, @kbd{M-x
1086 auto-save-mode} turns auto-saving on with a positive argument, off with a
1087 zero or negative argument; with no argument, it toggles.
1088
1089 @vindex auto-save-interval
1090   Emacs does auto-saving periodically based on counting how many characters
1091 you have typed since the last time auto-saving was done.  The variable
1092 @code{auto-save-interval} specifies how many characters there are between
1093 auto-saves.  By default, it is 300.  Emacs doesn't accept values that are
1094 too small: if you customize @code{auto-save-interval} to a value less
1095 than 20, Emacs will behave as if the value is 20.
1096
1097 @vindex auto-save-timeout
1098   Auto-saving also takes place when you stop typing for a while.  The
1099 variable @code{auto-save-timeout} says how many seconds Emacs should
1100 wait before it does an auto save (and perhaps also a garbage
1101 collection).  (The actual time period is longer if the current buffer is
1102 long; this is a heuristic which aims to keep out of your way when you
1103 are editing long buffers, in which auto-save takes an appreciable amount
1104 of time.)  Auto-saving during idle periods accomplishes two things:
1105 first, it makes sure all your work is saved if you go away from the
1106 terminal for a while; second, it may avoid some auto-saving while you
1107 are actually typing.
1108
1109   Emacs also does auto-saving whenever it gets a fatal error.  This
1110 includes killing the Emacs job with a shell command such as @samp{kill
1111 %emacs}, or disconnecting a phone line or network connection.
1112
1113 @findex do-auto-save
1114   You can request an auto-save explicitly with the command @kbd{M-x
1115 do-auto-save}.
1116
1117 @node Recover
1118 @subsection Recovering Data from Auto-Saves
1119
1120 @findex recover-file
1121   You can use the contents of an auto-save file to recover from a loss
1122 of data with the command @kbd{M-x recover-file @key{RET} @var{file}
1123 @key{RET}}.  This visits @var{file} and then (after your confirmation)
1124 restores the contents from its auto-save file @file{#@var{file}#}.
1125 You can then save with @kbd{C-x C-s} to put the recovered text into
1126 @var{file} itself.  For example, to recover file @file{foo.c} from its
1127 auto-save file @file{#foo.c#}, do:@refill
1128
1129 @example
1130 M-x recover-file @key{RET} foo.c @key{RET}
1131 yes @key{RET}