2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
[bpt/emacs.git] / man / files.texi
CommitLineData
6bf7aab6 1@c This is part of the Emacs manual.
259a88ca 2@c Copyright (C) 1985,86,87,93,94,95,97,99, 2000 Free Software Foundation, Inc.
6bf7aab6
DL
3@c See file emacs.texi for copying conditions.
4@node Files, Buffers, Fixit, Top
5@chapter File Handling
6@cindex files
7
8 The operating system stores data permanently in named @dfn{files}. So
9most of the text you edit with Emacs comes from a file and is ultimately
10stored in a file.
11
12 To edit a file, you must tell Emacs to read the file and prepare a
13buffer containing a copy of the file's text. This is called
14@dfn{visiting} the file. Editing commands apply directly to text in the
15buffer; that is, to the copy inside Emacs. Your changes appear in the
16file itself only when you @dfn{save} the buffer back into the file.
17
18 In addition to visiting and saving files, Emacs can delete, copy,
19rename, and append to files, keep multiple versions of them, and operate
20on file directories.
21
22@menu
23* File Names:: How to type and edit file-name arguments.
24* Visiting:: Visiting a file prepares Emacs to edit the file.
25* Saving:: Saving makes your changes permanent.
26* Reverting:: Reverting cancels all the changes not saved.
27* Auto Save:: Auto Save periodically protects against loss of data.
28* File Aliases:: Handling multiple names for one file.
29* Version Control:: Version control systems (RCS, CVS and SCCS).
30* Directories:: Creating, deleting, and listing file directories.
31* Comparing Files:: Finding where two files differ.
32* Misc File Ops:: Other things you can do on files.
33* Compressed Files:: Accessing compressed files.
259a88ca 34* File Archives:: Operating on tar, zip, jar etc. archive files.
6bf7aab6
DL
35* Remote Files:: Accessing files on other sites.
36* Quoted File Names:: Quoting special characters in file names.
37@end menu
38
39@node File Names
40@section File Names
41@cindex file names
42
43 Most Emacs commands that operate on a file require you to specify the
44file name. (Saving and reverting are exceptions; the buffer knows which
45file name to use for them.) You enter the file name using the
46minibuffer (@pxref{Minibuffer}). @dfn{Completion} is available, to make
47it easier to specify long file names. @xref{Completion}.
48
49 For most operations, there is a @dfn{default file name} which is used
50if you type just @key{RET} to enter an empty argument. Normally the
51default file name is the name of the file visited in the current buffer;
52this makes it easy to operate on that file with any of the Emacs file
53commands.
54
55@vindex default-directory
56 Each buffer has a default directory, normally the same as the
57directory of the file visited in that buffer. When you enter a file
58name without a directory, the default directory is used. If you specify
59a directory in a relative fashion, with a name that does not start with
60a slash, it is interpreted with respect to the default directory. The
61default directory is kept in the variable @code{default-directory},
62which has a separate value in every buffer.
63
64 For example, if the default file name is @file{/u/rms/gnu/gnu.tasks} then
65the default directory is @file{/u/rms/gnu/}. If you type just @samp{foo},
66which does not specify a directory, it is short for @file{/u/rms/gnu/foo}.
67@samp{../.login} would stand for @file{/u/rms/.login}. @samp{new/foo}
68would stand for the file name @file{/u/rms/gnu/new/foo}.
69
70@findex cd
71@findex pwd
72 The command @kbd{M-x pwd} prints the current buffer's default
73directory, and the command @kbd{M-x cd} sets it (to a value read using
74the minibuffer). A buffer's default directory changes only when the
75@code{cd} command is used. A file-visiting buffer's default directory
76is initialized to the directory of the file that is visited there. If
77you create a buffer with @kbd{C-x b}, its default directory is copied
78from that of the buffer that was current at the time.
79
80@vindex insert-default-directory
81 The default directory actually appears in the minibuffer when the
82minibuffer becomes active to read a file name. This serves two
83purposes: it @emph{shows} you what the default is, so that you can type
84a relative file name and know with certainty what it will mean, and it
85allows you to @emph{edit} the default to specify a different directory.
86This insertion of the default directory is inhibited if the variable
87@code{insert-default-directory} is set to @code{nil}.
88
89 Note that it is legitimate to type an absolute file name after you
90enter the minibuffer, ignoring the presence of the default directory
91name as part of the text. The final minibuffer contents may look
92invalid, but that is not so. For example, if the minibuffer starts out
93with @samp{/usr/tmp/} and you add @samp{/x1/rms/foo}, you get
94@samp{/usr/tmp//x1/rms/foo}; but Emacs ignores everything through the
95first slash in the double slash; the result is @samp{/x1/rms/foo}.
96@xref{Minibuffer File}.
97
98 @samp{$} in a file name is used to substitute environment variables.
99For example, if you have used the shell command @samp{export
100FOO=rms/hacks} to set up an environment variable named @code{FOO}, then
101you can use @file{/u/$FOO/test.c} or @file{/u/$@{FOO@}/test.c} as an
102abbreviation for @file{/u/rms/hacks/test.c}. The environment variable
103name consists of all the alphanumeric characters after the @samp{$};
104alternatively, it may be enclosed in braces after the @samp{$}. Note
105that shell commands to set environment variables affect Emacs only if
106done before Emacs is started.
107
108 To access a file with @samp{$} in its name, type @samp{$$}. This pair
109is converted to a single @samp{$} at the same time as variable
110substitution is performed for single @samp{$}. Alternatively, quote the
111whole file name with @samp{/:} (@pxref{Quoted File Names}).
112
113@findex substitute-in-file-name
114 The Lisp function that performs the substitution is called
115@code{substitute-in-file-name}. The substitution is performed only on
116file names read as such using the minibuffer.
117
118 You can include non-ASCII characters in file names if you set the
119variable @code{file-name-coding-system} to a non-@code{nil} value.
120@xref{Specify Coding}.
121
122@node Visiting
123@section Visiting Files
124@cindex visiting files
125
126@c WideCommands
127@table @kbd
128@item C-x C-f
129Visit a file (@code{find-file}).
130@item C-x C-r
131Visit a file for viewing, without allowing changes to it
132(@code{find-file-read-only}).
133@item C-x C-v
134Visit a different file instead of the one visited last
135(@code{find-alternate-file}).
136@item C-x 4 f
137Visit a file, in another window (@code{find-file-other-window}). Don't
138alter what is displayed in the selected window.
139@item C-x 5 f
140Visit a file, in a new frame (@code{find-file-other-frame}). Don't
141alter what is displayed in the selected frame.
142@item M-x find-file-literally
143Visit a file with no conversion of the contents.
144@end table
145
146@cindex files, visiting and saving
147@cindex visiting files
148@cindex saving files
149 @dfn{Visiting} a file means copying its contents into an Emacs buffer
150so you can edit them. Emacs makes a new buffer for each file that you
151visit. We say that this buffer is visiting the file that it was created
152to hold. Emacs constructs the buffer name from the file name by
153throwing away the directory, keeping just the name proper. For example,
154a file named @file{/usr/rms/emacs.tex} would get a buffer named
155@samp{emacs.tex}. If there is already a buffer with that name, a unique
156name is constructed by appending @samp{<2>}, @samp{<3>}, or so on, using
157the lowest number that makes a name that is not already in use.
158
159 Each window's mode line shows the name of the buffer that is being displayed
160in that window, so you can always tell what buffer you are editing.
161
162 The changes you make with editing commands are made in the Emacs
163buffer. They do not take effect in the file that you visited, or any
164place permanent, until you @dfn{save} the buffer. Saving the buffer
165means that Emacs writes the current contents of the buffer into its
166visited file. @xref{Saving}.
167
168@cindex modified (buffer)
169 If a buffer contains changes that have not been saved, we say the
170buffer is @dfn{modified}. This is important because it implies that
171some changes will be lost if the buffer is not saved. The mode line
172displays two stars near the left margin to indicate that the buffer is
173modified.
174
175@kindex C-x C-f
176@findex find-file
177 To visit a file, use the command @kbd{C-x C-f} (@code{find-file}). Follow
178the command with the name of the file you wish to visit, terminated by a
179@key{RET}.
180
181 The file name is read using the minibuffer (@pxref{Minibuffer}), with
182defaulting and completion in the standard manner (@pxref{File Names}).
183While in the minibuffer, you can abort @kbd{C-x C-f} by typing @kbd{C-g}.
184
185 Your confirmation that @kbd{C-x C-f} has completed successfully is the
186appearance of new text on the screen and a new buffer name in the mode
187line. If the specified file does not exist and could not be created, or
188cannot be read, then you get an error, with an error message displayed
189in the echo area.
190
191 If you visit a file that is already in Emacs, @kbd{C-x C-f} does not make
192another copy. It selects the existing buffer containing that file.
193However, before doing so, it checks that the file itself has not changed
194since you visited or saved it last. If the file has changed, a warning
195message is printed. @xref{Interlocking,,Simultaneous Editing}.
196
197@cindex creating files
198 What if you want to create a new file? Just visit it. Emacs prints
199@samp{(New File)} in the echo area, but in other respects behaves as if
200you had visited an existing empty file. If you make any changes and
201save them, the file is created.
202
203 Emacs recognizes from the contents of a file which convention it uses
204to separate lines---newline (used on GNU/Linux and on Unix),
205carriage-return linefeed (used on Microsoft systems), or just
206carriage-return (used on the Macintosh)---and automatically converts the
207contents to the normal Emacs convention, which is that the newline
208character separates lines. This is a part of the general feature of
209coding system conversion (@pxref{Coding Systems}), and makes it possible
210to edit files imported from various different operating systems with
211equal convenience. If you change the text and save the file, Emacs
212performs the inverse conversion, changing newlines back into
213carriage-return linefeed or just carriage-return if appropriate.
214
215@vindex find-file-run-dired
216 If the file you specify is actually a directory, @kbd{C-x C-f} invokes
217Dired, the Emacs directory browser, so that you can ``edit'' the contents
218of the directory (@pxref{Dired}). Dired is a convenient way to delete,
219look at, or operate on the files in the directory. However, if the
220variable @code{find-file-run-dired} is @code{nil}, then it is an error
221to try to visit a directory.
222
7ed32bd8
DL
223@cindex wildcard characters in file names
224@vindex find-file-wildcards
225 If the file name you specify contains @code{sh}-style wildcard
226characters, Emacs visits all the files that match it. @xref{Quoted File
227Names}, if you want to visit a file whose name actually contains
228wildcard characters. Wildcards comprise @samp{?}, @samp{*} and
229@samp{[@dots{}]} sequences. The wildcard feature can be disabled by
230customizing @code{find-file-wildcards}.
6bf7aab6
DL
231
232 If you visit a file that the operating system won't let you modify,
233Emacs makes the buffer read-only, so that you won't go ahead and make
234changes that you'll have trouble saving afterward. You can make the
235buffer writable with @kbd{C-x C-q} (@code{vc-toggle-read-only}).
236@xref{Misc Buffer}.
237
238@kindex C-x C-r
239@findex find-file-read-only
240 Occasionally you might want to visit a file as read-only in order to
241protect yourself from entering changes accidentally; do so by visiting
242the file with the command @kbd{C-x C-r} (@code{find-file-read-only}).
243
244@kindex C-x C-v
245@findex find-alternate-file
246 If you visit a nonexistent file unintentionally (because you typed the
247wrong file name), use the @kbd{C-x C-v} command
248(@code{find-alternate-file}) to visit the file you really wanted.
249@kbd{C-x C-v} is similar to @kbd{C-x C-f}, but it kills the current
250buffer (after first offering to save it if it is modified). When it
251reads the file name to visit, it inserts the entire default file name in
252the buffer, with point just after the directory part; this is convenient
253if you made a slight error in typing the name.
254
255 If you find a file which exists but cannot be read, @kbd{C-x C-f}
256signals an error.
257
258@kindex C-x 4 f
259@findex find-file-other-window
260 @kbd{C-x 4 f} (@code{find-file-other-window}) is like @kbd{C-x C-f}
261except that the buffer containing the specified file is selected in another
262window. The window that was selected before @kbd{C-x 4 f} continues to
263show the same buffer it was already showing. If this command is used when
264only one window is being displayed, that window is split in two, with one
265window showing the same buffer as before, and the other one showing the
266newly requested file. @xref{Windows}.
267
268@kindex C-x 5 f
269@findex find-file-other-frame
270 @kbd{C-x 5 f} (@code{find-file-other-frame}) is similar, but opens a
271new frame, or makes visible any existing frame showing the file you
272seek. This feature is available only when you are using a window
273system. @xref{Frames}.
274
275@findex find-file-literally
276 If you wish to edit a file as a sequence of characters with no special
277encoding or conversion, use the @kbd{M-x find-file-literally} command.
278It visits a file, like @kbd{C-x C-f}, but does not do format conversion
279(@pxref{Formatted Text}), character code conversion (@pxref{Coding
280Systems}), or automatic uncompression (@pxref{Compressed Files}).
281If you already have visited the same file in the usual (non-literal)
282manner, this command asks you whether to visit it literally instead.
283
284@vindex find-file-hooks
285@vindex find-file-not-found-hooks
286 Two special hook variables allow extensions to modify the operation of
287visiting files. Visiting a file that does not exist runs the functions
288in the list @code{find-file-not-found-hooks}; this variable holds a list
289of functions, and the functions are called one by one (with no
290arguments) until one of them returns non-@code{nil}. This is not a
291normal hook, and the name ends in @samp{-hooks} rather than @samp{-hook}
292to indicate that fact.
293
294 Any visiting of a file, whether extant or not, expects
295@code{find-file-hooks} to contain a list of functions, and calls them
296all, one by one, with no arguments. This variable is really a normal
297hook, but it has an abnormal name for historical compatibility. In the
298case of a nonexistent file, the @code{find-file-not-found-hooks} are run
299first. @xref{Hooks}.
300
301 There are several ways to specify automatically the major mode for
302editing the file (@pxref{Choosing Modes}), and to specify local
303variables defined for that file (@pxref{File Variables}).
304
305@node Saving
306@section Saving Files
307
308 @dfn{Saving} a buffer in Emacs means writing its contents back into the file
309that was visited in the buffer.
310
311@table @kbd
312@item C-x C-s
313Save the current buffer in its visited file (@code{save-buffer}).
314@item C-x s
315Save any or all buffers in their visited files (@code{save-some-buffers}).
316@item M-~
317Forget that the current buffer has been changed (@code{not-modified}).
318@item C-x C-w
319Save the current buffer in a specified file (@code{write-file}).
320@item M-x set-visited-file-name
321Change 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 When you wish to save the 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}
328displays a message like this:
329
330@example
331Wrote /u/rms/gnu/gnu.tasks
332@end example
333
334@noindent
335If the selected buffer is not modified (no changes have been made in it
336since the buffer was created or last saved), saving is not really done,
337because it would have no effect. Instead, @kbd{C-x C-s} displays a message
338like this in the echo area:
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}) offers to save any
347or all modified buffers. It asks you what to do with each buffer. The
348possible responses are analogous to those of @code{query-replace}:
349
350@table @kbd
351@item y
352Save this buffer and ask about the rest of the buffers.
353@item n
354Don't save this buffer, but ask about the rest of the buffers.
355@item !
356Save this buffer and all the rest with no more questions.
357@c following generates acceptable underfull hbox
358@item @key{RET}
359Terminate @code{save-some-buffers} without any more saving.
360@item .
361Save this buffer, then exit @code{save-some-buffers} without even asking
362about other buffers.
363@item C-r
364View the buffer that you are currently being asked about. When you exit
365View mode, you get back to @code{save-some-buffers}, which asks the
366question again.
367@item C-h
368Display a help message about these options.
369@end table
370
371 @kbd{C-x C-c}, the key sequence to exit Emacs, invokes
372@code{save-some-buffers} and therefore asks the same questions.
373
374@kindex M-~
375@findex not-modified
376 If you have changed a buffer but you do not want to save the changes,
377you should take some action to prevent it. Otherwise, each time you use
378@kbd{C-x s} or @kbd{C-x C-c}, you are liable to save this buffer by
379mistake. One thing you can do is type @kbd{M-~} (@code{not-modified}),
380which clears out the indication that the buffer is modified. If you do
381this, none of the save commands will believe that the buffer needs to be
382saved. (@samp{~} is often used as a mathematical symbol for `not'; thus
383@kbd{M-~} is `not', metafied.) You could also use
384@code{set-visited-file-name} (see below) to mark the buffer as visiting
385a different file name, one which is not in use for anything important.
386Alternatively, you can cancel all the changes made since the file was
387visited or saved, by reading the text from the file again. This is
388called @dfn{reverting}. @xref{Reverting}. You could also undo all the
389changes by repeating the undo command @kbd{C-x u} until you have undone
390all the changes; but reverting is easier.
391
392@findex set-visited-file-name
393 @kbd{M-x set-visited-file-name} alters the name of the file that the
394current buffer is visiting. It reads the new file name using the
395minibuffer. Then it specifies the visited file name and changes the
396buffer name correspondingly (as long as the new name is not in use).
397@code{set-visited-file-name} does not save the buffer in the newly
398visited file; it just alters the records inside Emacs in case you do
399save later. It also marks the buffer as ``modified'' so that @kbd{C-x
400C-s} in that buffer @emph{will} save.
401
402@kindex C-x C-w
403@findex write-file
404 If you wish to mark the buffer as visiting a different file and save it
405right away, use @kbd{C-x C-w} (@code{write-file}). It is precisely
406equivalent to @code{set-visited-file-name} followed by @kbd{C-x C-s}.
407@kbd{C-x C-s} used on a buffer that is not visiting a file has the
408same effect as @kbd{C-x C-w}; that is, it reads a file name, marks the
409buffer as visiting that file, and saves it there. The default file name in
410a buffer that is not visiting a file is made by combining the buffer name
411with the buffer's default directory.
412
413 If the new file name implies a major mode, then @kbd{C-x C-w} switches
414to that major mode, in most cases. The command
415@code{set-visited-file-name} also does this. @xref{Choosing Modes}.
416
417 If Emacs is about to save a file and sees that the date of the latest
418version on disk does not match what Emacs last read or wrote, Emacs
419notifies you of this fact, because it probably indicates a problem caused
420by simultaneous editing and requires your immediate attention.
421@xref{Interlocking,, Simultaneous Editing}.
422
423@vindex require-final-newline
424 If the variable @code{require-final-newline} is non-@code{nil}, Emacs
425puts a newline at the end of any file that doesn't already end in one,
426every time a file is saved or written. The default is @code{nil}.
427
428@menu
429* Backup:: How Emacs saves the old version of your file.
430* Interlocking:: How Emacs protects against simultaneous editing
431 of one file by two users.
432@end menu
433
434@node Backup
435@subsection Backup Files
436@cindex backup file
437@vindex make-backup-files
438@vindex vc-make-backup-files
439@vindex backup-enable-predicate
440
441 On most operating systems, rewriting a file automatically destroys all
442record of what the file used to contain. Thus, saving a file from Emacs
443throws away the old contents of the file---or it would, except that
444Emacs carefully copies the old contents to another file, called the
445@dfn{backup} file, before actually saving.
446
447 For most files, the variable @code{make-backup-files} determines
448whether to make backup files. On most operating systems, its default
449value is @code{t}, so that Emacs does write backup files.
450
451 For files managed by a version control system (@pxref{Version
452Control}), the variable @code{vc-make-backup-files} determines whether
453to make backup files. By default, it is @code{nil}, since backup files
454are redundant when you store all the previous versions in a version
455control system. @xref{VC Workfile Handling}.
456
457 The default value of the @code{backup-enable-predicate} variable
458prevents backup files being written for files in @file{/tmp}.
459
460 At your option, Emacs can keep either a single backup file or a series of
461numbered backup files for each file that you edit.
462
463 Emacs makes a backup for a file only the first time the file is saved
464from one buffer. No matter how many times you save a file, its backup file
465continues to contain the contents from before the file was visited.
466Normally this means that the backup file contains the contents from before
467the current editing session; however, if you kill the buffer and then visit
468the file again, a new backup file will be made by the next save.
469
470 You can also explicitly request making another backup file from a
471buffer even though it has already been saved at least once. If you save
472the buffer with @kbd{C-u C-x C-s}, the version thus saved will be made
473into a backup file if you save the buffer again. @kbd{C-u C-u C-x C-s}
474saves the buffer, but first makes the previous file contents into a new
475backup file. @kbd{C-u C-u C-u C-x C-s} does both things: it makes a
476backup from the previous contents, and arranges to make another from the
477newly saved contents, if you save again.
478
479@menu
480* Names: Backup Names. How backup files are named;
481 choosing single or numbered backup files.
482* Deletion: Backup Deletion. Emacs deletes excess numbered backups.
483* Copying: Backup Copying. Backups can be made by copying or renaming.
484@end menu
485
486@node Backup Names
487@subsubsection Single or Numbered Backups
488
489 If you choose to have a single backup file (this is the default),
490the backup file's name is constructed by appending @samp{~} to the
491file name being edited; thus, the backup file for @file{eval.c} would
492be @file{eval.c~}.
493
494 If you choose to have a series of numbered backup files, backup file
495names are made by appending @samp{.~}, the number, and another @samp{~} to
496the original file name. Thus, the backup files of @file{eval.c} would be
497called @file{eval.c.~1~}, @file{eval.c.~2~}, and so on, through names
498like @file{eval.c.~259~} and beyond.
499
500 If protection stops you from writing backup files under the usual names,
501the backup file is written as @file{%backup%~} in your home directory.
502Only one such file can exist, so only the most recently made such backup is
503available.
504
505@vindex version-control
506 The choice of single backup or numbered backups is controlled by the
507variable @code{version-control}. Its possible values are
508
509@table @code
510@item t
511Make numbered backups.
512@item nil
513Make numbered backups for files that have numbered backups already.
514Otherwise, make single backups.
515@item never
516Do not in any case make numbered backups; always make single backups.
517@end table
518
519@noindent
520You can set @code{version-control} locally in an individual buffer to
521control the making of backups for that buffer's file. For example,
522Rmail mode locally sets @code{version-control} to @code{never} to make sure
523that there is only one backup for an Rmail file. @xref{Locals}.
524
525@cindex @code{VERSION_CONTROL} environment variable
526 If you set the environment variable @code{VERSION_CONTROL}, to tell
527various GNU utilities what to do with backup files, Emacs also obeys the
528environment variable by setting the Lisp variable @code{version-control}
529accordingly at startup. If the environment variable's value is @samp{t}
530or @samp{numbered}, then @code{version-control} becomes @code{t}; if the
531value is @samp{nil} or @samp{existing}, then @code{version-control}
532becomes @code{nil}; if it is @samp{never} or @samp{simple}, then
533@code{version-control} becomes @code{never}.
534
535@node Backup Deletion
536@subsubsection Automatic Deletion of Backups
537
538 To prevent unlimited consumption of disk space, Emacs can delete numbered
539backup versions automatically. Generally Emacs keeps the first few backups
540and the latest few backups, deleting any in between. This happens every
541time a new backup is made.
542
543@vindex kept-old-versions
544@vindex kept-new-versions
545 The two variables @code{kept-old-versions} and
546@code{kept-new-versions} control this deletion. Their values are,
547respectively the number of oldest (lowest-numbered) backups to keep and
548the number of newest (highest-numbered) ones to keep, each time a new
549backup is made. Recall that these values are used just after a new
550backup version is made; that newly made backup is included in the count
551in @code{kept-new-versions}. By default, both variables are 2.
552
553@vindex delete-old-versions
554 If @code{delete-old-versions} is non-@code{nil}, the excess
555middle versions are deleted without a murmur. If it is @code{nil}, the
556default, then you are asked whether the excess middle versions should
557really be deleted.
558
559 Dired's @kbd{.} (Period) command can also be used to delete old versions.
560@xref{Dired Deletion}.
561
562@node Backup Copying
563@subsubsection Copying vs.@: Renaming
564
565 Backup files can be made by copying the old file or by renaming it. This
566makes a difference when the old file has multiple names. If the old file
567is renamed into the backup file, then the alternate names become names for
568the backup file. If the old file is copied instead, then the alternate
569names remain names for the file that you are editing, and the contents
570accessed by those names will be the new contents.
571
572 The method of making a backup file may also affect the file's owner
573and group. If copying is used, these do not change. If renaming is used,
574you become the file's owner, and the file's group becomes the default
575(different operating systems have different defaults for the group).
576
577 Having the owner change is usually a good idea, because then the owner
578always shows who last edited the file. Also, the owners of the backups
579show who produced those versions. Occasionally there is a file whose
580owner should not change; it is a good idea for such files to contain
581local variable lists to set @code{backup-by-copying-when-mismatch}
582locally (@pxref{File Variables}).
583
584@vindex backup-by-copying
585@vindex backup-by-copying-when-linked
586@vindex backup-by-copying-when-mismatch
587 The choice of renaming or copying is controlled by three variables.
588Renaming is the default choice. If the variable
589@code{backup-by-copying} is non-@code{nil}, copying is used. Otherwise,
590if the variable @code{backup-by-copying-when-linked} is non-@code{nil},
591then copying is used for files that have multiple names, but renaming
592may still be used when the file being edited has only one name. If the
593variable @code{backup-by-copying-when-mismatch} is non-@code{nil}, then
594copying is used if renaming would cause the file's owner or group to
595change. @code{backup-by-copying-when-mismatch} is @code{t} by default
596if you start Emacs as the superuser.
597
598 When a file is managed with a version control system (@pxref{Version
599Control}), Emacs does not normally make backups in the usual way for
600that file. But check-in and check-out are similar in some ways to
601making backups. One unfortunate similarity is that these operations
602typically break hard links, disconnecting the file name you visited from
603any alternate names for the same file. This has nothing to do with
604Emacs---the version control system does it.
605
606@node Interlocking
607@subsection Protection against Simultaneous Editing
608
609@cindex file dates
610@cindex simultaneous editing
611 Simultaneous editing occurs when two users visit the same file, both
612make changes, and then both save them. If nobody were informed that
613this was happening, whichever user saved first would later find that his
614changes were lost.
615
616 On some systems, Emacs notices immediately when the second user starts
617to change the file, and issues an immediate warning. On all systems,
618Emacs checks when you save the file, and warns if you are about to
619overwrite another user's changes. You can prevent loss of the other
620user's work by taking the proper corrective action instead of saving the
621file.
622
623@findex ask-user-about-lock
624@cindex locking files
625 When you make the first modification in an Emacs buffer that is
626visiting a file, Emacs records that the file is @dfn{locked} by you.
627(It does this by creating a symbolic link in the same directory with a
628different name.) Emacs removes the lock when you save the changes. The
629idea is that the file is locked whenever an Emacs buffer visiting it has
630unsaved changes.
631
632@cindex collision
633 If you begin to modify the buffer while the visited file is locked by
634someone else, this constitutes a @dfn{collision}. When Emacs detects a
635collision, it asks you what to do, by calling the Lisp function
636@code{ask-user-about-lock}. You can redefine this function for the sake
637of customization. The standard definition of this function asks you a
638question and accepts three possible answers:
639
640@table @kbd
641@item s
642Steal the lock. Whoever was already changing the file loses the lock,
643and you gain the lock.
644@item p
645Proceed. Go ahead and edit the file despite its being locked by someone else.
646@item q
647Quit. This causes an error (@code{file-locked}) and the modification you
648were trying to make in the buffer does not actually take place.
649@end table
650
651 Note that locking works on the basis of a file name; if a file has
652multiple names, Emacs does not realize that the two names are the same file
653and cannot prevent two users from editing it simultaneously under different
654names. However, basing locking on names means that Emacs can interlock the
655editing of new files that will not really exist until they are saved.
656
657 Some systems are not configured to allow Emacs to make locks, and
658there are cases where lock files cannot be written. In these cases,
659Emacs cannot detect trouble in advance, but it still can detect the
660collision when you try to save a file and overwrite someone else's
661changes.
662
663 If Emacs or the operating system crashes, this may leave behind lock
664files which are stale. So you may occasionally get warnings about
665spurious collisions. When you determine that the collision is spurious,
666just use @kbd{p} to tell Emacs to go ahead anyway.
667
668 Every time Emacs saves a buffer, it first checks the last-modification
669date of the existing file on disk to verify that it has not changed since the
670file was last visited or saved. If the date does not match, it implies
671that changes were made in the file in some other way, and these changes are
672about to be lost if Emacs actually does save. To prevent this, Emacs
673prints a warning message and asks for confirmation before saving.
674Occasionally you will know why the file was changed and know that it does
675not matter; then you can answer @kbd{yes} and proceed. Otherwise, you should
676cancel the save with @kbd{C-g} and investigate the situation.
677
678 The first thing you should do when notified that simultaneous editing
679has already taken place is to list the directory with @kbd{C-u C-x C-d}
680(@pxref{Directories}). This shows the file's current author. You
681should attempt to contact him to warn him not to continue editing.
682Often the next step is to save the contents of your Emacs buffer under a
683different name, and use @code{diff} to compare the two files.@refill
684
685@node Reverting
686@section Reverting a Buffer
687@findex revert-buffer
688@cindex drastic changes
689
690 If you have made extensive changes to a file and then change your mind
691about them, you can get rid of them by reading in the previous version
692of the file. To do this, use @kbd{M-x revert-buffer}, which operates on
693the current buffer. Since reverting a buffer unintentionally could lose
694a lot of work, you must confirm this command with @kbd{yes}.
695
696 @code{revert-buffer} keeps point at the same distance (measured in
697characters) from the beginning of the file. If the file was edited only
698slightly, you will be at approximately the same piece of text after
699reverting as before. If you have made drastic changes, the same value of
700point in the old file may address a totally different piece of text.
701
702 Reverting marks the buffer as ``not modified'' until another change is
703made.
704
705 Some kinds of buffers whose contents reflect data bases other than files,
706such as Dired buffers, can also be reverted. For them, reverting means
707recalculating their contents from the appropriate data base. Buffers
708created explicitly with @kbd{C-x b} cannot be reverted; @code{revert-buffer}
709reports an error when asked to do so.
710
711@vindex revert-without-query
712 When you edit a file that changes automatically and frequently---for
713example, a log of output from a process that continues to run---it may be
714useful for Emacs to revert the file without querying you, whenever you
715visit the file again with @kbd{C-x C-f}.
716
717 To request this behavior, set the variable @code{revert-without-query}
718to a list of regular expressions. When a file name matches one of these
719regular expressions, @code{find-file} and @code{revert-buffer} will
720revert it automatically if it has changed---provided the buffer itself
721is not modified. (If you have edited the text, it would be wrong to
722discard your changes.)
723
724@node Auto Save
725@section Auto-Saving: Protection Against Disasters
726@cindex Auto Save mode
727@cindex mode, Auto Save
728@cindex crashes
729
730 Emacs saves all the visited files from time to time (based on counting
731your keystrokes) without being asked. This is called @dfn{auto-saving}.
732It prevents you from losing more than a limited amount of work if the
733system crashes.
734
735 When Emacs determines that it is time for auto-saving, each buffer is
736considered, and is auto-saved if auto-saving is turned on for it and it
737has been changed since the last time it was auto-saved. The message
738@samp{Auto-saving...} is displayed in the echo area during auto-saving,
739if any files are actually auto-saved. Errors occurring during
740auto-saving are caught so that they do not interfere with the execution
741of commands you have been typing.
742
743@menu
744* Files: Auto Save Files. The file where auto-saved changes are
745 actually made until you save the file.
746* Control: Auto Save Control. Controlling when and how often to auto-save.
747* Recover:: Recovering text from auto-save files.
748@end menu
749
750@node Auto Save Files
751@subsection Auto-Save Files
752
753 Auto-saving does not normally save in the files that you visited, because
754it can be very undesirable to save a program that is in an inconsistent
755state when you have made half of a planned change. Instead, auto-saving
756is done in a different file called the @dfn{auto-save file}, and the
757visited file is changed only when you request saving explicitly (such as
758with @kbd{C-x C-s}).
759
760 Normally, the auto-save file name is made by appending @samp{#} to the
761front and rear of the visited file name. Thus, a buffer visiting file
762@file{foo.c} is auto-saved in a file @file{#foo.c#}. Most buffers that
763are not visiting files are auto-saved only if you request it explicitly;
764when they are auto-saved, the auto-save file name is made by appending
765@samp{#%} to the front and @samp{#} to the rear of buffer name. For
766example, the @samp{*mail*} buffer in which you compose messages to be
767sent is auto-saved in a file named @file{#%*mail*#}. Auto-save file
768names are made this way unless you reprogram parts of Emacs to do
769something different (the functions @code{make-auto-save-file-name} and
770@code{auto-save-file-name-p}). The file name to be used for auto-saving
771in a buffer is calculated when auto-saving is turned on in that buffer.
772
773 When you delete a substantial part of the text in a large buffer, auto
774save turns off temporarily in that buffer. This is because if you
775deleted the text unintentionally, you might find the auto-save file more
776useful if it contains the deleted text. To reenable auto-saving after
777this happens, save the buffer with @kbd{C-x C-s}, or use @kbd{C-u 1 M-x
778auto-save}.
779
780@vindex auto-save-visited-file-name
781 If you want auto-saving to be done in the visited file, set the variable
782@code{auto-save-visited-file-name} to be non-@code{nil}. In this mode,
783there is really no difference between auto-saving and explicit saving.
784
785@vindex delete-auto-save-files
786 A buffer's auto-save file is deleted when you save the buffer in its
787visited file. To inhibit this, set the variable @code{delete-auto-save-files}
788to @code{nil}. Changing the visited file name with @kbd{C-x C-w} or
789@code{set-visited-file-name} renames any auto-save file to go with
790the new visited name.
791
792@node Auto Save Control
793@subsection Controlling Auto-Saving
794
795@vindex auto-save-default
796@findex auto-save-mode
797 Each time you visit a file, auto-saving is turned on for that file's
798buffer if the variable @code{auto-save-default} is non-@code{nil} (but not
799in batch mode; @pxref{Entering Emacs}). The default for this variable is
800@code{t}, so auto-saving is the usual practice for file-visiting buffers.
801Auto-saving can be turned on or off for any existing buffer with the
802command @kbd{M-x auto-save-mode}. Like other minor mode commands, @kbd{M-x
803auto-save-mode} turns auto-saving on with a positive argument, off with a
804zero or negative argument; with no argument, it toggles.
805
806@vindex auto-save-interval
807 Emacs does auto-saving periodically based on counting how many characters
808you have typed since the last time auto-saving was done. The variable
809@code{auto-save-interval} specifies how many characters there are between
810auto-saves. By default, it is 300.
811
812@vindex auto-save-timeout
813 Auto-saving also takes place when you stop typing for a while. The
814variable @code{auto-save-timeout} says how many seconds Emacs should
815wait before it does an auto save (and perhaps also a garbage
816collection). (The actual time period is longer if the current buffer is
817long; this is a heuristic which aims to keep out of your way when you
818are editing long buffers, in which auto-save takes an appreciable amount
819of time.) Auto-saving during idle periods accomplishes two things:
820first, it makes sure all your work is saved if you go away from the
821terminal for a while; second, it may avoid some auto-saving while you
822are actually typing.
823
824 Emacs also does auto-saving whenever it gets a fatal error. This
825includes killing the Emacs job with a shell command such as @samp{kill
826%emacs}, or disconnecting a phone line or network connection.
827
828@findex do-auto-save
829 You can request an auto-save explicitly with the command @kbd{M-x
830do-auto-save}.
831
832@node Recover
833@subsection Recovering Data from Auto-Saves
834
835@findex recover-file
836 You can use the contents of an auto-save file to recover from a loss
837of data with the command @kbd{M-x recover-file @key{RET} @var{file}
838@key{RET}}. This visits @var{file} and then (after your confirmation)
839restores the contents from its auto-save file @file{#@var{file}#}.
840You can then save with @kbd{C-x C-s} to put the recovered text into
841@var{file} itself. For example, to recover file @file{foo.c} from its
842auto-save file @file{#foo.c#}, do:@refill
843
844@example
845M-x recover-file @key{RET} foo.c @key{RET}
846yes @key{RET}
847C-x C-s
848@end example
849
850 Before asking for confirmation, @kbd{M-x recover-file} displays a
851directory listing describing the specified file and the auto-save file,
852so you can compare their sizes and dates. If the auto-save file
853is older, @kbd{M-x recover-file} does not offer to read it.
854
855@findex recover-session
856 If Emacs or the computer crashes, you can recover all the files you
857were editing from their auto save files with the command @kbd{M-x
858recover-session}. This first shows you a list of recorded interrupted
859sessions. Move point to the one you choose, and type @kbd{C-c C-c}.
860
861 Then @code{recover-session} asks about each of the files that were
862being edited during that session, asking whether to recover that file.
863If you answer @kbd{y}, it calls @code{recover-file}, which works in its
864normal fashion. It shows the dates of the original file and its
865auto-save file, and asks once again whether to recover that file.
866
867 When @code{recover-session} is done, the files you've chosen to
868recover are present in Emacs buffers. You should then save them. Only
869this---saving them---updates the files themselves.
870
871@vindex auto-save-list-file-prefix
872 Interrupted sessions are recorded for later recovery in files named
873@file{~/.saves-@var{pid}-@var{hostname}}. The @samp{~/.saves} portion of
874these names comes from the value of @code{auto-save-list-file-prefix}.
875You can arrange to record sessions in a different place by setting that
876variable in your @file{.emacs} file, but you'll have to redefine
877@code{recover-session} as well to make it look in the new place. If you
878set @code{auto-save-list-file-prefix} to @code{nil} in your
879@file{.emacs} file, sessions are not recorded for recovery.
880
881@node File Aliases
882@section File Name Aliases
883
884 Symbolic links and hard links both make it possible for several file
885names to refer to the same file. Hard links are alternate names that
886refer directly to the file; all the names are equally valid, and no one
887of them is preferred. By contrast, a symbolic link is a kind of defined
888alias: when @file{foo} is a symbolic link to @file{bar}, you can use
889either name to refer to the file, but @file{bar} is the real name, while
890@file{foo} is just an alias. More complex cases occur when symbolic
891links point to directories.
892
893 If you visit two names for the same file, normally Emacs makes
894two different buffers, but it warns you about the situation.
895
896@vindex find-file-existing-other-name
897 If you wish to avoid visiting the same file in two buffers under
898different names, set the variable @code{find-file-existing-other-name}
899to a non-@code{nil} value. Then @code{find-file} uses the existing
900buffer visiting the file, no matter which of the file's names you
901specify.
902
903@vindex find-file-visit-truename
904@cindex truenames of files
905@cindex file truenames
906 If the variable @code{find-file-visit-truename} is non-@code{nil},
907then the file name recorded for a buffer is the file's @dfn{truename}
908(made by replacing all symbolic links with their target names), rather
909than the name you specify. Setting @code{find-file-visit-truename} also
910implies the effect of @code{find-file-existing-other-name}.
911
912@node Version Control
913@section Version Control
914@cindex version control
915
916 @dfn{Version control systems} are packages that can record multiple
917versions of a source file, usually storing the unchanged parts of the
918file just once. Version control systems also record history information
919such as the creation time of each version, who created it, and a
920description of what was changed in that version.
921
922 The Emacs version control interface is called VC. Its commands work
923with three version control systems---RCS, CVS and SCCS. The GNU project
924recommends RCS and CVS, which are free software and available from the
925Free Software Foundation.
926
927@menu
928* Introduction to VC:: How version control works in general.
929* VC Mode Line:: How the mode line shows version control status.
930* Basic VC Editing:: How to edit a file under version control.
931* Old Versions:: Examining and comparing old versions.
932* Secondary VC Commands:: The commands used a little less frequently.
933* Branches:: Multiple lines of development.
934* Snapshots:: Sets of file versions treated as a unit.
935* Miscellaneous VC:: Various other commands and features of VC.
936* Customizing VC:: Variables that change VC's behavior.
937@end menu
938
939@node Introduction to VC
940@subsection Introduction to Version Control
941
942 VC allows you to use a version control system from within Emacs,
943integrating the version control operations smoothly with editing. VC
944provides a uniform interface to version control, so that regardless of
945which version control system is in use, you can use it the same way.
946
947 This section provides a general overview of version control, and
948describes the version control systems that VC supports. You can skip
949this section if you are already familiar with the version control system
950you want to use.
951
952@menu
953* Version Systems:: Supported version control back-end systems.
954* VC Concepts:: Words and concepts related to version control.
955@end menu
956
957@node Version Systems
958@subsubsection Supported Version Control Systems
959
960@cindex RCS
961@cindex back end (version control)
962 VC currently works with three different version control systems or
963``back ends'': RCS, CVS, and SCCS.
964
965 RCS is a free version control system that is available from the Free
966Software Foundation. It is perhaps the most mature of the supported
967back ends, and the VC commands are conceptually closest to RCS. Almost
968everything you can do with RCS can be done through VC.
969
970@cindex CVS
971 CVS is built on top of RCS, and extends the features of RCS, allowing
972for more sophisticated release management, and concurrent multi-user
973development. VC supports basic editing operations under CVS, but for
974some less common tasks you still need to call CVS from the command line.
975Note also that before using CVS you must set up a repository, which is a
976subject too complex to treat here.
977
978@cindex SCCS
979 SCCS is a proprietary but widely used version control system. In
980terms of capabilities, it is the weakest of the three that VC
981supports. VC compensates for certain features missing in SCCS
982(snapshots, for example) by implementing them itself, but some other VC
983features, such as multiple branches, are not available with SCCS. You
984should use SCCS only if for some reason you cannot use RCS.
985
986@node VC Concepts
987@subsubsection Concepts of Version Control
988
989@cindex master file
990@cindex registered file
991 When a file is under version control, we also say that it is
992@dfn{registered} in the version control system. Each registered file
993has a corresponding @dfn{master file} which represents the file's
994present state plus its change history---enough to reconstruct the
995current version or any earlier version. Usually the master file also
996records a @dfn{log entry} for each version, describing in words what was
997changed in that version.
998
999@cindex work file
1000@cindex checking out files
1001 The file that is maintained under version control is sometimes called
1002the @dfn{work file} corresponding to its master file. You edit the work
1003file and make changes in it, as you would with an ordinary file. (With
1004SCCS and RCS, you must @dfn{lock} the file before you start to edit it.)
1005After you are done with a set of changes, you @dfn{check the file in},
1006which records the changes in the master file, along with a log entry for
1007them.
1008
1009 With CVS, there are usually multiple work files corresponding to a
1010single master file---often each user has his own copy. It is also
1011possible to use RCS in this way, but this is not the usual way to use
1012RCS.
1013
1014@cindex locking and version control
1015 A version control system typically has some mechanism to coordinate
1016between users who want to change the same file. One method is
1017@dfn{locking} (analogous to the locking that Emacs uses to detect
1018simultaneous editing of a file, but distinct from it). The other method
1019is to merge your changes with other people's changes when you check them
1020in.
1021
1022 With version control locking, work files are normally read-only so
1023that you cannot change them. You ask the version control system to make
1024a work file writable for you by locking it; only one user can do
1025this at any given time. When you check in your changes, that unlocks
1026the file, making the work file read-only again. This allows other users
1027to lock the file to make further changes. SCCS always uses locking, and
1028RCS normally does.
1029
1030 The other alternative for RCS is to let each user modify the work file
1031at any time. In this mode, locking is not required, but it is
1032permitted; check-in is still the way to record a new version.
1033
1034 CVS normally allows each user to modify his own copy of the work file
1035at any time, but requires merging with changes from other users at
1036check-in time. However, CVS can also be set up to require locking.
1037(@pxref{Backend Options}).
1038
1039@node VC Mode Line
1040@subsection Version Control and the Mode Line
1041
1042 When you visit a file that is under version control, Emacs indicates
1043this on the mode line. For example, @samp{RCS-1.3} says that RCS is
1044used for that file, and the current version is 1.3.
1045
1046 The character between the back-end name and the version number
1047indicates the version control status of the file. @samp{-} means that
1048the work file is not locked (if locking is in use), or not modified (if
1049locking is not in use). @samp{:} indicates that the file is locked, or
1050that it is modified. If the file is locked by some other user (for
1051instance, @samp{jim}), that is displayed as @samp{RCS:jim:1.3}.
1052
1053@node Basic VC Editing
1054@subsection Basic Editing under Version Control
1055
1056 The principal VC command is an all-purpose command that performs
1057either locking or check-in, depending on the situation.
1058
1059@table @kbd
1060@item C-x C-q
1061@itemx C-x v v
1062Perform the next logical version control operation on this file.
1063@end table
1064
1065@findex vc-next-action
1066@findex vc-toggle-read-only
1067@kindex C-x v v
1068@kindex C-x C-q @r{(Version Control)}
1069 Strictly speaking, the command for this job is @code{vc-next-action},
1070bound to @kbd{C-x v v}. However, the normal meaning of @kbd{C-x C-q} is
1071to make a read-only buffer writable, or vice versa; we have extended it
1072to do the same job properly for files managed by version control, by
1073performing the appropriate version control operations. When you type
1074@kbd{C-x C-q} on a registered file, it acts like @kbd{C-x v v}.
1075
1076 The precise action of this command depends on the state of the file,
1077and whether the version control system uses locking or not. SCCS and
1078RCS normally use locking; CVS normally does not use locking.
1079
1080@menu
1081* VC with Locking:: RCS in its default mode, SCCS, and optionally CVS.
1082* Without Locking:: Without locking: default mode for CVS.
1083* Log Buffer:: Features available in log entry buffers.
1084@end menu
1085
1086@node VC with Locking
1087@subsubsection Basic Version Control with Locking
1088
1089 If locking is used for the file (as with SCCS, and RCS in its default
1090mode), @kbd{C-x C-q} can either lock a file or check it in:
1091
1092@itemize @bullet
1093@item
1094If the file is not locked, @kbd{C-x C-q} locks it, and
1095makes it writable so that you can change it.
1096
1097@item
1098If the file is locked by you, and contains changes, @kbd{C-x C-q} checks
1099in the changes. In order to do this, it first reads the log entry
1100for the new version. @xref{Log Buffer}.
1101
1102@item
1103If the file is locked by you, but you have not changed it since you
1104locked it, @kbd{C-x C-q} releases the lock and makes the file read-only
1105again.
1106
1107@item
1108If the file is locked by some other user, @kbd{C-x C-q} asks you whether
1109you want to ``steal the lock'' from that user. If you say yes, the file
1110becomes locked by you, but a message is sent to the person who had
1111formerly locked the file, to inform him of what has happened.
1112@end itemize
1113
1114 These rules also apply when you use CVS in locking mode, except
1115that there is no such thing as stealing a lock.
1116
1117@node Without Locking
1118@subsubsection Basic Version Control without Locking
1119
1120 When there is no locking---the default for CVS---work files are always
1121writable; you do not need to do anything before you begin to edit a
1122file. The status indicator on the mode line is @samp{-} if the file is
1123unmodified; it flips to @samp{:} as soon as you save any changes in the
1124work file.
1125
1126 Here is what @kbd{C-x C-q} does when using CVS:
1127
1128@itemize @bullet
1129@item
1130If some other user has checked in changes into the master file,
1131Emacs asks you whether you want to merge those changes into your own
1132work file (@pxref{Merging}). You must do this before you can check in
1133your own changes.
1134
1135@item
1136If there are no new changes in the master file, but you have made
1137modifications in your work file, @kbd{C-x C-q} checks in your changes.
1138In order to do this, it first reads the log entry for the new version.
1139@xref{Log Buffer}.
1140
1141@item
1142If the file is not modified, the @kbd{C-x C-q} does nothing.
1143@end itemize
1144
1145 These rules also apply when you use RCS in the mode that does not
1146require locking, except that automatic merging of changes from the
1147master file is not implemented. Unfortunately, this means that nothing
1148informs you if another user has checked in changes in the same file
1149since you began editing it, and when this happens, his changes will be
1150effectively removed when you check in your version (though they will
1151remain in the master file, so they will not be entirely lost). You must
1152therefore verify the current version is unchanged, before you check in your
1153changes. We hope to eliminate this risk and provide automatic merging
1154with RCS in a future Emacs version.
1155
1156 In addition, locking is possible with RCS even in this mode, although
1157it is not required; @kbd{C-x C-q} with an unmodified file locks the
1158file, just as it does with RCS in its normal (locking) mode.
1159
1160@node Log Buffer
1161@subsubsection Features of the Log Entry Buffer
1162
1163 When you check in changes, @kbd{C-x C-q} first reads a log entry. It
1164pops up a buffer called @samp{*VC-Log*} for you to enter the log entry.
1165When you are finished, type @kbd{C-c C-c} in the @samp{*VC-Log*} buffer.
1166That is when check-in really happens.
1167
1168 To abort check-in, just @strong{don't} type @kbd{C-c C-c} in that
1169buffer. You can switch buffers and do other editing. As long as you
1170don't try to check in another file, the entry you were editing remains
1171in the @samp{*VC-Log*} buffer, and you can go back to that buffer at any
1172time to complete the check-in.
1173
1174 If you change several source files for the same reason, it is often
1175convenient to specify the same log entry for many of the files. To do
1176this, use the history of previous log entries. The commands @kbd{M-n},
1177@kbd{M-p}, @kbd{M-s} and @kbd{M-r} for doing this work just like the
1178minibuffer history commands (except that these versions are used outside
1179the minibuffer).
1180
1181@vindex vc-log-mode-hook
1182 Each time you check in a file, the log entry buffer is put into VC Log
1183mode, which involves running two hooks: @code{text-mode-hook} and
1184@code{vc-log-mode-hook}. @xref{Hooks}.
1185
1186@node Old Versions
1187@subsection Examining And Comparing Old Versions
1188
1189 One of the convenient features of version control is the ability
1190to examine any version of a file, or compare two versions.
1191
1192@table @kbd
1193@item C-x v ~ @var{version} @key{RET}
1194Examine version @var{version} of the visited file, in a buffer of its
1195own.
1196
1197@item C-x v =
1198Compare the current buffer contents with the latest checked-in version
1199of the file.
1200
1201@item C-u C-x v = @var{file} @key{RET} @var{oldvers} @key{RET} @var{newvers} @key{RET}
1202Compare the specified two versions of @var{file}.
1203
1204@item C-x v g
1205Display the result of the CVS annotate command using colors.
1206@end table
1207
1208@findex vc-version-other-window
1209@kindex C-x v ~
1210 To examine an old version in toto, visit the file and then type
1211@kbd{C-x v ~ @var{version} @key{RET}} (@code{vc-version-other-window}).
1212This puts the text of version @var{version} in a file named
1213@file{@var{filename}.~@var{version}~}, and visits it in its own buffer
1214in a separate window. (In RCS, you can also select an old version
1215and create a branch from it. @xref{Branches}.)
1216
1217@findex vc-diff
1218@kindex C-x v =
1219 But usually it is more convenient to compare two versions of the file,
1220with the command @kbd{C-x v =} (@code{vc-diff}). Plain @kbd{C-x v =}
1221compares the current buffer contents (saving them in the file if
1222necessary) with the last checked-in version of the file. @kbd{C-u C-x v
1223=}, with a numeric argument, reads a file name and two version numbers,
1224then compares those versions of the specified file.
1225
1226 If you supply a directory name instead of the name of a registered
1227file, this command compares the two specified versions of all registered
1228files in that directory and its subdirectories.
1229
1230 You can specify a checked-in version by its number; an empty input
1231specifies the current contents of the work file (which may be different
1232from all the checked-in versions). You can also specify a snapshot name
1233(@pxref{Snapshots}) instead of one or both version numbers.
1234
1235 This command works by running the @code{diff} utility, getting the
1236options from the variable @code{diff-switches}. It displays the output
1237in a special buffer in another window. Unlike the @kbd{M-x diff}
1238command, @kbd{C-x v =} does not try to locate the changes in the old and
1239new versions. This is because normally one or both versions do not
1240exist as files when you compare them; they exist only in the records of
1241the master file. @xref{Comparing Files}, for more information about
1242@kbd{M-x diff}.
1243
1244@findex vc-annotate
1245@kindex C-x v g
1246 For CVS-controlled files, you can display the result of the CVS
1247annotate command, using colors to enhance the visual appearance. Use
1248the command @kbd{M-x vc-annotate} to do this. Red means new, blue means
1249old, and intermediate colors indicate intermediate ages. A prefix
1250argument @var{n} specifies a stretch factor for the time scale; it makes
1251each color cover a period @var{n} times as long.
1252
1253@node Secondary VC Commands
1254@subsection The Secondary Commands of VC
1255
1256 This section explains the secondary commands of VC; those that you might
1257use once a day.
1258
1259@menu
1260* Registering:: Putting a file under version control.
1261* VC Status:: Viewing the VC status of files.
1262* VC Undo:: Cancelling changes before or after check-in.
1263* VC Dired Mode:: Listing files managed by version control.
1264* VC Dired Commands:: Commands to use in a VC Dired buffer.
1265@end menu
1266
1267@node Registering
1268@subsubsection Registering a File for Version Control
1269
1270@kindex C-x v i
1271@findex vc-register
1272 You can put any file under version control by simply visiting it, and
1273then typing @w{@kbd{C-x v i}} (@code{vc-register}).
1274
1275@table @kbd
1276@item C-x v i
1277Register the visited file for version control.
1278@end table
1279
1280@vindex vc-default-back-end
1281 To register the file, Emacs must choose which version control system
1282to use for it. You can specify your choice explicitly by setting
1283@code{vc-default-back-end} to @code{RCS}, @code{CVS} or @code{SCCS}.
1284Otherwise, if there is a subdirectory named @file{RCS}, @file{SCCS}, or
1285@file{CVS}, Emacs uses the corresponding version control system. In the
1286absence of any specification, the default choice is RCS if RCS is
1287installed, otherwise SCCS.
1288
1289 If locking is in use, @kbd{C-x v i} leaves the file unlocked and
1290read-only. Type @kbd{C-x C-q} if you wish to start editing it. After
1291registering a file with CVS, you must subsequently commit the initial
1292version by typing @kbd{C-x C-q}.
1293
1294@vindex vc-default-init-version
1295 The initial version number for a newly registered file is 1.1, by
1296default. You can specify a different default by setting the variable
1297@code{vc-default-init-version}, or you can give @kbd{C-x v i} a numeric
1298argument; then it reads the initial version number for this particular
1299file using the minibuffer.
1300
1301@vindex vc-initial-comment
1302 If @code{vc-initial-comment} is non-@code{nil}, @kbd{C-x v i} reads an
1303initial comment to describe the purpose of this source file. Reading
1304the initial comment works like reading a log entry (@pxref{Log Buffer}).
1305
1306@node VC Status
1307@subsubsection VC Status Commands
1308
1309@table @kbd
1310@item C-x v l
1311Display version control state and change history.
1312@end table
1313
1314@kindex C-x v l
1315@findex vc-print-log
1316 To view the detailed version control status and history of a file,
1317type @kbd{C-x v l} (@code{vc-print-log}). It displays the history of
1318changes to the current file, including the text of the log entries. The
1319output appears in a separate window.
1320
1321@node VC Undo
1322@subsubsection Undoing Version Control Actions
1323
1324@table @kbd
1325@item C-x v u
1326Revert the buffer and the file to the last checked-in version.
1327
1328@item C-x v c
1329Remove the last-entered change from the master for the visited file.
1330This undoes your last check-in.
1331@end table
1332
1333@kindex C-x v u
1334@findex vc-revert-buffer
1335 If you want to discard your current set of changes and revert to the
1336last version checked in, use @kbd{C-x v u} (@code{vc-revert-buffer}).
1337This leaves the file unlocked; if locking is in use, you must first lock
1338the file again before you change it again. @kbd{C-x v u} requires
1339confirmation, unless it sees that you haven't made any changes since the
1340last checked-in version.
1341
1342 @kbd{C-x v u} is also the command to unlock a file if you lock it and
1343then decide not to change it.
1344
1345@kindex C-x v c
1346@findex vc-cancel-version
1347 To cancel a change that you already checked in, use @kbd{C-x v c}
1348(@code{vc-cancel-version}). This command discards all record of the
1349most recent checked-in version. @kbd{C-x v c} also offers to revert
1350your work file and buffer to the previous version (the one that precedes
1351the version that is deleted).
1352
1353 If you answer @kbd{no}, VC keeps your changes in the buffer, and locks
1354the file. The no-revert option is useful when you have checked in a
1355change and then discover a trivial error in it; you can cancel the
1356erroneous check-in, fix the error, and check the file in again.
1357
1358 When @kbd{C-x v c} does not revert the buffer, it unexpands all
1359version control headers in the buffer instead (@pxref{Version Headers}).
1360This is because the buffer no longer corresponds to any existing
1361version. If you check it in again, the check-in process will expand the
1362headers properly for the new version number.
1363
1364 However, it is impossible to unexpand the RCS @samp{@w{$}Log$} header
1365automatically. If you use that header feature, you have to unexpand it
1366by hand---by deleting the entry for the version that you just canceled.
1367
1368 Be careful when invoking @kbd{C-x v c}, as it is easy to lose a lot of
1369work with it. To help you be careful, this command always requires
1370confirmation with @kbd{yes}. Note also that this command is disabled
1371under CVS, because canceling versions is very dangerous and discouraged
1372with CVS.
1373
1374@node VC Dired Mode
1375@subsubsection Dired under VC
1376
1377@kindex C-x v d
1378@findex vc-directory
1379 When you are working on a large program, it is often useful to find
1380out which files have changed within an entire directory tree, or to view
1381the status of all files under version control at once, and to perform
1382version control operations on collections of files. You can use the
1383command @kbd{C-x v d} (@code{vc-directory}) to make a directory listing
1384that includes only files relevant for version control.
1385
1386@vindex vc-dired-terse-display
1387 @kbd{C-x v d} creates a buffer which uses VC Dired Mode. This looks
1388much like an ordinary Dired buffer (@pxref{Dired}); however, normally it
1389shows only the noteworthy files (those locked or not up-to-date). This
1390is called @dfn{terse display}. If you set the variable
1391@code{vc-dired-terse-display} to @code{nil}, then VC Dired shows all
1392relevant files---those managed under version control, plus all
1393subdirectories (@dfn{full display}). The command @kbd{v t} in a VC
1394Dired buffer toggles between terse display and full display (@pxref{VC
1395Dired Commands}).
1396
1397@vindex vc-dired-recurse
1398 By default, VC Dired produces a recursive listing of noteworthy or
1399relevant files at or below the given directory. You can change this by
1400setting the variable @code{vc-dired-recurse} to @code{nil}; then VC
1401Dired shows only the files in the given directory.
1402
1403 The line for an individual file shows the version control state in the
1404place of the hard link count, owner, group, and size of the file. If
1405the file is unmodified, in sync with the master file, the version
1406control state shown is blank. Otherwise it consists of text in
1407parentheses. Under RCS and SCCS, the name of the user locking the file
1408is shown; under CVS, an abbreviated version of the @samp{cvs status}
1409output is used. Here is an example using RCS:
1410
1411@smallexample
1412@group
1413 /home/jim/project:
1414
1415 -rw-r--r-- (jim) Apr 2 23:39 file1
1416 -r--r--r-- Apr 5 20:21 file2
1417@end group
1418@end smallexample
1419
1420@noindent
1421The files @samp{file1} and @samp{file2} are under version control,
1422@samp{file1} is locked by user jim, and @samp{file2} is unlocked.
1423
1424 Here is an example using CVS:
1425
1426@smallexample
1427@group
1428 /home/joe/develop:
1429
1430 -rw-r--r-- (modified) Aug 2 1997 file1.c
1431 -rw-r--r-- Apr 4 20:09 file2.c
1432 -rw-r--r-- (merge) Sep 13 1996 file3.c
1433@end group
1434@end smallexample
1435
1436 Here @samp{file1.c} is modified with respect to the repository, and
1437@samp{file2.c} is not. @samp{file3.c} is modified, but other changes
1438have also been checked in to the repository---you need to merge them
1439with the work file before you can check it in.
1440
1441@vindex vc-directory-exclusion-list
1442 When VC Dired displays subdirectories (in the ``full'' display mode),
1443it omits some that should never contain any files under version control.
1444By default, this includes Version Control subdirectories such as
1445@samp{RCS} and @samp{CVS}; you can customize this by setting the
1446variable @code{vc-directory-exclusion-list}.
1447
1448 You can fine-tune VC Dired's format by typing @kbd{C-u C-x v d}---as in
1449ordinary Dired, that allows you to specify additional switches for the
1450@samp{ls} command.
1451
1452@node VC Dired Commands
1453@subsubsection VC Dired Commands
1454
1455 All the usual Dired commands work normally in VC Dired mode, except
1456for @kbd{v}, which is redefined as the version control prefix. You can
1457invoke VC commands such as @code{vc-diff} and @code{vc-print-log} by
1458typing @kbd{v =}, or @kbd{v l}, and so on. Most of these commands apply
1459to the file name on the current line.
1460
1461 The command @kbd{v v} (@code{vc-next-action}) operates on all the
1462marked files, so that you can lock or check in several files at once.
1463If it operates on more than one file, it handles each file according to
1464its current state; thus, it might lock one file, but check in another
1465file. This could be confusing; it is up to you to avoid confusing
1466behavior by marking a set of files that are in a similar state.
1467
1468 If any files call for check-in, @kbd{v v} reads a single log entry,
1469then uses it for all the files being checked in. This is convenient for
1470registering or checking in several files at once, as part of the same
1471change.
1472
1473@findex vc-dired-toggle-terse-mode
1474@findex vc-dired-mark-locked
1475 You can toggle between terse display (only locked files, or files not
1476up-to-date) and full display at any time by typing @kbd{v t}
1477@code{vc-dired-toggle-terse-mode}. There is also a special command
1478@kbd{* l} (@code{vc-dired-mark-locked}), which marks all files currently
1479locked (or, with CVS, all files not up-to-date). Thus, typing @kbd{* l
1480t k} is another way to delete from the buffer all files except those
1481currently locked.
1482
1483@node Branches
1484@subsection Multiple Branches of a File
1485@cindex branch (version control)
1486@cindex trunk (version control)
1487
1488 One use of version control is to maintain multiple ``current''
1489versions of a file. For example, you might have different versions of a
1490program in which you are gradually adding various unfinished new
1491features. Each such independent line of development is called a
1492@dfn{branch}. VC allows you to create branches, switch between
1493different branches, and merge changes from one branch to another.
1494Please note, however, that branches are only supported for RCS at the
1495moment.
1496
1497 A file's main line of development is usually called the @dfn{trunk}.
1498The versions on the trunk are normally numbered 1.1, 1.2, 1.3, etc. At
1499any such version, you can start an independent branch. A branch
1500starting at version 1.2 would have version number 1.2.1.1, and consecutive
1501versions on this branch would have numbers 1.2.1.2, 1.2.1.3, 1.2.1.4,
1502and so on. If there is a second branch also starting at version 1.2, it
1503would consist of versions 1.2.2.1, 1.2.2.2, 1.2.2.3, etc.
1504
1505@cindex head version
1506 If you omit the final component of a version number, that is called a
1507@dfn{branch number}. It refers to the highest existing version on that
1508branch---the @dfn{head version} of that branch. The branches in the
1509example above have branch numbers 1.2.1 and 1.2.2.
1510
1511@menu
1512* Switching Branches:: How to get to another existing branch.
1513* Creating Branches:: How to start a new branch.
1514* Merging:: Transferring changes between branches.
1515* Multi-User Branching:: Multiple users working at multiple branches
1516 in parallel.
1517@end menu
1518
1519@node Switching Branches
1520@subsubsection Switching between Branches
1521
1522 To switch between branches, type @kbd{C-u C-x C-q} and specify the
1523version number you want to select. This version is then visited
1524@emph{unlocked} (write-protected), so you can examine it before locking
1525it. Switching branches in this way is allowed only when the file is not
1526locked.
1527
1528 You can omit the minor version number, thus giving only the branch
1529number; this takes you to the head version on the chosen branch. If you
1530only type @key{RET}, Emacs goes to the highest version on the trunk.
1531
1532 After you have switched to any branch (including the main branch), you
1533stay on it for subsequent VC commands, until you explicitly select some
1534other branch.
1535
1536@node Creating Branches
1537@subsubsection Creating New Branches
1538
1539 To create a new branch from a head version (one that is the latest in
1540the branch that contains it), first select that version if necessary,
1541lock it with @kbd{C-x C-q}, and make whatever changes you want. Then,
1542when you check in the changes, use @kbd{C-u C-x C-q}. This lets you
1543specify the version number for the new version. You should specify a
1544suitable branch number for a branch starting at the current version.
1545For example, if the current version is 2.5, the branch number should be
15462.5.1, 2.5.2, and so on, depending on the number of existing branches at
1547that point.
1548
1549 To create a new branch at an older version (one that is no longer the
1550head of a branch), first select that version (@pxref{Switching
1551Branches}), then lock it with @kbd{C-x C-q}. You'll be asked to
1552confirm, when you lock the old version, that you really mean to create a
1553new branch---if you say no, you'll be offered a chance to lock the
1554latest version instead.
1555
1556 Then make your changes and type @kbd{C-x C-q} again to check in a new
1557version. This automatically creates a new branch starting from the
1558selected version. You need not specially request a new branch, because
1559that's the only way to add a new version at a point that is not the head
1560of a branch.
1561
1562 After the branch is created, you ``stay'' on it. That means that
1563subsequent check-ins create new versions on that branch. To leave the
1564branch, you must explicitly select a different version with @kbd{C-u C-x
1565C-q}. To transfer changes from one branch to another, use the merge
1566command, described in the next section.
1567
1568@node Merging
1569@subsubsection Merging Branches
1570
1571@cindex merging changes
1572 When you have finished the changes on a certain branch, you will
1573often want to incorporate them into the file's main line of development
1574(the trunk). This is not a trivial operation, because development might
1575also have proceeded on the trunk, so that you must @dfn{merge} the
1576changes into a file that has already been changed otherwise. VC allows
1577you to do this (and other things) with the @code{vc-merge} command.
1578
1579@table @kbd
1580@item C-x v m (vc-merge)
1581Merge changes into the work file.
1582@end table
1583
1584@kindex C-x v m
1585@findex vc-merge
1586 @kbd{C-x v m} (@code{vc-merge}) takes a set of changes and merges it
1587into the current version of the work file. It first asks you for a
1588branch number or a pair of version numbers in the minibuffer. Then it
1589finds the changes from that branch, or between the two versions you
1590specified, and merges them into the current version of the current file.
1591
1592 As an example, suppose that you have finished a certain feature on
1593branch 1.3.1. In the meantime, development on the trunk has proceeded
1594to version 1.5. To merge the changes from the branch to the trunk,
1595first go to the head version of the trunk, by typing @kbd{C-u C-x C-q
1596RET}. Version 1.5 is now current. If locking is used for the file,
1597type @kbd{C-x C-q} to lock version 1.5 so that you can change it. Next,
1598type @kbd{C-x v m 1.3.1 RET}. This takes the entire set of changes on
1599branch 1.3.1 (relative to version 1.3, where the branch started, up to
1600the last version on the branch) and merges it into the current version
1601of the work file. You can now check in the changed file, thus creating
1602version 1.6 containing the changes from the branch.
1603
1604 It is possible to do further editing after merging the branch, before
1605the next check-in. But it is usually wiser to check in the merged
1606version, then lock it and make the further changes. This will keep
1607a better record of the history of changes.
1608
1609@cindex conflicts
1610@cindex resolving conflicts
1611 When you merge changes into a file that has itself been modified, the
1612changes might overlap. We call this situation a @dfn{conflict}, and
1613reconciling the conflicting changes is called @dfn{resolving a
1614conflict}.
1615
1616 Whenever conflicts occur during merging, VC detects them, tells you
1617about them in the echo area, and asks whether you want help in merging.
1618If you say yes, it starts an Ediff session (@pxref{Top,
1619Ediff, Ediff, ediff, The Ediff Manual}).
1620
1621 If you say no, the conflicting changes are both inserted into the
1622file, surrounded by @dfn{conflict markers}. The example below shows how
1623a conflict region looks; the file is called @samp{name} and the current
1624master file version with user B's changes in it is 1.11.
1625
1626@c @w here is so CVS won't think this is a conflict.
1627@smallexample
1628@group
1629@w{<}<<<<<< name
1630 @var{User A's version}
1631=======
1632 @var{User B's version}
1633@w{>}>>>>>> 1.11
1634@end group
1635@end smallexample
1636
1637@cindex vc-resolve-conflicts
1638 Then you can resolve the conflicts by editing the file manually. Or
1639you can type @code{M-x vc-resolve-conflicts} after visiting the file.
1640This starts an Ediff session, as described above.
1641
1642@node Multi-User Branching
1643@subsubsection Multi-User Branching
1644
1645 It is often useful for multiple developers to work simultaneously on
1646different branches of a file. CVS allows this by default; for RCS, it
1647is possible if you create multiple source directories. Each source
1648directory should have a link named @file{RCS} which points to a common
1649directory of RCS master files. Then each source directory can have its
1650own choice of selected versions, but all share the same common RCS
1651records.
1652
1653 This technique works reliably and automatically, provided that the
1654source files contain RCS version headers (@pxref{Version Headers}). The
1655headers enable Emacs to be sure, at all times, which version number is
1656present in the work file.
1657
1658 If the files do not have version headers, you must instead tell Emacs
1659explicitly in each session which branch you are working on. To do this,
1660first find the file, then type @kbd{C-u C-x C-q} and specify the correct
1661branch number. This ensures that Emacs knows which branch it is using
1662during this particular editing session.
1663
1664@node Snapshots
1665@subsection Snapshots
1666@cindex snapshots and version control
1667
1668 A @dfn{snapshot} is a named set of file versions (one for each
1669registered file) that you can treat as a unit. One important kind of
1670snapshot is a @dfn{release}, a (theoretically) stable version of the
1671system that is ready for distribution to users.
1672
1673@menu
1674* Making Snapshots:: The snapshot facilities.
1675* Snapshot Caveats:: Things to be careful of when using snapshots.
1676@end menu
1677
1678@node Making Snapshots
1679@subsubsection Making and Using Snapshots
1680
1681 There are two basic commands for snapshots; one makes a
1682snapshot with a given name, the other retrieves a named snapshot.
1683
1684@table @code
1685@kindex C-x v s
1686@findex vc-create-snapshot
1687@item C-x v s @var{name} @key{RET}
1688Define the last saved versions of every registered file in or under the
1689current directory as a snapshot named @var{name}
1690(@code{vc-create-snapshot}).
1691
1692@kindex C-x v r
1693@findex vc-retrieve-snapshot
1694@item C-x v r @var{name} @key{RET}
1695For all registered files at or below the current directory level, select
1696whatever versions correspond to the snapshot @var{name}
1697(@code{vc-retrieve-snapshot}).
1698
1699This command reports an error if any files are locked at or below the
1700current directory, without changing anything; this is to avoid
1701overwriting work in progress.
1702@end table
1703
1704 A snapshot uses a very small amount of resources---just enough to record
1705the list of file names and which version belongs to the snapshot. Thus,
1706you need not hesitate to create snapshots whenever they are useful.
1707
1708 You can give a snapshot name as an argument to @kbd{C-x v =} or
1709@kbd{C-x v ~} (@pxref{Old Versions}). Thus, you can use it to compare a
1710snapshot against the current files, or two snapshots against each other,
1711or a snapshot against a named version.
1712
1713@node Snapshot Caveats
1714@subsubsection Snapshot Caveats
1715
1716@cindex named configurations (RCS)
1717 VC's snapshot facilities are modeled on RCS's named-configuration
1718support. They use RCS's native facilities for this, so under VC
1719snapshots made using RCS are visible even when you bypass VC.
1720
1721@c worded verbosely to avoid overfull hbox.
1722 For SCCS, VC implements snapshots itself. The files it uses contain
1723name/file/version-number triples. These snapshots are visible only
1724through VC.
1725
1726 A snapshot is a set of checked-in versions. So make sure that all the
1727files are checked in and not locked when you make a snapshot.
1728
1729 File renaming and deletion can create some difficulties with snapshots.
1730This is not a VC-specific problem, but a general design issue in version
1731control systems that no one has solved very well yet.
1732
1733 If you rename a registered file, you need to rename its master along
1734with it (the command @code{vc-rename-file} does this automatically). If
1735you are using SCCS, you must also update the records of the snapshot, to
1736mention the file by its new name (@code{vc-rename-file} does this,
1737too). An old snapshot that refers to a master file that no longer
1738exists under the recorded name is invalid; VC can no longer retrieve
1739it. It would be beyond the scope of this manual to explain enough about
1740RCS and SCCS to explain how to update the snapshots by hand.
1741
1742 Using @code{vc-rename-file} makes the snapshot remain valid for
1743retrieval, but it does not solve all problems. For example, some of the
1744files in the program probably refer to others by name. At the very
1745least, the makefile probably mentions the file that you renamed. If you
1746retrieve an old snapshot, the renamed file is retrieved under its new
1747name, which is not the name that the makefile expects. So the program
1748won't really work as retrieved.
1749
1750@node Miscellaneous VC
1751@subsection Miscellaneous Commands and Features of VC
1752
1753 This section explains the less-frequently-used features of VC.
1754
1755@menu
1756* Change Logs and VC:: Generating a change log file from log entries.
1757* Renaming and VC:: A command to rename both the source and master
1758 file correctly.
1759* Version Headers:: Inserting version control headers into working files.
1760@end menu
1761
1762@node Change Logs and VC
1763@subsubsection Change Logs and VC
1764
1765 If you use RCS or CVS for a program and also maintain a change log
1766file for it (@pxref{Change Log}), you can generate change log entries
1767automatically from the version control log entries:
1768
1769@table @kbd
1770@item C-x v a
1771@kindex C-x v a
1772@findex vc-update-change-log
1773Visit the current directory's change log file and, for registered files
1774in that directory, create new entries for versions checked in since the
1775most recent entry in the change log file.
1776(@code{vc-update-change-log}).
1777
1778This command works with RCS or CVS only, not with SCCS.
1779
1780@item C-u C-x v a
1781As above, but only find entries for the current buffer's file.
1782
1783@item M-1 C-x v a
1784As above, but find entries for all the currently visited files that are
1785maintained with version control. This works only with RCS, and it puts
1786all entries in the log for the default directory, which may not be
1787appropriate.
1788@end table
1789
1790 For example, suppose the first line of @file{ChangeLog} is dated
17911999-04-10, and that the only check-in since then was by Nathaniel
1792Bowditch to @file{rcs2log} on 1999-05-22 with log text @samp{Ignore log
1793messages that start with `#'.}. Then @kbd{C-x v a} visits
1794@file{ChangeLog} and inserts text like this:
1795
1796@iftex
1797@medbreak
1798@end iftex
1799@smallexample
1800@group
18011999-05-22 Nathaniel Bowditch <nat@@apn.org>
1802
1803 * rcs2log: Ignore log messages that start with `#'.
1804@end group
1805@end smallexample
1806@iftex
1807@medbreak
1808@end iftex
1809
1810@noindent
1811You can then edit the new change log entry further as you wish.
1812
1813 Unfortunately, timestamps in ChangeLog files are only dates, so some
1814of the new change log entry may duplicate what's already in ChangeLog.
1815You will have to remove these duplicates by hand.
1816
1817 Normally, the log entry for file @file{foo} is displayed as @samp{*
1818foo: @var{text of log entry}}. The @samp{:} after @file{foo} is omitted
1819if the text of the log entry starts with @w{@samp{(@var{functionname}):
1820}}. For example, if the log entry for @file{vc.el} is
1821@samp{(vc-do-command): Check call-process status.}, then the text in
1822@file{ChangeLog} looks like this:
1823
1824@iftex
1825@medbreak
1826@end iftex
1827@smallexample
1828@group
18291999-05-06 Nathaniel Bowditch <nat@@apn.org>
1830
1831 * vc.el (vc-do-command): Check call-process status.
1832@end group
1833@end smallexample
1834@iftex
1835@medbreak
1836@end iftex
1837
1838 When @kbd{C-x v a} adds several change log entries at once, it groups
1839related log entries together if they all are checked in by the same
1840author at nearly the same time. If the log entries for several such
1841files all have the same text, it coalesces them into a single entry.
1842For example, suppose the most recent check-ins have the following log
1843entries:
1844
1845@flushleft
1846@bullet{} For @file{vc.texinfo}: @samp{Fix expansion typos.}
1847@bullet{} For @file{vc.el}: @samp{Don't call expand-file-name.}
1848@bullet{} For @file{vc-hooks.el}: @samp{Don't call expand-file-name.}
1849@end flushleft
1850
1851@noindent
1852They appear like this in @file{ChangeLog}:
1853
1854@iftex
1855@medbreak
1856@end iftex
1857@smallexample
1858@group
18591999-04-01 Nathaniel Bowditch <nat@@apn.org>
1860
1861 * vc.texinfo: Fix expansion typos.
1862
1863 * vc.el, vc-hooks.el: Don't call expand-file-name.
1864@end group
1865@end smallexample
1866@iftex
1867@medbreak
1868@end iftex
1869
1870 Normally, @kbd{C-x v a} separates log entries by a blank line, but you
1871can mark several related log entries to be clumped together (without an
1872intervening blank line) by starting the text of each related log entry
1873with a label of the form @w{@samp{@{@var{clumpname}@} }}. The label
1874itself is not copied to @file{ChangeLog}. For example, suppose the log
1875entries are:
1876
1877@flushleft
1878@bullet{} For @file{vc.texinfo}: @samp{@{expand@} Fix expansion typos.}
1879@bullet{} For @file{vc.el}: @samp{@{expand@} Don't call expand-file-name.}
1880@bullet{} For @file{vc-hooks.el}: @samp{@{expand@} Don't call expand-file-name.}
1881@end flushleft
1882
1883@noindent
1884Then the text in @file{ChangeLog} looks like this:
1885
1886@iftex
1887@medbreak
1888@end iftex
1889@smallexample
1890@group
18911999-04-01 Nathaniel Bowditch <nat@@apn.org>
1892
1893 * vc.texinfo: Fix expansion typos.
1894 * vc.el, vc-hooks.el: Don't call expand-file-name.
1895@end group
1896@end smallexample
1897@iftex
1898@medbreak
1899@end iftex
1900
1901 A log entry whose text begins with @samp{#} is not copied to
1902@file{ChangeLog}. For example, if you merely fix some misspellings in
1903comments, you can log the change with an entry beginning with @samp{#}
1904to avoid putting such trivia into @file{ChangeLog}.
1905
1906@node Renaming and VC
1907@subsubsection Renaming VC Work Files and Master Files
1908
1909@findex vc-rename-file
1910 When you rename a registered file, you must also rename its master
1911file correspondingly to get proper results. Use @code{vc-rename-file}
1912to rename the source file as you specify, and rename its master file
1913accordingly. It also updates any snapshots (@pxref{Snapshots}) that
1914mention the file, so that they use the new name; despite this, the
1915snapshot thus modified may not completely work (@pxref{Snapshot
1916Caveats}).
1917
1918 You cannot use @code{vc-rename-file} on a file that is locked by
1919someone else.
1920
1921@node Version Headers
1922@subsubsection Inserting Version Control Headers
1923
1924 Sometimes it is convenient to put version identification strings
1925directly into working files. Certain special strings called
1926@dfn{version headers} are replaced in each successive version by the
1927number of that version.
1928
1929 If you are using RCS, and version headers are present in your working
1930files, Emacs can use them to determine the current version and the
1931locking state of the files. This is more reliable than referring to the
1932master files, which is done when there are no version headers. Note
1933that in a multi-branch environment, version headers are necessary to
1934make VC behave correctly (@pxref{Multi-User Branching}).
1935
1936 Searching for version headers is controlled by the variable
1937@code{vc-consult-headers}. If it is non-@code{nil}, Emacs searches for
1938headers to determine the version number you are editing. Setting it to
1939@code{nil} disables this feature.
1940
1941@kindex C-x v h
1942@findex vc-insert-headers
1943 You can use the @kbd{C-x v h} command (@code{vc-insert-headers}) to
1944insert a suitable header string.
1945
1946@table @kbd
1947@item C-x v h
1948Insert headers in a file for use with your version-control system.
1949@end table
1950
1951@vindex vc-header-alist
1952 The default header string is @samp{@w{$}Id$} for RCS and
1953@samp{@w{%}W%} for SCCS. You can specify other headers to insert by
1954setting the variable @code{vc-header-alist}. Its value is a list of
1955elements of the form @code{(@var{program} . @var{string})} where
1956@var{program} is @code{RCS} or @code{SCCS} and @var{string} is the
1957string to use.
1958
1959 Instead of a single string, you can specify a list of strings; then
1960each string in the list is inserted as a separate header on a line of
1961its own.
1962
1963 It is often necessary to use ``superfluous'' backslashes when writing
1964the strings that you put in this variable. This is to prevent the
1965string in the constant from being interpreted as a header itself if the
1966Emacs Lisp file containing it is maintained with version control.
1967
1968@vindex vc-comment-alist
1969 Each header is inserted surrounded by tabs, inside comment delimiters,
1970on a new line at point. Normally the ordinary comment
1971start and comment end strings of the current mode are used, but for
1972certain modes, there are special comment delimiters for this purpose;
1973the variable @code{vc-comment-alist} specifies them. Each element of
1974this list has the form @code{(@var{mode} @var{starter} @var{ender})}.
1975
1976@vindex vc-static-header-alist
1977 The variable @code{vc-static-header-alist} specifies further strings
1978to add based on the name of the buffer. Its value should be a list of
1979elements of the form @code{(@var{regexp} . @var{format})}. Whenever
1980@var{regexp} matches the buffer name, @var{format} is inserted as part
1981of the header. A header line is inserted for each element that matches
1982the buffer name, and for each string specified by
1983@code{vc-header-alist}. The header line is made by processing the
1984string from @code{vc-header-alist} with the format taken from the
1985element. The default value for @code{vc-static-header-alist} is as follows:
1986
1987@example
1988@group
1989(("\\.c$" .
1990 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n\
1991#endif /* lint */\n"))
1992@end group
1993@end example
1994
1995@noindent
1996It specifies insertion of text of this form:
1997
1998@example
1999@group
2000
2001#ifndef lint
2002static char vcid[] = "@var{string}";
2003#endif /* lint */
2004@end group
2005@end example
2006
2007@noindent
2008Note that the text above starts with a blank line.
2009
2010 If you use more than one version header in a file, put them close
2011together in the file. The mechanism in @code{revert-buffer} that
2012preserves markers may not handle markers positioned between two version
2013headers.
2014
2015@node Customizing VC
2016@subsection Customizing VC
2017
2018 There are many ways of customizing VC. The options you can set fall
2019into four categories, described in the following sections.
2020
4f36dd62
DL
2021@vindex vc-ignore-vc-files
2022@cindex Version control, deactivating
2023 In addition, it is possible to turn VC on and off generally by setting
2024the variable @code{vc-ignore-vc-files}. Normally VC will notice the
2025presence of version control on a file you visit and automatically invoke
2026the relevant program to check the file's state. Change
2027@code{vc-ignore-vc-files} if this isn't the right thing, for instance,
2028if you edit files under version control but don't have the relevant
2029version control programs available.
2030
6bf7aab6
DL
2031@menu
2032* Backend Options:: Customizing the back-end to your needs.
2033* VC Workfile Handling:: Various options concerning working files.
2034* VC Status Retrieval:: How VC finds the version control status of a file,
2035 and how to customize this.
2036* VC Command Execution:: Which commands VC should run, and how.
2037@end menu
2038
2039@node Backend Options
2040@subsubsection Options for VC Backends
2041
2042@cindex backend options (VC)
2043@cindex locking under version control
2044 You can tell RCS and CVS whether to use locking for a file or not
2045(@pxref{VC Concepts}, for a description of locking). VC automatically
2046recognizes what you have chosen, and behaves accordingly.
2047
2048@cindex non-strict locking (RCS)
2049@cindex locking, non-strict (RCS)
2050 For RCS, the default is to use locking, but there is a mode called
2051@dfn{non-strict locking} in which you can check-in changes without
2052locking the file first. Use @samp{rcs -U} to switch to non-strict
2053locking for a particular file, see the @samp{rcs} manpage for details.
2054
2055@cindex locking (CVS)
2056 Under CVS, the default is not to use locking; anyone can change a work
2057file at any time. However, there are ways to restrict this, resulting
2058in behavior that resembles locking.
2059
2060@cindex CVSREAD environment variable (CVS)
2061 For one thing, you can set the @code{CVSREAD} environment variable to
2062an arbitrary value. If this variable is defined, CVS makes your work
2063files read-only by default. In Emacs, you must type @kbd{C-x C-q} to
2064make the file writeable, so that editing works in fact similar as if
2065locking was used. Note however, that no actual locking is performed, so
2066several users can make their files writeable at the same time. When
2067setting @code{CVSREAD} for the first time, make sure to check out all
2068your modules anew, so that the file protections are set correctly.
2069
2070@cindex cvs watch feature
2071@cindex watching files (CVS)
2072 Another way to achieve something similar to locking is to use the
2073@dfn{watch} feature of CVS. If a file is being watched, CVS makes it
2074read-only by default, and you must also use @kbd{C-x C-q} in Emacs to
2075make it writable. VC calls @code{cvs edit} to make the file writeable,
2076and CVS takes care to notify other developers of the fact that you
2077intend to change the file. See the CVS documentation for details on
2078using the watch feature.
2079
2080@vindex vc-handle-cvs
2081 You can turn off use of VC for CVS-managed files by setting the
2082variable @code{vc-handle-cvs} to @code{nil}. If you do this, Emacs
2083treats these files as if they were not registered, and the VC commands
2084are not available for them. You must do all CVS operations manually.
2085
2086@node VC Workfile Handling
2087@subsubsection VC Workfile Handling
2088
2089@vindex vc-make-backup-files
2090 Emacs normally does not save backup files for source files that are
2091maintained with version control. If you want to make backup files even
2092for files that use version control, set the variable
2093@code{vc-make-backup-files} to a non-@code{nil} value.
2094
2095@vindex vc-keep-workfiles
2096 Normally the work file exists all the time, whether it is locked or
2097not. If you set @code{vc-keep-workfiles} to @code{nil}, then checking
2098in a new version with @kbd{C-x C-q} deletes the work file; but any
2099attempt to visit the file with Emacs creates it again. (With CVS, work
2100files are always kept.)
2101
2102@vindex vc-follow-symlinks
2103 Editing a version-controlled file through a symbolic link can be
2104dangerous. It bypasses the version control system---you can edit the
2105file without locking it, and fail to check your changes in. Also,
2106your changes might overwrite those of another user. To protect against
2107this, VC checks each symbolic link that you visit, to see if it points
2108to a file under version control.
2109
2110 The variable @code{vc-follow-symlinks} controls what to do when a
2111symbolic link points to a version-controlled file. If it is @code{nil},
2112VC only displays a warning message. If it is @code{t}, VC automatically
2113follows the link, and visits the real file instead, telling you about
2114this in the echo area. If the value is @code{ask} (the default), VC
2115asks you each time whether to follow the link.
2116
2117@node VC Status Retrieval
2118@subsubsection VC Status Retrieval
2119@c There is no need to tell users about vc-master-templates.
2120
2121 When deducing the locked/unlocked state of a file, VC first looks for
2122an RCS version header string in the file (@pxref{Version Headers}). If
2123there is no header string, or if you are using SCCS, VC normally looks
2124at the file permissions of the work file; this is fast. But there might
2125be situations when the file permissions cannot be trusted. In this case
2126the master file has to be consulted, which is rather expensive. Also
2127the master file can only tell you @emph{if} there's any lock on the
2128file, but not whether your work file really contains that locked
2129version.
2130
2131@vindex vc-consult-headers
2132 You can tell VC not to use version headers to determine lock status by
2133setting @code{vc-consult-headers} to @code{nil}. VC then always uses
2134the file permissions (if it can trust them), or else checks the master
2135file.
2136
2137@vindex vc-mistrust-permissions
2138 You can specify the criterion for whether to trust the file
2139permissions by setting the variable @code{vc-mistrust-permissions}. Its
2140value can be @code{t} (always mistrust the file permissions and check
2141the master file), @code{nil} (always trust the file permissions), or a
2142function of one argument which makes the decision. The argument is the
2143directory name of the @file{RCS}, @file{CVS} or @file{SCCS}
2144subdirectory. A non-@code{nil} value from the function says to mistrust
2145the file permissions. If you find that the file permissions of work
2146files are changed erroneously, set @code{vc-mistrust-permissions} to
2147@code{t}. Then VC always checks the master file to determine the file's
2148status.
2149
2150@node VC Command Execution
2151@subsubsection VC Command Execution
2152
2153@vindex vc-suppress-confirm
2154 If @code{vc-suppress-confirm} is non-@code{nil}, then @kbd{C-x C-q}
2155and @kbd{C-x v i} can save the current buffer without asking, and
2156@kbd{C-x v u} also operates without asking for confirmation. (This
2157variable does not affect @kbd{C-x v c}; that operation is so drastic
2158that it should always ask for confirmation.)
2159
2160@vindex vc-command-messages
2161 VC mode does much of its work by running the shell commands for RCS,
2162CVS and SCCS. If @code{vc-command-messages} is non-@code{nil}, VC
2163displays messages to indicate which shell commands it runs, and
2164additional messages when the commands finish.
2165
2166@vindex vc-path
2167 You can specify additional directories to search for version control
2168programs by setting the variable @code{vc-path}. These directories are
2169searched before the usual search path. But the proper files are usually
2170found automatically.
2171
2172@node Directories
2173@section File Directories
2174
2175@cindex file directory
2176@cindex directory listing
2177 The file system groups files into @dfn{directories}. A @dfn{directory
2178listing} is a list of all the files in a directory. Emacs provides
2179commands to create and delete directories, and to make directory
2180listings in brief format (file names only) and verbose format (sizes,
2181dates, and authors included). There is also a directory browser called
2182Dired; see @ref{Dired}.
2183
2184@table @kbd
2185@item C-x C-d @var{dir-or-pattern} @key{RET}
2186Display a brief directory listing (@code{list-directory}).
2187@item C-u C-x C-d @var{dir-or-pattern} @key{RET}
2188Display a verbose directory listing.
2189@item M-x make-directory @key{RET} @var{dirname} @key{RET}
2190Create a new directory named @var{dirname}.
2191@item M-x delete-directory @key{RET} @var{dirname} @key{RET}
2192Delete the directory named @var{dirname}. It must be empty,
2193or you get an error.
2194@end table
2195
2196@findex list-directory
2197@kindex C-x C-d
2198 The command to display a directory listing is @kbd{C-x C-d}
2199(@code{list-directory}). It reads using the minibuffer a file name
2200which is either a directory to be listed or a wildcard-containing
2201pattern for the files to be listed. For example,
2202
2203@example
2204C-x C-d /u2/emacs/etc @key{RET}
2205@end example
2206
2207@noindent
2208lists all the files in directory @file{/u2/emacs/etc}. Here is an
2209example of specifying a file name pattern:
2210
2211@example
2212C-x C-d /u2/emacs/src/*.c @key{RET}
2213@end example
2214
2215 Normally, @kbd{C-x C-d} prints a brief directory listing containing
2216just file names. A numeric argument (regardless of value) tells it to
2217make a verbose listing including sizes, dates, and authors (like
2218@samp{ls -l}).
2219
2220@vindex list-directory-brief-switches
2221@vindex list-directory-verbose-switches
2222 The text of a directory listing is obtained by running @code{ls} in an
2223inferior process. Two Emacs variables control the switches passed to
2224@code{ls}: @code{list-directory-brief-switches} is a string giving the
2225switches to use in brief listings (@code{"-CF"} by default), and
2226@code{list-directory-verbose-switches} is a string giving the switches to
2227use in a verbose listing (@code{"-l"} by default).
2228
2229@node Comparing Files
2230@section Comparing Files
2231@cindex comparing files
2232
2233@findex diff
2234@vindex diff-switches
2235 The command @kbd{M-x diff} compares two files, displaying the
2236differences in an Emacs buffer named @samp{*Diff*}. It works by running
2237the @code{diff} program, using options taken from the variable
2238@code{diff-switches}, whose value should be a string.
2239
2240 The buffer @samp{*Diff*} has Compilation mode as its major mode, so
2241you can use @kbd{C-x `} to visit successive changed locations in the two
2242source files. You can also move to a particular hunk of changes and
2243type @key{RET} or @kbd{C-c C-c}, or click @kbd{Mouse-2} on it, to move
2244to the corresponding source location. You can also use the other
2245special commands of Compilation mode: @key{SPC} and @key{DEL} for
2246scrolling, and @kbd{M-p} and @kbd{M-n} for cursor motion.
2247@xref{Compilation}.
2248
2249@findex diff-backup
2250 The command @kbd{M-x diff-backup} compares a specified file with its most
2251recent backup. If you specify the name of a backup file,
2252@code{diff-backup} compares it with the source file that it is a backup
2253of.
2254
2255@findex compare-windows
2256 The command @kbd{M-x compare-windows} compares the text in the current
2257window with that in the next window. Comparison starts at point in each
2258window, and each starting position is pushed on the mark ring in its
2259respective buffer. Then point moves forward in each window, a character
2260at a time, until a mismatch between the two windows is reached. Then
2261the command is finished. For more information about windows in Emacs,
2262@ref{Windows}.
2263
2264@vindex compare-ignore-case
2265 With a numeric argument, @code{compare-windows} ignores changes in
2266whitespace. If the variable @code{compare-ignore-case} is
2267non-@code{nil}, it ignores differences in case as well.
2268
2269 See also @ref{Emerge}, for convenient facilities for merging two
2270similar files.
2271
2272@node Misc File Ops
2273@section Miscellaneous File Operations
2274
2275 Emacs has commands for performing many other operations on files.
2276All operate on one file; they do not accept wildcard file names.
2277
2278@findex view-file
2279@cindex viewing
2280@cindex View mode
2281@cindex mode, View
2282 @kbd{M-x view-file} allows you to scan or read a file by sequential
2283screenfuls. It reads a file name argument using the minibuffer. After
2284reading the file into an Emacs buffer, @code{view-file} displays the
2285beginning. You can then type @key{SPC} to scroll forward one windowful,
2286or @key{DEL} to scroll backward. Various other commands are provided
2287for moving around in the file, but none for changing it; type @kbd{?}
2288while viewing for a list of them. They are mostly the same as normal
2289Emacs cursor motion commands. To exit from viewing, type @kbd{q}.
2290The commands for viewing are defined by a special major mode called View
2291mode.
2292
2293 A related command, @kbd{M-x view-buffer}, views a buffer already present
2294in Emacs. @xref{Misc Buffer}.
2295
2296@findex insert-file
2297 @kbd{M-x insert-file} inserts a copy of the contents of the specified
2298file into the current buffer at point, leaving point unchanged before the
2299contents and the mark after them.
2300
2301@findex write-region
2302 @kbd{M-x write-region} is the inverse of @kbd{M-x insert-file}; it
2303copies the contents of the region into the specified file. @kbd{M-x
2304append-to-file} adds the text of the region to the end of the specified
2305file. @xref{Accumulating Text}.
2306
2307@findex delete-file
2308@cindex deletion (of files)
2309 @kbd{M-x delete-file} deletes the specified file, like the @code{rm}
2310command in the shell. If you are deleting many files in one directory, it
2311may be more convenient to use Dired (@pxref{Dired}).
2312
2313@findex rename-file
2314 @kbd{M-x rename-file} reads two file names @var{old} and @var{new} using
2315the minibuffer, then renames file @var{old} as @var{new}. If a file named
2316@var{new} already exists, you must confirm with @kbd{yes} or renaming is not
2317done; this is because renaming causes the old meaning of the name @var{new}
2318to be lost. If @var{old} and @var{new} are on different file systems, the
2319file @var{old} is copied and deleted.
2320
2321@findex add-name-to-file
2322 The similar command @kbd{M-x add-name-to-file} is used to add an
2323additional name to an existing file without removing its old name.
2324The new name must belong on the same file system that the file is on.
2325
2326@findex copy-file
2327@cindex copying files
2328 @kbd{M-x copy-file} reads the file @var{old} and writes a new file named
2329@var{new} with the same contents. Confirmation is required if a file named
2330@var{new} already exists, because copying has the consequence of overwriting
2331the old contents of the file @var{new}.
2332
2333@findex make-symbolic-link
2334 @kbd{M-x make-symbolic-link} reads two file names @var{target} and
2335@var{linkname}, then creates a symbolic link named @var{linkname} and
2336pointing at @var{target}. The effect is that future attempts to open file
2337@var{linkname} will refer to whatever file is named @var{target} at the
2338time the opening is done, or will get an error if the name @var{target} is
2339not in use at that time. This command does not expand the argument
2340@var{target}, so that it allows you to specify a relative name
2341as the target of the link.
2342
2343 Confirmation is required when creating the link if @var{linkname} is
2344in use. Note that not all systems support symbolic links.
2345
2346@node Compressed Files
2347@section Accessing Compressed Files
2348@cindex compression
2349@cindex uncompression
2350@cindex Auto Compression mode
2351@cindex mode, Auto Compression
2352@pindex gzip
2353
2354@findex auto-compression-mode
259a88ca 2355@vindex auto-compression-mode
6bf7aab6
DL
2356 Emacs comes with a library that can automatically uncompress
2357compressed files when you visit them, and automatically recompress them
2358if you alter them and save them. To enable this feature, type the
259a88ca
DL
2359command @kbd{M-x auto-compression-mode}. You can enable it permanently
2360by customizing the option @var{auto-compression-mode}.
6bf7aab6
DL
2361
2362 When automatic compression (which implies automatic uncompression as
2363well) is enabled, Emacs recognizes compressed files by their file names.
2364File names ending in @samp{.gz} indicate a file compressed with
2365@code{gzip}. Other endings indicate other compression programs.
2366
2367 Automatic uncompression and compression apply to all the operations in
2368which Emacs uses the contents of a file. This includes visiting it,
2369saving it, inserting its contents into a buffer, loading it, and byte
2370compiling it.
2371
259a88ca
DL
2372@node File Archives
2373@section File Archives
2374@cindex mode, tar
2375@cindex Tar mode
2376@cindex Archive mode
2377@cindex mode, archive
2378@cindex @code{arc}
2379@cindex @code{jar}
2380@cindex @code{zip}
2381@cindex @code{lzh}
2382@cindex @code{zoo}
2383@pindex tar
2384@pindex arc
2385@pindex jar
2386@pindex zip
2387@pindex lzh
2388@pindex zoo
2389
2390If you visit a file with extension @samp{.tar}, it is assumed to be an
2391`archive' made by the @code{tar} program and it is viewed in a Tar mode
2392buffer. This provides a Dired-like listing of the contents.
2393@xref{Dired}. You can move around the component files as in Dired to
2394visit and manipulate them.
2395
2396The keys @kbd{e}, @kbd{f} and @kbd{RET} all extract a component file
2397into its own buffer. You can edit it there and when you save the buffer
2398the edited version will replace the version in the Tar buffer. @var{v}
2399extracts a file into a buffer in View mode. @kbd{d} marks a file for
2400deletion when you later use @kbd{x}, as in Dired. @kbd{C} copies a file
2401from the archive to disk and @kbd{R} renames a file.
2402
2403Saving the Tar buffer writes a new version of the archive to disk with
2404the changes you made to the components.
2405
2406If you enable Auto Compression mode (@pxref{Compressed Files}), then Tar
2407mode will be used also for compressed archives in files with extensions
2408@samp{.tgz}, @code{.tar.Z} and @code{.tar.gz}.
2409
7ed32bd8
DL
2410It is not necessary to have the @code{tar} program available to use Tar
2411mode or Archive mode---Emacs reads the archives directly.
2412
259a88ca
DL
2413@cindex @code{arc}
2414@cindex @code{jar}
2415@cindex @code{zip}
2416@cindex @code{lzh}
2417@cindex @code{zoo}
2418@pindex tar
2419@pindex arc
2420@pindex jar
2421@pindex zip
2422@pindex lzh
2423@pindex zoo
2424@cindex Java class archives
2425A separate but similar Archive mode, is used for archives produced by
2426the programs @code{arc}, @code{zip}, @code{lzh} and @code{zoo} which
2427have extensions corresponding to the program names. These archiving
2428programs are typically used on MS-DOS and MS-Windows systems. Java
2429class archives with extension @samp{.jar} are also recognized. The
2430keybindings in Archive mode are similar to those in Tar mode.
2431
7ed32bd8
DL
2432Unlike Tar mode, Archive mode runs the appropriate program to unpack and
2433repack archives. Details of the program names and their options can be
2434set in the `Archive' Customize group.
259a88ca 2435
6bf7aab6
DL
2436@node Remote Files
2437@section Remote Files
2438
2439@cindex FTP
2440@cindex remote file access
2441 You can refer to files on other machines using a special file name syntax:
2442
2443@example
2444@group
2445/@var{host}:@var{filename}
2446/@var{user}@@@var{host}:@var{filename}
4f36dd62 2447/@var{user}@@@var{host}#@var{port}:@var{filename}
6bf7aab6
DL
2448@end group
2449@end example
2450
2451@noindent
2452When you do this, Emacs uses the FTP program to read and write files on
2453the specified host. It logs in through FTP using your user name or the
2454name @var{user}. It may ask you for a password from time to time; this
4f36dd62
DL
2455is used for logging in on @var{host}. The form using @var{port} allows
2456you to access servers running on a non-default TCP port.
6bf7aab6
DL
2457
2458@cindex ange-ftp
2459@vindex ange-ftp-default-user
2460 Normally, if you do not specify a user name in a remote file name,
2461that means to use your own user name. But if you set the variable
2462@code{ange-ftp-default-user} to a string, that string is used instead.
2463(The Emacs package that implements FTP file access is called
2464@code{ange-ftp}.)
2465
2466@vindex file-name-handler-alist
4f36dd62
DL
2467 You can entirely turn off the FTP file name feature by removing the
2468entries @var{ange-ftp-completion-hook-function} and
2469@var{ange-ftp-hook-function} from the variable
7ed32bd8
DL
2470@code{file-name-handler-alist}. You can turn off the feature in
2471individual cases by quoting the file name with @samp{/:} (@pxref{Quoted
2472File Names}).
6bf7aab6
DL
2473
2474@node Quoted File Names
2475@section Quoted File Names
2476
2477@cindex quoting file names
2478 You can @dfn{quote} an absolute file name to prevent special
2479characters and syntax in it from having their special effects.
2480The way to do this is to add @samp{/:} at the beginning.
2481
2482 For example, you can quote a local file name which appears remote, to
2483prevent it from being treated as a remote file name. Thus, if you have
2484a directory named @file{/foo:} and a file named @file{bar} in it, you
2485can refer to that file in Emacs as @samp{/:/foo:/bar}.
2486
2487 @samp{/:} can also prevent @samp{~} from being treated as a special
2488character for a user's home directory. For example, @file{/:/tmp/~hack}
2489refers to a file whose name is @file{~hack} in directory @file{/tmp}.
2490
2491 Likewise, quoting with @samp{/:} is one way to enter in the minibuffer
2492a file name that contains @samp{$}. However, the @samp{/:} must be at
2493the beginning of the buffer in order to quote @samp{$}.
2494
7ed32bd8 2495@cindex wildcard characters in file names
6bf7aab6
DL
2496 You can also quote wildcard characters with @samp{/:}, for visiting.
2497For example, @file{/:/tmp/foo*bar} visits the file @file{/tmp/foo*bar}.
2498However, in most cases you can simply type the wildcard characters for
2499themselves. For example, if the only file name in @file{/tmp} that
2500starts with @samp{foo} and ends with @samp{bar} is @file{foo*bar}, then
2501specifying @file{/tmp/foo*bar} will visit just @file{/tmp/foo*bar}.
7ed32bd8 2502Another way is to specify @file{/tmp/foo[*]bar}.