Build Fix -- compatibility issue with newer autoconf
[sxemacs] / info / sxemacs / files.texi
1 @node Files, Buffers, Fixit, Top
2 @chapter File Handling
3 @cindex files
4
5   The basic unit of stored data in Unix is the @dfn{file}.  To edit a file,
6 you must tell Emacs to examine the file and prepare a buffer containing a
7 copy of the file's text.  This is called @dfn{visiting} the file.  Editing
8 commands apply directly to text in the buffer; that is, to the copy inside
9 Emacs.  Your changes appear in the file itself only when you @dfn{save} the
10 buffer back into the file.
11
12 @cindex files, remote
13 @cindex remote files
14   Emacs is also able to handle ``remote files'' which are stored on
15 other hosts.  Not only is Emacs somewhat aware of the special issues
16 involved with network file systems, but it can also use FTP and ssh (or
17 rsh) to make local copies of the files, and refresh them on the remote
18 host automatically when you save the buffer.  The FTP interface is
19 provided by the standard @samp{efs} package @ref{Top, EFS, , efs}.  The
20 ssh/rsh interface is provided by the optional @samp{tramp} package
21 @ref{Top, TRAMP, , tramp}.  These packages attempt to implement all of
22 the operations described below, making remote file use transparent
23 (except for unavoidable network delays).
24
25   In addition to visiting and saving files, Emacs can delete, copy, rename,
26 and append to files, and operate on file directories.
27
28 @menu
29 * File Names::       How to type and edit file name arguments.
30 * Visiting::         Visiting a file prepares Emacs to edit the file.
31 * Saving::           Saving makes your changes permanent.
32 * Reverting::        Reverting cancels all the changes not saved.
33 * Auto Save::        Auto Save periodically protects against loss of data.
34 * Version Control::  Version control systems (RCS and SCCS).
35 * ListDir::          Listing the contents of a file directory.
36 * Comparing Files::  Finding where two files differ.
37 * Dired::            ``Editing'' a directory to delete, rename, etc.
38                      the files in it.
39 * Misc File Ops::    Other things you can do on files.
40 @end menu
41
42 @node File Names, Visiting, Files, Files
43 @section File Names
44 @cindex file names
45
46   Most Emacs commands that operate on a file require you to specify the
47 file name.  (Saving and reverting are exceptions; the buffer knows which
48 file name to use for them.)  File names are specified in the minibuffer
49 (@pxref{Minibuffer}).  @dfn{Completion} is available, to make it easier to
50 specify long file names.  @xref{Completion}.
51
52   There is always a @dfn{default file name} which is used if you
53 enter an empty argument by typing just @key{RET}.  Normally the default
54 file name is the name of the file visited in the current buffer; this
55 makes it easy to operate on that file with any of the Emacs file
56 commands.
57
58 The syntax for accessing remote files unfortunately varies depending on
59 the method used.  The syntax for using FTP is
60 @samp{/@var{user}@@@var{remote-host}:@var{path-on-remote-host}}.  The
61 syntax for using ssh is
62 @samp{/[@var{user}@@@var{remote-host}]@var{path-on-remote-host}}.
63
64   In both cases the @samp{@var{user}@@} portion is optional (it defaults
65 to your local user name).  @var{path-on-remote-host} may use the
66 @samp{~} notation to indicate @var{user}'s home directory on the remote
67 host.  The default file name will reflect the remote host information.
68
69 @vindex default-directory
70   Each buffer has a default directory, normally the same as the
71 directory of the file visited in that buffer.  When Emacs reads a file
72 name, the default directory is used if you do not specify a directory.
73 If you specify a directory in a relative fashion, with a name that does
74 not start with a slash, it is interpreted with respect to the default
75 directory.  The default directory of the current buffer is kept in the
76 variable @code{default-directory}, which has a separate value in every
77 buffer.  The value of the variable should end with a slash.
78
79   For example, if the default file name is @file{/u/rms/gnu/gnu.tasks} then
80 the default directory is @file{/u/rms/gnu/}.  If you type just @samp{foo},
81 which does not specify a directory, it is short for @file{/u/rms/gnu/foo}.
82 @samp{../.login} would stand for @file{/u/rms/.login}.  @samp{new/foo}
83 would stand for the filename @file{/u/rms/gnu/new/foo}.
84
85   When visiting a remote file via EFS or TRAMP, the remote directory
86 becomes the default directory (@pxref{Visiting}) for that buffer, just
87 as a local directory would.
88
89 @vindex default-directory-alist
90 The variable @code{default-directory-alist} takes an alist of major
91 modes and their opinions on @code{default-directory} as a Lisp
92 expression to evaluate.  A resulting value of @code{nil} is ignored in
93 favor of @code{default-directory}.
94
95 @findex make-directory
96 @findex remove-directory
97 @cindex creating directories
98 @cindex removing directories
99 You can create a new directory with the function @code{make-directory},
100 which takes as an argument a file name string. The current directory is
101 displayed in the minibuffer when the function is called; you can delete
102 the old directory name and supply a new directory name. For example, if
103 the current directory is @file{/u/rms/gnu}, you can delete @file{gnu}
104 and type @file{oryx} and @key{RET} to create @file{/u/rms/oryx}.
105 Removing a directory is similar to creating one.  To remove a directory,
106 use @code{remove-directory}; it takes one argument, a file name string.
107
108   The command @kbd{M-x pwd} prints the current buffer's default directory,
109 and the command @kbd{M-x cd} sets it (to a value read using the
110 minibuffer).  A buffer's default directory changes only when the @code{cd}
111 command is used.  A file-visiting buffer's default directory is initialized
112 to the directory of the file that is visited there.  If a buffer is created
113 with @kbd{C-x b}, its default directory is copied from that of the
114 buffer that was current at the time.
115
116 @vindex insert-default-directory
117   The default directory name actually appears in the minibuffer when the
118 minibuffer becomes active to read a file name.  This serves two
119 purposes: it shows you what the default is, so that you can type a
120 relative file name and know with certainty what it will mean, and it
121 allows you to edit the default to specify a different directory.  To
122 inhibit the insertion of the default directory, set the variable
123 @code{insert-default-directory} to @code{nil}.
124
125   Note that it is legitimate to type an absolute file name after you
126 enter the minibuffer, ignoring the presence of the default directory
127 name.  The final minibuffer contents may look invalid, but that is not
128 so.  @xref{Minibuffer File}.
129
130   @samp{$} in a file name is used to substitute environment variables.  For
131 example, if you have used the shell command @samp{setenv FOO rms/hacks} to
132 set up an environment variable named @samp{FOO}, then you can use
133 @file{/u/$FOO/test.c} or @file{/u/$@{FOO@}/test.c} as an abbreviation for
134 @file{/u/rms/hacks/test.c}.  The environment variable name consists of all
135 the alphanumeric characters after the @samp{$}; alternatively, it may be
136 enclosed in braces after the @samp{$}.  Note that the @samp{setenv} command
137 affects Emacs only if done before Emacs is started.
138
139   To access a file with @samp{$} in its name, type @samp{$$}.  This pair
140 is converted to a single @samp{$} at the same time variable substitution
141 is performed for single @samp{$}.  The Lisp function that performs the
142 substitution is called @code{substitute-in-file-name}.  The substitution
143 is performed only on filenames read as such using the minibuffer.
144
145 @node Visiting, Saving, File Names, Files
146 @section Visiting Files
147 @cindex visiting files
148
149 @c WideCommands
150 @table @kbd
151 @item C-x C-f
152 Visit a file (@code{find-file}).
153 @item C-x C-v
154 Visit a different file instead of the one visited last
155 (@code{find-alternate-file}).
156 @item C-x 4 C-f
157 Visit a file, in another window (@code{find-file-other-window}).  Don't
158 change this window.
159 @item C-x 5 C-f
160 Visit a file, in another frame (@code{find-file-other-frame}).  Don't
161 change this window or frame.
162 @end table
163
164 @cindex files
165 @cindex visiting
166 @cindex saving
167   @dfn{Visiting} a file means copying its contents into an Emacs buffer
168 so you can edit it.  Emacs creates a new buffer for each file you
169 visit.  We say that the buffer is visiting the file that it was created
170 to hold.  Emacs constructs the buffer name from the file name by
171 throwing away the directory and keeping just the file name.  For example,
172 a file named @file{/usr/rms/emacs.tex} is displayed in a buffer named
173 @samp{emacs.tex}.  If a buffer with that name exists, a unique
174 name is constructed by appending @samp{<2>}, @samp{<3>},and so on, using
175 the lowest number that makes a name that is not already in use.
176
177   Each window's mode line shows the name of the buffer that is being displayed
178 in that window, so you can always tell what buffer you are editing.
179
180   The changes you make with Emacs are made in the Emacs buffer.  They do
181 not take effect in the file that you visit, or any other permanent
182 place, until you @dfn{save} the buffer.  Saving the buffer means that
183 Emacs writes the current contents of the buffer into its visited file.
184 @xref{Saving}.
185
186 @cindex modified (buffer)
187   If a buffer contains changes that have not been saved, the buffer is said
188 to be @dfn{modified}.  This is important because it implies that some
189 changes will be lost if the buffer is not saved.  The mode line displays
190 two stars near the left margin if the buffer is modified.
191
192 @kindex C-x 5 C-f
193 @findex find-file
194 @findex find-file-other-frame
195   To visit a file, use the command @kbd{C-x C-f} (@code{find-file}).  Follow
196 the command with the name of the file you wish to visit, terminated by a
197 @key{RET}.  If you are using SXEmacs under X, you can also use the
198 @b{Open...} command from the @b{File} menu bar item.
199
200   The file name is read using the minibuffer (@pxref{Minibuffer}), with
201 defaulting and completion in the standard manner (@pxref{File Names}).
202 While in the minibuffer, you can abort @kbd{C-x C-f} by typing @kbd{C-g}.
203
204   @kbd{C-x C-f} has completed successfully when text appears on the
205 screen and a new buffer name appears in the mode line.  If the specified
206 file does not exist and could not be created or cannot be read, an error
207 results.  The error message is printed in the echo area, and includes
208 the name of the file that Emacs was trying to visit.
209
210   If you visit a file that is already in Emacs, @kbd{C-x C-f} does not make
211 another copy.  It selects the existing buffer containing that file.
212 However, before doing so, it checks that the file itself has not changed
213 since you visited or saved it last.  If the file has changed, Emacs
214 prints a warning message.  @xref{Interlocking,,Simultaneous Editing}.
215
216 @findex find-this-file
217 You can switch to a specific file called out in the current buffer by
218 calling the function @code{find-this-file}. By providing a prefix
219 argument, this function calls @code{filename-at-point} and switches to a
220 buffer visiting the file @var{filename}. It creates one if none already
221 exists. You can use this function to edit the file mentioned in the
222 buffer you are working in or to test if the file exists. You can do that
223 by using the minibuffer completion after snatching the all or part of
224 the filename.
225
226 @vindex find-file-use-truenames
227 @vindex buffer-file-name
228 If the variable @code{find-file-use-truenames}'s value is
229 non-@code{nil}, a buffer's visited filename will always be traced back
230 to the real file. The filename will never be a symbolic link, and there
231 will never be a symbolic link anywhere in its directory path. In other
232 words, the @code{buffer-file-name} and @code{buffer-file-truename} will
233 be equal.
234
235 @vindex find-file-compare-truenames
236 @vindex buffer-file-truename
237 If the variable @code{find-file-compare-truenames} value is
238 non-@code{nil}, the @code{find-file} command will check the
239 @code{buffer-file-truename} of all visited files when deciding whether a
240 given file is already in a buffer, instead of just
241 @code{buffer-file-name}.  If you attempt to visit another file which is
242 a symbolic link to a file that is already in a buffer, the existing
243 buffer will be found instead of a newly created one.  This works if any
244 component of the pathname (including a non-terminal component) is a
245 symbolic link as well, but doesn't work with hard links (nothing does).
246
247 @cindex creating files
248    If you want to create a file, just visit it.  Emacs prints
249 @samp{(New File)} in the echo area, but in other respects behaves as if you
250 had visited an existing empty file.  If you make any changes and save them,
251 the file is created.
252
253 @kindex C-x C-v
254 @findex find-alternate-file
255   If you visit a nonexistent file unintentionally (because you typed the
256 wrong file name), use the @kbd{C-x C-v} (@code{find-alternate-file})
257 command to visit the file you wanted.  @kbd{C-x C-v} is similar to @kbd{C-x
258 C-f}, but it kills the current buffer (after first offering to save it if
259 it is modified).  @kbd{C-x C-v} is allowed even if the current buffer
260 is not visiting a file.
261
262 @vindex find-file-run-dired
263   If the file you specify is actually a directory, Dired is called on
264 that directory (@pxref{Dired}).  To inhibit this, set the variable
265 @code{find-file-run-dired} to @code{nil}; then it is an error to try to
266 visit a directory.
267
268 @kindex C-x 4 f
269 @findex find-file-other-window
270   @kbd{C-x 4 f} (@code{find-file-other-window}) is like @kbd{C-x C-f}
271 except that the buffer containing the specified file is selected in another
272 window.  The window that was selected before @kbd{C-x 4 f} continues to
273 show the same buffer it was already showing.  If you use this command when
274 only one window is being displayed, that window is split in two, with one
275 window showing the same buffer as before, and the other one showing the
276 newly requested file.  @xref{Windows}.
277
278 @kindex C-x 5 C-f
279 @findex find-file-other-frame
280 @kbd{C-x 5 C-f} (@code{find-file-other-frame}) is like @kbd{C-x C-f}
281 except that it creates a new frame in which the file is displayed.
282
283 @findex find-this-file-other-window
284  Use the function @code{find-this-file-other-window} to edit a file
285 mentioned in the buffer you are editing or to test if that file exists.
286 To do this, use the minibuffer completion after snatching the part or
287 all of the filename. By providing a prefix argument, the function calls
288 @code{filename-at-point} and switches you to a buffer visiting the file
289 @var{filename} in another window. The function creates a buffer if none
290 already exists. This function is similar to @code{find-file-other-window}.
291
292 @vindex find-file-hooks
293 @vindex find-file-not-found-hooks
294   There are two hook variables that allow extensions to modify the
295 operation of visiting files.  Visiting a file that does not exist runs the
296 functions in the list @code{find-file-not-found-hooks}; the value of this
297 variable is expected to be a list of functions which are
298 called one by one until one of them returns non-@code{nil}.  Any visiting
299 of a file, whether extant or not, expects @code{find-file-hooks} to
300 contain list of functions and calls them all, one by one.  In both cases
301 the functions receive no arguments.  Visiting a nonexistent file
302 runs the @code{find-file-not-found-hooks} first.
303
304 @node Saving, Reverting, Visiting, Files
305 @section Saving Files
306
307   @dfn{Saving} a buffer in Emacs means writing its contents back into the file
308 that was visited in the buffer.
309
310 @table @kbd
311 @item C-x C-s
312 Save the current buffer in its visited file (@code{save-buffer}).
313 @item C-x s
314 Save any or all buffers in their visited files (@code{save-some-buffers}).
315 @item M-~
316 Forget that the current buffer has been changed (@code{not-modified}).
317 @item C-x C-w
318 Save the current buffer in a specified file, and record that file as
319 the one visited in the buffer (@code{write-file}).
320 @item M-x set-visited-file-name
321 Change file the name under which the current buffer will be saved.
322 @end table
323
324 @kindex C-x C-s
325 @findex save-buffer
326   To save a file and make your changes permanent, type
327 @kbd{C-x C-s} (@code{save-buffer}).  After saving is finished, @kbd{C-x C-s}
328 prints a message such as:
329
330 @example
331 Wrote /u/rms/gnu/gnu.tasks
332 @end example
333
334 @noindent
335 If the selected buffer is not modified (no changes have been made in it
336 since the buffer was created or last saved), Emacs does not save it
337 because it would have no effect.  Instead, @kbd{C-x C-s} prints a message
338 in the echo area saying:
339
340 @example
341 (No changes need to be saved)
342 @end example
343
344 @kindex C-x s
345 @findex save-some-buffers
346   The command @kbd{C-x s} (@code{save-some-buffers}) can save any or all
347 modified buffers.  First it asks, for each modified buffer, whether to
348 save it.  The questions should be answered with @kbd{y} or @kbd{n}.
349 @kbd{C-x C-c}, the key that kills Emacs, invokes
350 @code{save-some-buffers} and therefore asks the same questions.
351
352 @kindex M-~
353 @findex not-modified
354   If you have changed a buffer and do not want the changes to be saved,
355 you should take some action to prevent it.  Otherwise, you are liable to
356 save it by mistake each time you use @code{save-some-buffers} or a
357 related command.  One thing you can do is type @kbd{M-~}
358 (@code{not-modified}), which removes the indication that the buffer
359 is modified.  If you do this, none of the save commands will believe
360 that the buffer needs to be saved.  (@samp{~} is often used as a
361 mathematical symbol for `not'; thus @kbd{Meta-~} is `not', metafied.)
362 You could also use @code{set-visited-file-name} (see below) to mark the
363 buffer as visiting a different file name, not in use for
364 anything important.
365
366 You can also undo all the changes made since the file was visited or
367 saved, by reading the text from the file again.  This is called
368 @dfn{reverting}.  @xref{Reverting}.  Alternatively, you can undo all the
369 changes by repeating the undo command @kbd{C-x u}; but this only works
370 if you have not made more changes than the undo mechanism can remember.
371
372 @findex set-visited-file-name
373   @kbd{M-x set-visited-file-name} alters the name of the file that the
374 current buffer is visiting.  It prompts you for the new file name in the
375 minibuffer.  You can also use @code{set-visited-file-name} on a buffer
376 that is not visiting a file.  The buffer's name is changed to correspond
377 to the file it is now visiting unless the new name is already used by a
378 different buffer; in that case, the buffer name is not changed.
379 @code{set-visited-file-name} does not save the buffer in the newly
380 visited file; it just alters the records inside Emacs so that it will
381 save the buffer in that file.  It also marks the buffer as ``modified''
382 so that @kbd{C-x C-s} @i{will} save.
383
384 @kindex C-x C-w
385 @findex write-file
386   If you wish to mark a buffer as visiting a different file and save it
387 right away, use @kbd{C-x C-w} (@code{write-file}).  It is precisely
388 equivalent to @code{set-visited-file-name} followed by @kbd{C-x C-s}.
389 @kbd{C-x C-s} used on a buffer that is not visiting  a file has the
390 same effect as @kbd{C-x C-w}; that is, it reads a file name, marks the
391 buffer as visiting that file, and saves it there.  The default file name in
392 a buffer that is not visiting a file is made by combining the buffer name
393 with the buffer's default directory.
394
395   If Emacs is about to save a file and sees that the date of the latest
396 version on disk does not match what Emacs last read or wrote, Emacs
397 notifies you of this fact, because it probably indicates a problem caused
398 by simultaneous editing and requires your immediate attention.
399 @xref{Interlocking,, Simultaneous Editing}.
400
401 @vindex require-final-newline
402   If the variable @code{require-final-newline} is non-@code{nil}, Emacs
403 puts a newline at the end of any file that doesn't already end in one,
404 every time a file is saved or written.
405
406 @vindex write-file-hooks
407 @vindex after-save-hook
408   Use the hook variable @code{write-file-hooks} to implement other ways
409 to write files, and specify things to be done before files are written.  The
410 value of this variable should be a list of Lisp functions.  When a file
411 is to be written, the functions in the list are called, one by one, with
412 no arguments.  If one of them returns a non-@code{nil} value, Emacs
413 takes this to mean that the file has been written in some suitable
414 fashion; the rest of the functions are not called, and normal writing is
415 not done. Use the hook variable @code{after-save-hook} to list
416 all the functions to be called after writing out a buffer to a file.
417
418 @menu
419 * Backup::       How Emacs saves the old version of your file.
420 * Interlocking:: How Emacs protects against simultaneous editing
421                   of one file by two users.
422 @end menu
423
424 @node Backup, Interlocking, Saving, Saving
425 @subsection Backup Files
426 @cindex backup file
427 @vindex make-backup-files
428
429   Because Unix does not provide version numbers in file names, rewriting a
430 file in Unix automatically destroys all record of what the file used to
431 contain.  Thus, saving a file from Emacs throws away the old contents of
432 the file---or it would, except that Emacs carefully copies the old contents
433 to another file, called the @dfn{backup} file, before actually saving.
434 (Make sure that the variable @code{make-backup-files} is non-@code{nil}.
435 Backup files are not written if this variable is @code{nil}).
436
437   At your option, Emacs can keep either a single backup file or a series of
438 numbered backup files for each file you edit.
439
440   Emacs makes a backup for a file only the first time a file is saved
441 from one buffer.  No matter how many times you save a file, its backup file
442 continues to contain the contents from before the file was visited.
443 Normally this means that the backup file contains the contents from before
444 the current editing session; however, if you kill the buffer and then visit
445 the file again, a new backup file is made by the next save.
446
447 @menu
448 * Names: Backup Names.          How backup files are named;
449                                 Choosing single or numbered backup files.
450 * Deletion: Backup Deletion.    Emacs deletes excess numbered backups.
451 * Copying: Backup Copying.      Backups can be made by copying or renaming.
452 @end menu
453
454 @node Backup Names, Backup Deletion, Backup, Backup
455 @subsubsection Single or Numbered Backups
456
457   If you choose to have a single backup file (the default),
458 the backup file's name is constructed by appending @samp{~} to the
459 file name being edited; thus, the backup file for @file{eval.c} is
460 @file{eval.c~}.
461
462   If you choose to have a series of numbered backup files, backup file
463 names are made by appending @samp{.~}, the number, and another @samp{~} to
464 the original file name.  Thus, the backup files of @file{eval.c} would be
465 called @file{eval.c.~1~}, @file{eval.c.~2~}, and so on, through names
466 like @file{eval.c.~259~} and beyond.
467
468   If protection stops you from writing backup files under the usual names,
469 the backup file is written as @file{%backup%~} in your home directory.
470 Only one such file can exist, so only the most recently made backup is
471 available.
472
473 @vindex version-control
474   The choice of single backup or numbered backups is controlled by the
475 variable @code{version-control}.  Its possible values are:
476
477 @table @code
478 @item t
479 Make numbered backups.
480 @item nil
481 Make numbered backups for files that have numbered backups already.
482 Otherwise, make single backups.
483 @item never
484 Never make numbered backups; always make single backups.
485 @end table
486
487 @noindent
488 @code{version-control} may be set locally in an individual buffer to
489 control the making of backups for that buffer's file.  For example,
490 Rmail mode locally sets @code{version-control} to @code{never} to make sure
491 that there is only one backup for an Rmail file.  @xref{Locals}.
492
493 @node Backup Deletion, Backup Copying, Backup Names, Backup
494 @subsubsection Automatic Deletion of Backups
495
496 @vindex kept-old-versions
497 @vindex kept-new-versions
498   To prevent unlimited consumption of disk space, Emacs can delete numbered
499 backup versions automatically.  Generally Emacs keeps the first few backups
500 and the latest few backups, deleting any in between.  This happens every
501 time a new backup is made.  The two variables that control the deletion are
502 @code{kept-old-versions} and @code{kept-new-versions}.  Their values are, respectively
503 the number of oldest (lowest-numbered) backups to keep and the number of
504 newest (highest-numbered) ones to keep, each time a new backup is made.
505 The values are used just after a new backup version is made;
506 that newly made backup is included in the count in @code{kept-new-versions}.
507 By default, both variables are 2.
508
509 @vindex delete-old-versions
510   If @code{delete-old-versions} is non-@code{nil},  excess
511 middle versions are deleted without notification.  If it is @code{nil}, the
512 default, you are asked whether the excess middle versions should
513 really be deleted.
514
515   You can also use Dired's @kbd{.} (Period) command to delete old versions.
516 @xref{Dired}.
517
518 @node Backup Copying,  , Backup Deletion, Backup
519 @subsubsection Copying vs.@: Renaming
520
521   You can make backup files by copying the old file or by renaming it.
522 This makes a difference when the old file has multiple names.  If you
523 rename the old file into the backup file, the alternate names
524 become names for the backup file.  If you copy the old file instead,
525 the alternate names remain names for the file that you are editing,
526 and the contents accessed by those names will be the new contents.
527
528   How you make a backup file may also affect the file's owner
529 and group.  If you use copying, they do not change.  If renaming is used,
530 you become the file's owner, and the file's group becomes the default
531 (different operating systems have different defaults for the group).
532
533   Having the owner change is usually a good idea, because then the owner
534 is always the person who last edited the file.  Occasionally there is a
535 file whose owner should not change.  Since most files should change
536 owners, it is a good idea to use local variable lists to set
537 @code{backup-by-copying-when-mismatch} for the special cases where the
538 owner should not change (@pxref{File Variables}).
539
540 @vindex backup-by-copying
541 @vindex backup-by-copying-when-linked
542 @vindex backup-by-copying-when-mismatch
543   Three variables control the choice of renaming or copying.
544 Normally, renaming is done.  If the variable @code{backup-by-copying} is
545 non-@code{nil}, copying is used.  Otherwise, if the variable
546 @code{backup-by-copying-when-linked} is non-@code{nil}, copying is
547 done for files that have multiple names, but renaming may still be done when
548 the file being edited has only one name.  If the variable
549 @code{backup-by-copying-when-mismatch} is non-@code{nil}, copying is
550 done if renaming would cause the file's owner or group to change.  @refill
551
552 @node Interlocking,  , Backup, Saving
553 @subsection Protection Against Simultaneous Editing
554
555 @cindex file dates
556 @cindex simultaneous editing
557   Simultaneous editing occurs when two users visit the same file, both
558 make changes, and both save their changes.  If no one was informed that
559 this was happening, and you saved first, you would later find that your
560 changes were lost.  On some systems, Emacs notices immediately when the
561 second user starts to change a file already being edited, and issues a
562 warning.  When this is not possible, or if the second user has started
563 to change the file despite the warning, Emacs checks when the file is
564 saved, and issues a second warning when a user is about to overwrite a
565 file containing another user's changes.  If you are the user editing the
566 file, you can take corrective action at this point and prevent actual
567 loss of work.
568
569 @findex ask-user-about-lock
570   When you make the first modification in an Emacs buffer that is visiting
571 a file, Emacs records that you have locked the file.  (It does this by
572 writing another file in a directory reserved for this purpose.)  The lock
573 is removed when you save the changes.  The idea is that the file is locked
574 whenever the buffer is modified.  If you begin to modify the buffer while
575 the visited file is locked by someone else, this constitutes a collision,
576 and Emacs asks you what to do.  It does this by calling the Lisp function
577 @code{ask-user-about-lock}, which you can redefine to customize what it
578 does.  The standard definition of this function asks you a
579 question and accepts three possible answers:
580
581 @table @kbd
582 @item s
583 Steal the lock.  Whoever was already changing the file loses the lock,
584 and you get the lock.
585 @item p
586 Proceed.  Go ahead and edit the file despite its being locked by someone else.
587 @item q
588 Quit.  This causes an error (@code{file-locked}) and the modification you
589 were trying to make in the buffer does not actually take place.
590 @end table
591
592   Note that locking works on the basis of a file name; if a file has
593 multiple names, Emacs does not realize that the two names are the same file
594 and cannot prevent two users from editing it simultaneously under different
595 names.  However, basing locking on names means that Emacs can interlock the
596 editing of new files that do not really exist until they are saved.
597
598   Some systems are not configured to allow Emacs to make locks.  On
599 these systems, Emacs cannot detect trouble in advance, but it can still
600 detect it in time to prevent you from overwriting someone else's changes.
601
602   Every time Emacs saves a buffer, it first checks the last-modification
603 date of the existing file on disk to see that it has not changed since the
604 file was last visited or saved.  If the date does not match, it implies
605 that changes were made in the file in some other way, and these changes are
606 about to be lost if Emacs actually does save.  To prevent this, Emacs
607 prints a warning message and asks for confirmation before saving.
608 Occasionally you will know why the file was changed and know that it does
609 not matter; then you can answer @kbd{yes} and proceed.  Otherwise, you should
610 cancel the save with @kbd{C-g} and investigate the situation.
611
612   The first thing you should do when notified that simultaneous editing
613 has already taken place is to list the directory with @kbd{C-u C-x C-d}
614 (@pxref{ListDir,,Directory Listing}).  This will show the file's current
615 author.  You should attempt to contact that person and ask him not to
616 continue editing.  Often the next step is to save the contents of your
617 Emacs buffer under a different name, and use @code{diff} to compare the
618 two files.@refill
619
620   Simultaneous editing checks are also made when you visit a file that
621 is already visited with @kbd{C-x C-f} and when you start to modify a
622 file.  This is not strictly necessary, but it is useful to find out
623 about such a problem as early as possible, when corrective action takes
624 less work.
625
626 @findex set-default-file-modes
627 @cindex file protection
628 Another way to protect your file is to set the read, write, and
629 executable permissions for the file. Use the function
630 @code{set-default-file-modes} to set the UNIX @code{umask} value to the
631 @var{nmask} argument. The @code{umask} value is the default protection
632 mode for new files.
633
634 @node Reverting, Auto Save, Saving, Files
635 @section Reverting a Buffer
636 @findex revert-buffer
637 @cindex drastic changes
638
639   If you have made extensive changes to a file and then change your mind
640 about them, you can get rid of all changes by reading in the previous
641 version of the file.  To do this, use @kbd{M-x revert-buffer}, which
642 operates on the current buffer.  Since reverting a buffer can result in
643 very extensive changes, you must confirm it with @kbd{yes}.
644
645   You may request that @code{revert-buffer} check for an auto-save file
646 that is more recent than the visited file by providing a prefix
647 argument.  If a recent auto-save file exists, @code{revert-buffer}
648 offers to read the auto-save file instead of the visited file
649 (@pxref{Auto Save}).  Emacs asks you about the auto-save file before the
650 request for confirmation of the @kbd{revert-buffer} operation, and
651 demands @kbd{y} or @kbd{n} as an answer.  If you have started to type
652 @kbd{yes} to confirm the revert operation, the @kbd{y} will answer the
653 question about using the auto-save file, but the @kbd{es} will not be
654 valid confirmation for the reversion.  This gives you a chance to cancel
655 the operation with @kbd{C-g} and try again with the answers you really
656 intend.
657
658   @code{revert-buffer} preserves the value of point (in characters from
659 the beginning of the file).  If the file was edited only slightly, you
660 will be at approximately the same piece of text after reverting as
661 before.  If you have made more extensive changes, after reversion point
662 may be in a totally different context than your last edits before
663 reversion.
664
665 A buffer reverted from its visited file is marked ``not modified'' until
666 you make a change.  The buffer's modes will also be recalculated, by
667 @code{normal-mode}.
668
669   Some kinds of buffers whose contents reflect data bases other than files,
670 such as Dired buffers, can also be reverted.  For them, reverting means
671 refreshing their contents from the appropriate data.  Buffers created
672 randomly with @kbd{C-x b} cannot be reverted; @code{revert-buffer}
673 reports an error when asked to do so.
674
675 @node Auto Save, Version Control, Reverting, Files
676 @section Auto-Saving: Protection Against Disasters
677 @cindex Auto-Save mode
678 @cindex crashes
679
680   Emacs saves all the visited files from time to time (based on counting
681 your keystrokes) without being asked.  This is called @dfn{auto-saving}.
682 It prevents you from losing more than a limited amount of work if the
683 system crashes.
684
685   When Emacs determines it is time for auto-saving, each buffer is
686 considered and is auto-saved if auto-saving is turned on for it and it has
687 changed since the last time it was auto-saved.  If any auto-saving is
688 done, the message @samp{Auto-saving...} is displayed in the echo area until
689 auto-saving is finished.  Errors occurring during auto-saving are caught
690 so that they do not interfere with the execution of commands you have been
691 typing.
692
693 @menu
694 * Files: Auto Save Files.
695 * Control: Auto Save Control.
696 * Recover::             Recovering text from auto-save files.
697 @end menu
698
699 @node Auto Save Files, Auto Save Control, Auto Save, Auto Save
700 @subsection Auto-Save Files
701
702   Auto-saving does not normally write to the files you visited, because
703 it can be undesirable to save a program that is in an inconsistent
704 state when you have made only half of a planned change.  Instead, auto-saving
705 is done in a different file called the @dfn{auto-save file}, and the
706 visited file is changed only when you save explicitly, for example,
707 with @kbd{C-x C-s}.
708
709   Normally, the name of the auto-save file is generated by appending
710 @samp{#} to the front and back of the visited file name.  Thus, a buffer
711 visiting file @file{foo.c} would be auto-saved in a file @file{#foo.c#}.
712 Most buffers that are not visiting files are auto-saved only if you
713 request it explicitly; when they are auto-saved, the auto-save file name
714 is generated by appending @samp{#%} to the front and @samp{#} to the
715 back of buffer name.  For example, the @samp{*mail*} buffer in which you
716 compose messages to be sent is auto-saved in a file named
717 @file{#%*mail*#}.  Names of auto-save files are generated this way
718 unless you customize the functions @code{make-auto-save-file-name} and
719 @code{auto-save-file-name-p} to do something different.  The file name
720 to be used for auto-saving a buffer is calculated at the time auto-saving is
721 turned on in that buffer.
722
723 @vindex auto-save-visited-file-name
724   If you want auto-saving to be done in the visited file, set the variable
725 @code{auto-save-visited-file-name} to be non-@code{nil}.  In this mode,
726 there is really no difference between auto-saving and explicit saving.
727
728 @vindex delete-auto-save-files
729   Emacs deletes a buffer's auto-save file when you explicitly save the
730 buffer.  To inhibit the deletion, set the variable
731 @code{delete-auto-save-files} to @code{nil}.  Changing the visited file
732 name with @kbd{C-x C-w} or @code{set-visited-file-name} renames any
733 auto-save file to correspond to the new visited name.
734
735 @node Auto Save Control, Recover, Auto Save Files, Auto Save
736 @subsection Controlling Auto-Saving
737
738 @vindex auto-save-default
739 @findex auto-save-mode
740   Each time you visit a file, auto-saving is turned on for that file's
741 buffer if the variable @code{auto-save-default} is non-@code{nil} (but
742 not in batch mode; @pxref{Entering Emacs}).  The default for this
743 variable is @code{t}, so Emacs auto-saves buffers that visit files by
744 default.  You can use the command @kbd{M-x auto-save-mode} to turn
745 auto-saving for a buffer on or off.  Like other minor mode commands,
746 @kbd{M-x auto-save-mode} turns auto-saving on with a positive argument,
747 off with a zero or negative argument; with no argument, it toggles.
748
749 @vindex auto-save-interval
750 @findex do-auto-save
751   Emacs performs auto-saving periodically based on counting how many
752 characters you have typed since the last time auto-saving happened.  The
753 variable @code{auto-save-interval} specifies the number of characters
754 between auto-saves.  By default, it is 300.  Emacs also auto-saves
755 whenever you call the function @code{do-auto-save}.
756
757   Emacs also does auto-saving whenever it gets a fatal error.  This
758 includes killing the Emacs job with a shell command such as @code{kill
759 -emacs}, or disconnecting a phone line or network connection.
760
761 @vindex auto-save-timeout
762 You can set the number of seconds of idle time before an auto-save is
763 done. Setting the value of the variable @code{auto-save-timeout} to zero or
764 @code{nil} will  disable auto-saving due to idleness.
765
766 The actual amount of idle time between auto-saves is logarithmically
767 related to the size of the current buffer.  This variable is the number
768 of seconds after which an auto-save will happen when the current buffer
769 is 50k or less; the timeout will be 2 1/4 times this in a 200k buffer, 3
770 3/4 times this in a 1000k buffer, and 4 1/2 times this in a 2000k
771 buffer.
772
773 For this variable to have any effect, you must do @code{(require 'timer)}.
774
775 @node Recover,  , Auto Save Control, Auto Save
776 @subsection Recovering Data from Auto-Saves
777
778 @findex recover-file
779   If you want to use the contents of an auto-save file to recover from a
780 loss of data, use the command @kbd{M-x recover-file @key{RET} @var{file}
781 @key{RET}}.  Emacs visits @var{file} and then (after your confirmation)
782 restores the contents from the auto-save file @file{#@var{file}#}.  You
783 can then save the file with @kbd{C-x C-s} to put the recovered text into
784 @var{file} itself.  For example, to recover file @file{foo.c} from its
785 auto-save file @file{#foo.c#}, do:@refill
786
787 @example
788 M-x recover-file @key{RET} foo.c @key{RET}
789 C-x C-s
790 @end example
791
792   Before asking for confirmation, @kbd{M-x recover-file} displays a
793 directory listing describing the specified file and the auto-save file,
794 so you can compare their sizes and dates.  If the auto-save file
795 is older, @kbd{M-x recover-file} does not offer to read it.
796
797   Auto-saving is disabled by @kbd{M-x recover-file} because using
798 this command implies that the auto-save file contains valuable data
799 from a past session.  If you save the data in the visited file and
800 then go on to make new changes, turn auto-saving back on
801 with @kbd{M-x auto-save-mode}.
802
803 @node Version Control, ListDir, Auto Save, Files
804 @section Version Control
805 @cindex version control
806
807   @dfn{Version control systems} are packages that can record multiple
808 versions of a source file, usually storing the unchanged parts of the
809 file just once.  Version control systems also record history information
810 such as the creation time of each version, who created it, and a
811 description of what was changed in that version.
812
813   The GNU project recommends the version control system known as RCS,
814 which is free software and available from the Free Software Foundation.
815 Emacs supports use of either RCS or SCCS (a proprietary, but widely
816 used, version control system that is not quite as powerful as RCS)
817 through a facility called VC.  The same Emacs commands work with either
818 RCS or SCCS, so you hardly have to know which one of them you are
819 using.
820
821 @menu
822 * Concepts of VC::              Basic version control information;
823                                   checking files in and out.
824 * Editing with VC::             Commands for editing a file maintained
825                                   with version control.
826 * Variables for Check-in/out::  Variables that affect the commands used
827                                   to check files in or out.
828 * Log Entries::                 Logging your changes.
829 * Change Logs and VC::          Generating a change log file from log
830                                   entries.
831 * Old Versions::                Examining and comparing old versions.
832 * VC Status::                   Commands to view the VC status of files and
833                                   look at log entries.
834 * Renaming and VC::             A command to rename both the source and
835                                   master file correctly.
836 * Snapshots::                   How to make and use snapshots, a set of
837                                   file versions that can be treated as a unit.
838 * Version Headers::             Inserting version control headers into
839                                   working files.
840 @end menu
841
842 @node Concepts of VC, Editing with VC, Version Control, Version Control
843 @subsection Concepts of Version Control
844
845 @cindex RCS
846 @cindex SCCS
847 @cindex master file
848 @cindex registered file
849 @cindex work file
850    When a file is under version control, we also say that it is
851 @dfn{registered} in the version control system.  Each registered file
852 has a corresponding @dfn{master file} which represents the file's
853 present state plus its change history, so that you can reconstruct from
854 it either the current version or any specified earlier version.  Usually
855 the master file also records a @dfn{log entry} for each version describing
856 what was changed in that version.
857
858   The file that is maintained under version control is sometimes called
859 the @dfn{work file} corresponding to its master file.
860
861 @cindex checking out files
862 @cindex checking in files
863 @cindex locking and version control
864    To examine a file, you @dfn{check it out}.  This extracts a version
865 of the source file (typically, the most recent) from the master file.
866 If you want to edit the file, you must check it out @dfn{locked}.  Only
867 one user can do this at a time for any given source file.  (This kind
868 of locking is completely unrelated to the locking that Emacs uses to
869 detect simultaneous editing of a file.)
870
871   When you are done with your editing, you must @dfn{check in} the new
872 version.  This records the new version in the master file, and unlocks
873 the source file so that other people can lock it and thus modify it.
874
875   Checkin and checkout are the basic operations of version control.  You
876 can do both of them with a single Emacs command: @w{@kbd{C-x C-q}}
877 (@code{vc-toggle-read-only}).
878
879   A @dfn{snapshot} is a coherent collection of versions of the various
880 files that make up a program.  @xref{Snapshots}.
881
882 @node Editing with VC, Variables for Check-in/out, Concepts of VC, Version Control
883 @subsection Editing with Version Control
884
885   When you visit a file that is maintained using version control, the
886 mode line displays @samp{RCS} or @samp{SCCS} to inform you that version
887 control is in use, and also (in case you care) which low-level system
888 the file is actually stored in.  Normally, such a source file is
889 read-only, and the mode line indicates this with @samp{%%}.  With RCS,
890 the mode line also indicates the number of the head version, which is
891 normally also the version you are looking at.
892
893   These are the commands for editing a file maintained with
894 version control:
895
896 @table @kbd
897 @item C-x C-q
898 Check the visited file in or out.
899
900 @item C-x v u
901 Revert the buffer and the file to the last checked in version.
902
903 @item C-x v c
904 Remove the last-entered change from the master for the visited file.
905 This undoes your last check-in.
906
907 @item C-x v i
908 Register the visited file in version control.
909 @end table
910
911 @noindent
912 (@kbd{C-x v} is the prefix key for version control commands; all of these
913 commands except for @kbd{C-x C-q} start with @kbd{C-x v}.)
914
915 @kindex C-x C-q @r{(version control)}
916   When you want to modify a file maintained with version control, type
917 @kbd{C-x C-q} (@code{vc-toggle-read-only}).  This @dfn{checks out} the
918 file, and tells RCS or SCCS to lock the file.  This means making the
919 file writable for you (but not for anyone else).
920
921 @cindex log entry
922   When you are finished editing the file, type @kbd{C-x C-q} again.
923 When used on a file that is checked out, this command checks the file
924 in.  But check-in does not start immediately; first, you must enter the
925 @dfn{log entry}---a description of the changes in the new version.
926 @kbd{C-x C-q} pops up a buffer for you to enter this in.  When you are
927 finished typing in the log entry, type @kbd{C-c C-c} to terminate it; this is
928 when actual check-in takes place.
929
930   Once you have checked in your changes, the file is unlocked, so that
931 other users can lock it and modify it.
932
933 @vindex vc-make-backup-files
934   Emacs does not save backup files for source files that are maintained
935 with version control.  If you want to make backup files despite version
936 control, set the variable @code{vc-make-backup-files} to a
937 non-@code{nil} value.
938
939 @vindex vc-keep-workfiles
940   Normally the work file exists all the time, whether it is locked or
941 not.  If you set @code{vc-keep-workfiles} to @code{nil}, then checking
942 in a new version with @kbd{C-x C-q} deletes the work file; but any
943 attempt to visit the file with Emacs creates it again.
944
945   It is not impossible to lock a file that someone else has locked.  If
946 you try to check out a file that is locked, @kbd{C-x C-q} asks you
947 whether you want to ``steal the lock.''  If you say yes, the file
948 becomes locked by you, but a message is sent to the person who had
949 formerly locked the file, to inform him of what has happened.  The mode
950 line indicates that a file is locked by someone else by displaying the
951 login name of that person, before the version number.
952
953 @kindex C-x v u
954 @findex vc-revert-buffer
955   If you want to discard your current set of changes and revert to the
956 last version checked in, use @kbd{C-x v u} (@code{vc-revert-buffer}).
957 This cancels your last check-out, leaving the file unlocked.  If you want
958 to make a different set of changes, you must first check the file out
959 again.  @kbd{C-x v u} requires confirmation, unless it sees that
960 you haven't made any changes since the last checked-in version.
961
962   @kbd{C-x v u} is also the command to use if you lock a file and then
963 don't actually change it.
964
965 @kindex C-x v c
966 @findex vc-cancel-version
967   You can cancel a change after checking it in, with @kbd{C-x v c}
968 (@code{vc-cancel-version}).  This command discards all record of the
969 most recent checked in version, so be careful about using it.  It
970 requires confirmation with @kbd{yes}.  By default, @kbd{C-x v c} reverts
971 your workfile and buffer to the previous version (the one that precedes
972 the version that is deleted), but you can prevent the reversion by
973 giving the command a prefix argument.  Then the buffer does not change.
974
975   This command with a prefix argument is useful when you have checked in
976 a change and then discover a trivial error in it; you can cancel the
977 erroneous check-in, fix the error, and repeat the check-in.
978
979   Be careful when invoking @kbd{C-x v c}, as it is easy to throw away a
980 lot of work with it.  To help you be careful, this command always
981 requires confirmation with @samp{yes}.
982
983 @kindex C-x v i
984 @findex vc-register
985 @vindex vc-default-back-end
986   You can register the visited file for version control using
987 @w{@kbd{C-x v i}} (@code{vc-register}).  If the variable
988 @code{vc-default-back-end} is non-@code{nil}, it specifies which
989 version control system to use; otherwise, this uses RCS if it is
990 installed on your system and SCCS if not.  After @kbd{C-x v i},
991 the file is unlocked and read-only.  Type @kbd{C-x C-q} if you wish to
992 edit it.
993
994   By default, the initial version number is 1.1.  If you want to use a
995 different number, give @kbd{C-x v i} a prefix argument; then it reads
996 the initial version number using the minibuffer.
997
998 @vindex vc-initial-comment
999   If @code{vc-initial-comment} is non-@code{nil}, @kbd{C-x v i} reads
1000 an initial comment (much like a log entry) to describe the purpose of
1001 this source file.
1002
1003 @kindex C-u C-x v v
1004 @findex vc-next-action
1005   To specify the version number for a subsequent checkin, use the
1006 command @kbd{C-u C-x v v}.  @kbd{C-x v v} (@code{vc-next-action}) is the
1007 command that @kbd{C-x C-q} uses to do the ``real work'' when the visited
1008 file uses version control.  When used for checkin, and given a prefix
1009 argument, it reads the version number with the minibuffer.
1010
1011 @node Variables for Check-in/out, Log Entries, Editing with VC, Version Control
1012 @subsection Variables Affecting Check-in and Check-out
1013 @c There is no need to tell users about vc-master-templates.
1014
1015 @vindex vc-suppress-confirm
1016   If @code{vc-suppress-confirm} is non-@code{nil}, then @kbd{C-x C-q}
1017 and @kbd{C-x v i} can save the current buffer without asking, and
1018 @kbd{C-x v u} also operates without asking for confirmation.
1019 (This variable does not affect @kbd{C-x v c}; that is so drastic
1020 that it should always ask for confirmation.)
1021
1022 @vindex vc-command-messages
1023   VC mode does much of its work by running the shell commands for RCS
1024 and SCCS.  If @code{vc-command-messages} is non-@code{nil}, VC displays
1025 messages to indicate which shell commands it runs, and additional
1026 messages when the commands finish.
1027
1028   Normally, VC assumes that it can deduce the locked/unlocked state of
1029 files by looking at the file permissions of the work file; this is
1030 fast.  However, if the @file{RCS} or @file{SCCS} subdirectory is
1031 actually a symbolic link, then VC does not trust the file permissions to
1032 reflect this status.
1033
1034 @vindex vc-mistrust-permissions
1035 You can specify the criterion for whether to trust the file permissions
1036 by setting the variable @code{vc-mistrust-permissions}.  Its value may
1037 be @code{t} (always mistrust the file permissions and check the master
1038 file), @code{nil} (always trust the file permissions), or a function of
1039 one argument which makes the decision.  The argument is the directory
1040 name of the @file{RCS} or @file{SCCS} subdirectory.  A non-@code{nil}
1041 value from the function says to mistrust the file permissions.
1042
1043   If you find that the file permissions of work files are changed
1044 erroneously, set @code{vc-mistrust-permissions} to @code{t}.  Then VC
1045 always checks the master file to determine the file's status.
1046
1047 @vindex vc-path
1048   You can specify additional directories to search for version control
1049 programs by setting the variable @code{vc-path}.  These directories
1050 are searched before the usual search path.  The proper result usually
1051 happens automatically.
1052
1053 @node Log Entries, Change Logs and VC, Variables for Check-in/out, Version Control
1054 @subsection Log Entries
1055
1056   When you're editing an initial comment or log entry for inclusion in a
1057 master file, finish your entry by typing @kbd{C-c C-c}.
1058
1059 @table @kbd
1060 @item C-c C-c
1061 Finish the comment edit normally (@code{vc-finish-logentry}).
1062 This finishes check-in.
1063 @end table
1064
1065   To abort check-in, just don't type @kbd{C-c C-c} in that buffer.  You
1066 can switch buffers and do other editing.  As long as you don't try to
1067 check in another file, the entry you were editing remains in its
1068 buffer, and you can go back to that buffer at any time to complete the
1069 check-in.
1070
1071   If you change several source files for the same reason, it is often
1072 convenient to specify the same log entry for many of the files.  To do
1073 this, use the history of previous log entries.  The commands @kbd{M-n},
1074 @kbd{M-p}, @kbd{M-s} and @kbd{M-r} for doing this work just like the
1075 minibuffer history commands (except that these versions are used outside
1076 the minibuffer).
1077
1078 @vindex vc-log-mode-hook
1079   Each time you check in a file, the log entry buffer is put into VC Log
1080 mode, which involves running two hooks: @code{text-mode-hook} and
1081 @code{vc-log-mode-hook}.
1082
1083 @node Change Logs and VC, Old Versions, Log Entries, Version Control
1084 @subsection Change Logs and VC
1085
1086   If you use RCS for a program and also maintain a change log file for
1087 it (@pxref{Change Log}), you can generate change log entries
1088 automatically from the version control log entries:
1089
1090 @table @kbd
1091 @item C-x v a
1092 @kindex C-x v a
1093 @findex vc-update-change-log
1094 Visit the current directory's change log file and create new entries for
1095 versions checked in since the most recent entry in the change log file
1096 (@code{vc-update-change-log}).
1097
1098 This command works with RCS only; it does not work with SCCS.
1099 @end table
1100
1101   For example, suppose the first line of @file{ChangeLog} is dated 10
1102 April 1992, and that the only check-in since then was by Nathaniel
1103 Bowditch to @file{rcs2log} on 8 May 1992 with log text @samp{Ignore log
1104 messages that start with `#'.}.  Then @kbd{C-x v a} visits
1105 @file{ChangeLog} and inserts text like this:
1106
1107 @smallexample
1108 @group
1109 Fri May  8 21:45:00 1992  Nathaniel Bowditch  (nat@@apn.org)
1110
1111         * rcs2log: Ignore log messages that start with `#'.
1112 @end group
1113 @end smallexample
1114
1115 @noindent
1116 You can then edit the new change log entry further as you wish.
1117
1118   Normally, the log entry for file @file{foo} is displayed as @samp{*
1119 foo: @var{text of log entry}}.  The @samp{:} after @file{foo} is omitted
1120 if the text of the log entry starts with @w{@samp{(@var{functionname}):
1121 }}.  For example, if the log entry for @file{vc.el} is
1122 @samp{(vc-do-command): Check call-process status.}, then the text in
1123 @file{ChangeLog} looks like this:
1124
1125 @smallexample
1126 @group
1127 Wed May  6 10:53:00 1992  Nathaniel Bowditch  (nat@@apn.org)
1128
1129         * vc.el (vc-do-command): Check call-process status.
1130 @end group
1131 @end smallexample
1132
1133   When @kbd{C-x v a} adds several change log entries at once, it groups
1134 related log entries together if they all are checked in by the same
1135 author at nearly the same time.  If the log entries for several such
1136 files all have the same text, it coalesces them into a single entry.
1137 For example, suppose the most recent checkins have the following log
1138 entries:
1139
1140 @example
1141 @exdent For @file{vc.texinfo}:
1142 Fix expansion typos.
1143 @exdent For @file{vc.el}:
1144 Don't call expand-file-name.
1145 @exdent For @file{vc-hooks.el}:
1146 Don't call expand-file-name.
1147 @end example
1148
1149   They appear like this in @file{ChangeLog}:
1150
1151 @smallexample
1152 @group
1153 Wed Apr  1 08:57:59 1992  Nathaniel Bowditch  (nat@@apn.org)
1154
1155         * vc.texinfo: Fix expansion typos.
1156
1157         * vc.el, vc-hooks.el: Don't call expand-file-name.
1158 @end group
1159 @end smallexample
1160
1161   Normally, @kbd{C-x v a} separates log entries by a blank line, but you
1162 can mark several related log entries to be clumped together (without an
1163 intervening blank line) by starting the text of each related log entry
1164 with a label of the form @w{@samp{@{@var{clumpname}@} }}.  The label
1165 itself is not copied to @file{ChangeLog}.  For example, suppose the log
1166 entries are:
1167
1168 @example
1169 @exdent For @file{vc.texinfo}:
1170 @{expand@} Fix expansion typos.
1171 @exdent For @file{vc.el}:
1172 @{expand@} Don't call expand-file-name.
1173 @exdent For @file{vc-hooks.el}:
1174 @{expand@} Don't call expand-file-name.
1175 @end example
1176
1177 @noindent
1178 Then the text in @file{ChangeLog} looks like this:
1179
1180 @smallexample
1181 @group
1182 Wed Apr  1 08:57:59 1992  Nathaniel Bowditch  (nat@@apn.org)
1183
1184         * vc.texinfo: Fix expansion typos.
1185         * vc.el, vc-hooks.el: Don't call expand-file-name.
1186 @end group
1187 @end smallexample
1188
1189   A log entry whose text begins with @samp{#} is not copied to
1190 @file{ChangeLog}.  For example, if you merely fix some misspellings in
1191 comments, you can log the change with an entry beginning with @samp{#}
1192 to avoid putting such trivia into @file{ChangeLog}.
1193
1194 @node Old Versions, VC Status, Change Logs and VC, Version Control
1195 @subsection Examining And Comparing Old Versions
1196
1197 @table @kbd
1198 @item C-x v ~ @var{version} @key{RET}
1199 Examine version @var{version} of the visited file, in a buffer of its
1200 own (@code{vc-version-other-window}).
1201
1202 @item C-x v =
1203 Compare the current buffer contents with the latest checked-in version
1204 of the file.
1205
1206 @item C-u C-x v = @var{file} @key{RET} @var{oldvers} @key{RET} @var{newvers} @key{RET}
1207 Compare the specified two versions of @var{file}.
1208 @end table
1209
1210 @findex vc-version-other-window
1211 @kindex C-x v ~
1212   You can examine any version of a file by first visiting it, and then
1213 using @kbd{C-x v ~ @var{version} @key{RET}}
1214 (@code{vc-version-other-window}).  This puts the text of version
1215 @var{version} in a file named @file{@var{filename}.~@var{version}~},
1216 then visits it in a separate window.
1217
1218 @findex vc-diff
1219 @kindex C-x v =
1220   To compare two versions of a file, use the command @kbd{C-x v =}
1221 (@code{vc-diff}).
1222
1223   Plain @kbd{C-x v =} compares the current buffer contents (saving them
1224 in the file if necessary) with the last checked-in version of the file.
1225 With a prefix argument, @kbd{C-x v =} reads a file name and two version
1226 numbers, then compares those versions of the specified file.
1227
1228   If you supply a directory name instead of the name of a work file,
1229 this command compares the two specified versions of all registered files
1230 in that directory and its subdirectories.  You can also specify a
1231 snapshot name (@pxref{Snapshots}) instead of one or both version
1232 numbers.
1233
1234   You can specify a checked-in version by its number; you can specify
1235 the most recent checked-in version with an empty version number.
1236
1237   This command works by running the @code{vcdiff} utility, getting the
1238 options from the variable @code{diff-switches}.  It displays the output
1239 in a special buffer in another window.  Unlike the @kbd{M-x diff}
1240 command, @kbd{C-x v =} does not try to find the changes in the old and
1241 new versions.  This is because one or both versions normally do not
1242 exist as files.  They exist only in the records of the master file.
1243 @xref{Comparing Files}, for more information about @kbd{M-x diff}.
1244
1245 @node VC Status, Renaming and VC, Old Versions, Version Control
1246 @subsection VC Status Commands
1247
1248 @kindex C-x v l
1249 @findex vc-print-log
1250   To view the detailed version control status and history of a file,
1251 type @kbd{C-x v l} (@code{vc-print-log}).  It displays the history of
1252 changes to the current file, including the text of the log entries.  The
1253 output appears in a separate window.
1254
1255 @kindex C-x v d
1256 @findex vc-directory
1257   When you are working on a large program, it's often useful to find all
1258 the files that are currently locked, or all the files maintained in
1259 version control at all.  You can use @kbd{C-x v d} (@code{vc-directory})
1260 to show all the locked files in or beneath the current directory.  This
1261 includes all files that are locked by any user.  @kbd{C-u C-x v d} lists
1262 all files in or beneath the current directory that are maintained with
1263 version control.
1264
1265   The list of files is displayed as a buffer that uses an augmented
1266 Dired mode.  The names of the users locking various files are shown (in
1267 parentheses) in place of the owner and group.  All the normal Dired
1268 commands work in this buffer.  Most interactive VC commands work also,
1269 and apply to the file name on the current line.
1270
1271   The @kbd{C-x v v} command (@code{vc-next-action}), when used in the
1272 augmented Dired buffer, operates on all the marked files (or the file on
1273 the current line).  If it operates on more than one file, it handles
1274 each file according to its current state; thus, it may check out one
1275 file and check in another (because it is already checked out).  If it
1276 has to check in any files, it reads a single log entry, then uses that
1277 text for all the files being checked in.  This can be convenient for
1278 registering or checking in several files at once, as part of the same
1279 change.
1280
1281 @node Renaming and VC, Snapshots, VC Status, Version Control
1282 @subsection Renaming VC Work Files and Master Files
1283
1284 @findex vc-rename-file
1285   When you rename a registered file, you must also rename its master
1286 file correspondingly to get proper results.  Use @code{vc-rename-file}
1287 to rename the source file as you specify, and rename its master file
1288 accordingly.  It also updates any snapshots (@pxref{Snapshots}) that
1289 mention the file, so that they use the new name; despite this, the
1290 snapshot thus modified may not completely work (@pxref{Snapshot
1291 Caveats}).
1292
1293   You cannot use @code{vc-rename-file} on a file that is locked by
1294 someone else.
1295
1296 @node Snapshots, Version Headers, Renaming and VC, Version Control
1297 @subsection Snapshots
1298 @cindex snapshots and version control
1299
1300   A @dfn{snapshot} is a named set of file versions (one for each
1301 registered file) that you can treat as a unit.  One important kind of
1302 snapshot is a @dfn{release}, a (theoretically) stable version of the
1303 system that is ready for distribution to users.
1304
1305 @menu
1306 * Making Snapshots::            The snapshot facilities.
1307 * Snapshot Caveats::            Things to be careful of when using snapshots.
1308 @end menu
1309
1310 @node Making Snapshots, Snapshot Caveats, Snapshots, Snapshots
1311 @subsubsection Making and Using Snapshots
1312
1313   There are two basic commands for snapshots; one makes a
1314 snapshot with a given name, the other retrieves a named snapshot.
1315
1316 @table @code
1317 @kindex C-x v s
1318 @findex vc-create-snapshot
1319 @item C-x v s @var{name} @key{RET}
1320 Define the last saved versions of every registered file in or under the
1321 current directory as a snapshot named @var{name}
1322 (@code{vc-create-snapshot}).
1323
1324 @kindex C-x v r
1325 @findex vc-retrieve-snapshot
1326 @item C-x v r @var{name} @key{RET}
1327 Check out all registered files at or below the current directory level
1328 using whatever versions correspond to the snapshot @var{name}
1329 (@code{vc-retrieve-snapshot}).
1330
1331 This command reports an error if any files are locked at or below the
1332 current directory, without changing anything; this is to avoid
1333 overwriting work in progress.
1334 @end table
1335
1336   A snapshot uses a very small amount of resources---just enough to record
1337 the list of file names and which version belongs to the snapshot.  Thus,
1338 you need not hesitate to create snapshots whenever they are useful.
1339
1340   You can give a snapshot name as an argument to @kbd{C-x v =} or
1341 @kbd{C-x v ~} (@pxref{Old Versions}).  Thus, you can use it to compare a
1342 snapshot against the current files, or two snapshots against each other,
1343 or a snapshot against a named version.
1344
1345 @node Snapshot Caveats,  , Making Snapshots, Snapshots
1346 @subsubsection Snapshot Caveats
1347
1348 @cindex named configurations (RCS)
1349   VC's snapshot facilities are modeled on RCS's named-configuration
1350 support.  They use RCS's native facilities for this, so under VC
1351 snapshots made using RCS are visible even when you bypass VC.
1352
1353 @c worded verbosely to avoid overfull hbox.
1354   For SCCS, VC implements snapshots itself.  The files it uses contain
1355 name/file/version-number triples.  These snapshots are visible only
1356 through VC.
1357
1358   A snapshot is a set of checked-in versions.  So make sure that all the
1359 files are checked in and not locked when you make a snapshot.
1360
1361   File renaming and deletion can create some difficulties with snapshots.
1362 This is not a VC-specific problem, but a general design issue in version
1363 control systems that no one has solved very well yet.
1364
1365   If you rename a registered file, you need to rename its master along
1366 with it (the command @code{vc-rename-file} does this automatically).  If
1367 you are using SCCS, you must also update the records of the snapshot, to
1368 mention the file by its new name (@code{vc-rename-file} does this,
1369 too).  An old snapshot that refers to a master file that no longer
1370 exists under the recorded name is invalid; VC can no longer retrieve
1371 it.  It would be beyond the scope of this manual to explain enough about
1372 RCS and SCCS to explain how to update the snapshots by hand.
1373
1374   Using @code{vc-rename-file} makes the snapshot remain valid for
1375 retrieval, but it does not solve all problems.  For example, some of the
1376 files in the program probably refer to others by name.  At the very
1377 least, the makefile probably mentions the file that you renamed.  If you
1378 retrieve an old snapshot, the renamed file is retrieved under its new
1379 name, which is not the name that the makefile expects.  So the program
1380 won't really work as retrieved.
1381
1382 @node Version Headers,  , Snapshots, Version Control
1383 @subsection Inserting Version Control Headers
1384
1385    Sometimes it is convenient to put version identification strings
1386 directly into working files.  Certain special strings called
1387 @dfn{version headers} are replaced in each successive version by the
1388 number of that version.
1389
1390 @kindex C-x v h
1391 @findex vc-insert-headers
1392   You can use the @kbd{C-x v h} command (@code{vc-insert-headers}) to
1393 insert a suitable header string.
1394
1395 @table @kbd
1396 @item C-x v h
1397 Insert headers in a file for use with your version-control system.
1398 @end table
1399
1400 @vindex vc-header-alist
1401   The default header string is @samp{\$Id\$} for RCS and @samp{\%W\%}
1402 for SCCS. (The actual strings inserted do not have the backslashes
1403 in them.  They were placed in the Info source file so that the
1404 strings don't get interpreted as version-control headers when the
1405 Info source files are maintained under version control.) You can
1406 specify other headers to insert by setting the variable
1407 @code{vc-header-alist}.  Its value is a list of elements of the form
1408 @code{(@var{program} . @var{string})} where @var{program} is @code{RCS}
1409 or @code{SCCS} and @var{string} is the string to use.
1410
1411   Instead of a single string, you can specify a list of strings; then
1412 each string in the list is inserted as a separate header on a line of
1413 its own.
1414
1415   It is often necessary to use ``superfluous'' backslashes when writing
1416 the strings that you put in this variable.  This is to prevent the
1417 string in the constant from being interpreted as a header itself if the
1418 Emacs Lisp file containing it is maintained with version control.
1419
1420 @vindex vc-comment-alist
1421   Each header is inserted surrounded by tabs, inside comment delimiters,
1422 on a new line at the start of the buffer.  Normally the ordinary comment
1423 start and comment end strings of the current mode are used, but for
1424 certain modes, there are special comment delimiters for this purpose;
1425 the variable @code{vc-comment-alist} specifies them.  Each element of
1426 this list has the form @code{(@var{mode} @var{starter} @var{ender})}.
1427
1428 @vindex vc-static-header-alist
1429   The variable @code{vc-static-header-alist} specifies further strings
1430 to add based on the name of the buffer.  Its value should be a list of
1431 elements of the form @code{(@var{regexp} . @var{format})}.  Whenever
1432 @var{regexp} matches the buffer name, @var{format} is inserted as part
1433 of the header.  A header line is inserted for each element that matches
1434 the buffer name, and for each string specified by
1435 @code{vc-header-alist}.  The header line is made by processing the
1436 string from @code{vc-header-alist} with the format taken from the
1437 element.  The default value for @code{vc-static-header-alist} is:
1438
1439 @example
1440 @group
1441 (("\\.c$" .
1442   "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n\
1443 #endif /* lint */\n"))
1444 @end group
1445 @end example
1446
1447 @noindent
1448 which specifies insertion of a string of this form:
1449
1450 @example
1451 @group
1452
1453 #ifndef lint
1454 static char vcid[] = "@var{string}";
1455 #endif /* lint */
1456 @end group
1457 @end example
1458
1459 @node ListDir, Comparing Files, Version Control, Files
1460 @section Listing a File Directory
1461
1462 @cindex file directory
1463 @cindex directory listing
1464   Files are organized by Unix into @dfn{directories}.  A @dfn{directory
1465 listing} is a list of all the files in a directory.  Emacs provides
1466 directory listings in brief format (file names only) and verbose format
1467 (sizes, dates, and authors included).
1468
1469 @table @kbd
1470 @item C-x C-d @var{dir-or-pattern}
1471 Print a brief directory listing (@code{list-directory}).
1472 @item C-u C-x C-d @var{dir-or-pattern}
1473 Print a verbose directory listing.
1474 @end table
1475
1476 @findex list-directory
1477 @kindex C-x C-d
1478   To print a directory listing, use @kbd{C-x C-d}
1479 (@code{list-directory}).  This command prompts in the minibuffer for a
1480 file name which is either a  directory to be listed or pattern
1481 containing wildcards for the files to be listed.  For example,
1482
1483 @example
1484 C-x C-d /u2/emacs/etc @key{RET}
1485 @end example
1486
1487 @noindent
1488 lists all the files in directory @file{/u2/emacs/etc}.  An example of
1489 specifying a file name pattern is:
1490
1491 @example
1492 C-x C-d /u2/emacs/src/*.c @key{RET}
1493 @end example
1494
1495   Normally, @kbd{C-x C-d} prints a brief directory listing containing just
1496 file names.  A numeric argument (regardless of value) tells it to print a
1497 verbose listing (like @code{ls -l}).
1498
1499 @vindex list-directory-brief-switches
1500 @vindex list-directory-verbose-switches
1501   Emacs obtains the text of a directory listing by running @code{ls} in
1502 an inferior process.  Two Emacs variables control the switches passed to
1503 @code{ls}: @code{list-directory-brief-switches} is a string giving the
1504 switches to use in brief listings (@code{"-CF"} by default).
1505 @code{list-directory-verbose-switches} is a string giving the switches
1506 to use in a verbose listing (@code{"-l"} by default).
1507
1508 The variable @code{directory-abbrev-alist} is an alist of abbreviations
1509 for file directories.  The list consists of elements of the form
1510 @code{(FROM .  TO)}, each meaning to replace @code{FROM} with @code{TO}
1511 when it appears in a directory name.  This replacement is done when
1512 setting up the default directory of a newly visited file.  Every @code{FROM}
1513 string should start with `@samp{^}'.
1514
1515 Use this feature when you have directories which you normally refer to
1516 via absolute symbolic links.  Make @code{TO} the name of the link, and
1517 @code{FROM} the name it is linked to.
1518
1519 @node Comparing Files, Dired, ListDir, Files
1520 @section Comparing Files
1521 @cindex comparing files
1522
1523 @findex diff
1524 @vindex diff-switches
1525   The command @kbd{M-x diff} compares two files, displaying the
1526 differences in an Emacs buffer named @samp{*Diff*}.  It works by running
1527 the @code{diff} program, using options taken from the variable
1528 @code{diff-switches}, whose value should be a string.
1529
1530   The buffer @samp{*Diff*} has Compilation mode as its major mode, so
1531 you can use @kbd{C-x `} to visit successive changed locations in the two
1532 source files.  You can also move to a particular hunk of changes and
1533 type @kbd{C-c C-c} to find the corresponding source location.  You can
1534 also use the other special commands of Compilation mode: @key{SPC} and
1535 @key{DEL} for scrolling, and @kbd{M-p} and @kbd{M-n} for cursor motion.
1536 @xref{Compilation}.
1537
1538 @findex diff-backup
1539   The command @kbd{M-x diff-backup} compares a specified file with its most
1540 recent backup.  If you specify the name of a backup file,
1541 @code{diff-backup} compares it with the source file that it is a backup
1542 of.
1543
1544 @findex compare-windows
1545 @cindex comparing files
1546   The command @kbd{M-x compare-windows} compares the text in the current
1547 window with that in the next window.  Comparison starts at point in each
1548 window.  Point moves forward in each window, a character at a time in each
1549 window, until the next characters in the two windows are different.  Then
1550 the command is finished.  For more information about windows in Emacs,
1551 @ref{Windows}.
1552
1553 @vindex compare-ignore-case
1554   With a numeric argument, @code{compare-windows} ignores changes in
1555 whitespace.  If the variable @code{compare-ignore-case} is
1556 non-@code{nil}, it ignores differences in case as well.
1557
1558 @node Dired, Misc File Ops, Comparing Files, Files
1559 @section Dired, the Directory Editor
1560 @cindex Dired
1561 @cindex deletion (of files)
1562
1563   Dired makes it easy to delete or visit many of the files in a single
1564 directory at once.  It creates an Emacs buffer containing a listing of the
1565 directory.  You can use the normal Emacs commands to move around in this
1566 buffer and special Dired commands to operate on the files.
1567
1568 @menu
1569 * Enter: Dired Enter.         How to invoke Dired.
1570 * Edit: Dired Edit.           Editing the Dired buffer.
1571 * Deletion: Dired Deletion.   Deleting files with Dired.
1572 * Immed: Dired Immed.         Other file operations through Dired.
1573 @end menu
1574
1575 @node Dired Enter, Dired Edit, Dired, Dired
1576 @subsection Entering Dired
1577
1578 @findex dired
1579 @kindex C-x d
1580 @vindex dired-listing-switches
1581   To invoke dired, type @kbd{C-x d} or @kbd{M-x dired}.  The command reads a
1582 directory name or wildcard file name pattern as a minibuffer argument just
1583 like the @code{list-directory} command, @kbd{C-x C-d}.  Where @code{dired}
1584 differs from @code{list-directory} is in naming the buffer after the
1585 directory name or the wildcard pattern used for the listing, and putting
1586 the buffer into Dired mode so that the special commands of Dired are
1587 available in it.  The variable @code{dired-listing-switches} is a string
1588 used as an argument to @code{ls} in making the directory; this string
1589 @i{must} contain @samp{-l}.
1590
1591 @findex dired-other-window
1592 @kindex C-x 4 d
1593   To display the Dired buffer in another window rather than in the selected
1594 window, use @kbd{C-x 4 d} (@code{dired-other-window)} instead of @kbd{C-x d}.
1595
1596 @node Dired Edit, Dired Deletion, Dired Enter, Dired
1597 @subsection Editing in Dired
1598
1599   Once the Dired buffer exists, you can switch freely between it and other
1600 Emacs buffers.  Whenever the Dired buffer is selected, certain special
1601 commands are provided that operate on files that are listed.  The Dired
1602 buffer is ``read-only'', and inserting text in it is not useful, so
1603 ordinary printing characters such as @kbd{d} and @kbd{x} are used for Dired
1604 commands.  Most Dired commands operate on the file described by the line
1605 that point is on.  Some commands perform operations immediately; others
1606 ``flag'' a file to be operated on later.
1607
1608   Most Dired commands that operate on the current line's file also treat a
1609 numeric argument as a repeat count, meaning to act on the files of the
1610 next few lines.  A negative argument means to operate on the files of the
1611 preceding lines, and leave point on the first of those lines.
1612
1613   All the usual Emacs cursor motion commands are available in Dired
1614 buffers.  Some special purpose commands are also provided.  The keys
1615 @kbd{C-n} and @kbd{C-p} are redefined so that they try to position
1616 the cursor at the beginning of the filename on the line, rather than
1617 at the beginning of the line.
1618
1619   For extra convenience, @key{SPC} and @kbd{n} in Dired are equivalent to
1620 @kbd{C-n}.  @kbd{p} is equivalent to @kbd{C-p}.  Moving by lines is done so
1621 often in Dired that it deserves to be easy to type.  @key{DEL} (move up and
1622 unflag) is often useful simply for moving up.@refill
1623
1624   The @kbd{g} command in Dired runs @code{revert-buffer} to reinitialize
1625 the buffer from the actual disk directory and show any changes made in the
1626 directory by programs other than Dired.  All deletion flags in the Dired
1627 buffer are lost when this is done.
1628
1629 @node Dired Deletion, Dired Immed, Dired Edit, Dired
1630 @subsection Deleting Files With Dired
1631
1632   The primary use of Dired is to flag files for deletion and then delete
1633 them.
1634
1635 @table @kbd
1636 @item d
1637 Flag this file for deletion.
1638 @item u
1639 Remove deletion-flag on this line.
1640 @item @key{DEL}
1641 Remove deletion-flag on previous line, moving point to that line.
1642 @item x
1643 Delete the files that are flagged for deletion.
1644 @item #
1645 Flag all auto-save files (files whose names start and end with @samp{#})
1646 for deletion (@pxref{Auto Save}).
1647 @item ~
1648 Flag all backup files (files whose names end with @samp{~}) for deletion
1649 (@pxref{Backup}).
1650 @item .@: @r{(Period)}
1651 Flag excess numeric backup files for deletion.  The oldest and newest
1652 few backup files of any one file are exempt; the middle ones are flagged.
1653 @end table
1654
1655   You can flag a file for deletion by moving to the line describing the
1656 file and typing @kbd{d} or @kbd{C-d}.  The deletion flag is visible as a
1657 @samp{D} at the beginning of the line.  Point is moved to the beginning of
1658 the next line, so that repeated @kbd{d} commands flag successive files.
1659
1660   The files are flagged for deletion rather than deleted immediately to
1661 avoid the danger of deleting a file accidentally.  Until you direct Dired
1662 to delete the flagged files, you can remove deletion flags using the
1663 commands @kbd{u} and @key{DEL}.  @kbd{u} works just like @kbd{d}, but
1664 removes flags rather than making flags.  @key{DEL} moves upward, removing
1665 flags; it is like @kbd{u} with numeric argument automatically negated.
1666
1667   To delete the flagged files, type @kbd{x}.  This command first displays a
1668 list of all the file names flagged for deletion, and requests confirmation
1669 with @kbd{yes}.  Once you confirm, all the flagged files are deleted, and their
1670 lines are deleted from the text of the Dired buffer.  The shortened Dired
1671 buffer remains selected.  If you answer @kbd{no} or quit with @kbd{C-g}, you
1672 return immediately to Dired, with the deletion flags still present and no
1673 files actually deleted.
1674
1675   The @kbd{#}, @kbd{~}, and @kbd{.} commands flag many files for
1676 deletion, based on their names.  These commands are useful precisely
1677 because they do not actually delete any files; you can remove the
1678 deletion flags from any flagged files that you really wish to keep.@refill
1679
1680   @kbd{#} flags for deletion all files that appear to have been made by
1681 auto-saving (that is, files whose names begin and end with @samp{#}).
1682 @kbd{~} flags for deletion all files that appear to have been made as
1683 backups for files that were edited (that is, files whose names end with
1684 @samp{~}).
1685
1686 @vindex dired-kept-versions
1687   @kbd{.} (Period) flags just some of the backup files for deletion: only
1688 numeric backups that are not among the oldest few nor the newest few
1689 backups of any one file.  Normally @code{dired-kept-versions} (not
1690 @code{kept-new-versions}; that applies only when saving) specifies the
1691 number of newest versions of each file to keep, and
1692 @code{kept-old-versions} specifies the number of oldest versions to keep.
1693 Period with a positive numeric argument, as in @kbd{C-u 3 .}, specifies the
1694 number of newest versions to keep, overriding @code{dired-kept-versions}.
1695 A negative numeric argument overrides @code{kept-old-versions}, using minus
1696 the value of the argument to specify the number of oldest versions of each
1697 file to keep.@refill
1698
1699 @node Dired Immed,  , Dired Deletion, Dired
1700 @subsection Immediate File Operations in Dired
1701
1702   Some file operations in Dired take place immediately when they are
1703 requested.
1704
1705 @table @kbd
1706 @item C
1707 Copies the file described on the current line.  You must supply a file name
1708 to copy to, using the minibuffer.
1709 @item f
1710 Visits the file described on the current line.  It is just like typing
1711 @kbd{C-x C-f} and supplying that file name.  If the file on this line is a
1712 subdirectory, @kbd{f} actually causes Dired to be invoked on that
1713 subdirectory.  @xref{Visiting}.
1714 @item o
1715 Like @kbd{f}, but uses another window to display the file's buffer.  The
1716 Dired buffer remains visible in the first window.  This is like using
1717 @kbd{C-x 4 C-f} to visit the file.  @xref{Windows}.
1718 @item R
1719 Renames the file described on the current line.  You must supply a file
1720 name to rename to, using the minibuffer.
1721 @item v
1722 Views the file described on this line using @kbd{M-x view-file}.  Viewing a
1723 file is like visiting it, but is slanted toward moving around in the file
1724 conveniently and does not allow changing the file.  @xref{Misc File
1725 Ops,View File}.  Viewing a file that is a directory runs Dired on that
1726 directory.@refill
1727 @end table
1728
1729 @node Misc File Ops,  , Dired, Files
1730 @section Miscellaneous File Operations
1731
1732   Emacs has commands for performing many other operations on files.
1733 All operate on one file; they do not accept wildcard file names.
1734
1735 @findex add-name-to-file
1736   You can use the command @kbd{M-x add-name-to-file} to add a name to an
1737 existing file without removing the old name.  The new name must belong
1738 on the file system that the file is on.
1739
1740 @findex append-to-file
1741   @kbd{M-x append-to-file} adds the text of the region to the end of the
1742 specified file.
1743
1744 @findex copy-file
1745 @cindex copying files
1746   @kbd{M-x copy-file} reads the file @var{old} and writes a new file
1747 named @var{new} with the same contents.  Confirmation is required if a
1748 file named @var{new} already exists, because copying overwrites the old
1749 contents of the file @var{new}.
1750
1751 @findex delete-file
1752 @cindex deletion (of files)
1753   @kbd{M-x delete-file} deletes a specified file, like the @code{rm}
1754 command in the shell.  If you are deleting many files in one directory, it
1755 may be more convenient to use Dired (@pxref{Dired}).
1756
1757 @findex insert-file
1758   @kbd{M-x insert-file} inserts a copy of the contents of a specified
1759 file into the current buffer at point, leaving point unchanged before the
1760 contents and the mark after them.  @xref{Mark}.
1761
1762 @findex make-symbolic-link
1763   @kbd{M-x make-symbolic-link} reads two file names @var{old} and
1764 @var{linkname}, and then creates a symbolic link named @var{linkname}
1765 and pointing at @var{old}.  Future attempts to open file
1766 @var{linkname} will then refer to the file named @var{old} at the time
1767 the opening is done, or will result in an error if the name @var{old} is
1768 not in use at that time.  Confirmation is required if you create the
1769 link while @var{linkname} is in use.  Note that not all systems support
1770 symbolic links.
1771
1772 @findex rename-file
1773   @kbd{M-x rename-file} reads two file names @var{old} and @var{new} using
1774 the minibuffer, then renames file @var{old} as @var{new}.  If a file named
1775 @var{new} already exists, you must confirm with @kbd{yes} or renaming is not
1776 done; this is because renaming causes the previous meaning of the
1777 name @var{new} to be lost.  If @var{old} and @var{new} are on different
1778 file systems, the file @var{old} is copied and deleted.
1779
1780 @findex view-file
1781 @cindex viewing
1782   @kbd{M-x view-file} allows you to scan or read a file by sequential
1783 screenfuls.  It reads a file name argument using the minibuffer.  After
1784 reading the file into an Emacs buffer, @code{view-file} reads and displays
1785 one windowful.  You can then type @key{SPC} to scroll forward one window,
1786 or @key{DEL} to scroll backward.  Various other commands are provided for
1787 moving around in the file, but none for changing it; type @kbd{C-h} while
1788 viewing a file for a list of them.  Most commands are the default Emacs
1789 cursor motion commands.  To exit from viewing, type @kbd{C-c}.