]> code.delx.au - gnu-emacs/blob - doc/emacs/files.texi
Merge from trunk.
[gnu-emacs] / doc / emacs / files.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985-1987, 1993-1995, 1997, 1999-2012
3 @c Free Software Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node Files, Buffers, Keyboard Macros, Top
6 @chapter File Handling
7 @cindex files
8
9 The operating system stores data permanently in named @dfn{files}, so
10 most of the text you edit with Emacs comes from a file and is ultimately
11 stored in a file.
12
13 To edit a file, you must tell Emacs to read the file and prepare a
14 buffer containing a copy of the file's text. This is called
15 @dfn{visiting} the file. Editing commands apply directly to text in the
16 buffer; that is, to the copy inside Emacs. Your changes appear in the
17 file itself only when you @dfn{save} the buffer back into the file.
18
19 In addition to visiting and saving files, Emacs can delete, copy,
20 rename, and append to files, keep multiple versions of them, and operate
21 on file directories.
22
23 @menu
24 * File Names:: How to type and edit file-name arguments.
25 * Visiting:: Visiting a file prepares Emacs to edit the file.
26 * Saving:: Saving makes your changes permanent.
27 * Reverting:: Reverting cancels all the changes not saved.
28 @ifnottex
29 * Autorevert:: Auto Reverting non-file buffers.
30 @end ifnottex
31 * Auto Save:: Auto Save periodically protects against loss of data.
32 * File Aliases:: Handling multiple names for one file.
33 * Directories:: Creating, deleting, and listing file directories.
34 * Comparing Files:: Finding where two files differ.
35 * Diff Mode:: Mode for editing file differences.
36 * Misc File Ops:: Other things you can do on files.
37 * Compressed Files:: Accessing compressed files.
38 * File Archives:: Operating on tar, zip, jar etc. archive files.
39 * Remote Files:: Accessing files on other sites.
40 * Quoted File Names:: Quoting special characters in file names.
41 * File Name Cache:: Completion against a list of files you often use.
42 * File Conveniences:: Convenience Features for Finding Files.
43 * Filesets:: Handling sets of files.
44 @end menu
45
46 @node File Names
47 @section File Names
48 @cindex file names
49
50 @cindex default file name
51 Many Emacs commands that operate on a file require you to specify
52 the file name, using the minibuffer (@pxref{Minibuffer File}).
53
54 While in the minibuffer, you can use the usual completion and
55 history commands (@pxref{Minibuffer}). Note that file name completion
56 ignores file names whose extensions appear in the variable
57 @code{completion-ignored-extensions} (@pxref{Completion Options}).
58 Note also that most commands use ``permissive completion with
59 confirmation'' for reading file names: you are allowed to submit a
60 nonexistent file name, but if you type @key{RET} immediately after
61 completing up to a nonexistent file name, Emacs prints
62 @samp{[Confirm]} and you must type a second @key{RET} to confirm.
63 @xref{Completion Exit}, for details.
64
65 @cindex default directory
66 @vindex default-directory
67 @vindex insert-default-directory
68 Each buffer has a @dfn{default directory}, stored in the
69 buffer-local variable @code{default-directory}. Whenever Emacs reads
70 a file name using the minibuffer, it usually inserts the default
71 directory into the minibuffer as the initial contents. You can
72 inhibit this insertion by changing the variable
73 @code{insert-default-directory} to @code{nil} (@pxref{Minibuffer
74 File}). Regardless, Emacs always assumes that any relative file name
75 is relative to the default directory, e.g. entering a file name
76 without a directory specifies a file in the default directory.
77
78 @findex cd
79 @findex pwd
80 When you visit a file, Emacs sets @code{default-directory} in the
81 visiting buffer to the directory of its file. When you create a new
82 buffer that is not visiting a file, via a command like @kbd{C-x b},
83 its default directory is usually copied from the buffer that was
84 current at the time (@pxref{Select Buffer}). You can use the command
85 @kbd{M-x pwd} to see the value of @code{default-directory} in the
86 current buffer. The command @kbd{M-x cd} prompts for a directory
87 name, and sets the buffer's @code{default-directory} to that directory
88 (doing this does not change the buffer's file name, if any).
89
90 As an example, when you visit the file @file{/u/rms/gnu/gnu.tasks},
91 the default directory is set to @file{/u/rms/gnu/}. If you invoke a
92 command that reads a file name, entering just @samp{foo} in the
93 minibuffer, with a directory omitted, specifies the file
94 @file{/u/rms/gnu/foo}; entering @samp{../.login} specifies
95 @file{/u/rms/.login}; and entering @samp{new/foo} specifies
96 @file{/u/rms/gnu/new/foo}.
97
98 When typing a file name into the minibuffer, you can make use of a
99 couple of shortcuts: a double slash is interpreted as ``ignore
100 everything before the second slash in the pair,'' and @samp{~/} is
101 interpreted as your home directory. @xref{Minibuffer File}.
102
103 @cindex environment variables in file names
104 @cindex expansion of environment variables
105 @cindex @code{$} in file names
106 @anchor{File Names with $}The character @samp{$} is used to
107 substitute an environment variable into a file name. The name of the
108 environment variable consists of all the alphanumeric characters after
109 the @samp{$}; alternatively, it can be enclosed in braces after the
110 @samp{$}. For example, if you have used the shell command
111 @command{export FOO=rms/hacks} to set up an environment variable named
112 @env{FOO}, then both @file{/u/$FOO/test.c} and
113 @file{/u/$@{FOO@}/test.c} are abbreviations for
114 @file{/u/rms/hacks/test.c}. If the environment variable is not
115 defined, no substitution occurs, so that the character @samp{$} stands
116 for itself. Note that environment variables affect Emacs only if they
117 are applied before Emacs is started.
118
119 To access a file with @samp{$} in its name, if the @samp{$} causes
120 expansion, type @samp{$$}. This pair is converted to a single
121 @samp{$} at the same time that variable substitution is performed for
122 a single @samp{$}. Alternatively, quote the whole file name with
123 @samp{/:} (@pxref{Quoted File Names}). File names which begin with a
124 literal @samp{~} should also be quoted with @samp{/:}.
125
126 You can include non-@acronym{ASCII} characters in file names.
127 @xref{File Name Coding}.
128
129 @node Visiting
130 @section Visiting Files
131 @cindex visiting files
132 @cindex open file
133
134 @table @kbd
135 @item C-x C-f
136 Visit a file (@code{find-file}).
137 @item C-x C-r
138 Visit a file for viewing, without allowing changes to it
139 (@code{find-file-read-only}).
140 @item C-x C-v
141 Visit a different file instead of the one visited last
142 (@code{find-alternate-file}).
143 @item C-x 4 f
144 Visit a file, in another window (@code{find-file-other-window}). Don't
145 alter what is displayed in the selected window.
146 @item C-x 5 f
147 Visit a file, in a new frame (@code{find-file-other-frame}). Don't
148 alter what is displayed in the selected frame.
149 @item M-x find-file-literally
150 Visit a file with no conversion of the contents.
151 @end table
152
153 @cindex files, visiting and saving
154 @cindex saving files
155 @dfn{Visiting} a file means reading its contents into an Emacs
156 buffer so you can edit them. Emacs makes a new buffer for each file
157 that you visit.
158
159 @kindex C-x C-f
160 @findex find-file
161 To visit a file, type @kbd{C-x C-f} (@code{find-file}) and use the
162 minibuffer to enter the name of the desired file. While in the
163 minibuffer, you can abort the command by typing @kbd{C-g}. @xref{File
164 Names}, for details about entering file names into minibuffers.
165
166 If the specified file exists but the system does not allow you to
167 read it, an error message is displayed in the echo area. Otherwise,
168 you can tell that @kbd{C-x C-f} has completed successfully by the
169 appearance of new text on the screen, and by the buffer name shown in
170 the mode line (@pxref{Mode Line}). Emacs normally constructs the
171 buffer name from the file name, omitting the directory name. For
172 example, a file named @file{/usr/rms/emacs.tex} is visited in a buffer
173 named @samp{emacs.tex}. If there is already a buffer with that name,
174 Emacs constructs a unique name; the normal method is to append
175 @samp{<2>}, @samp{<3>}, and so on, but you can select other methods.
176 @xref{Uniquify}.
177
178 @cindex creating files
179 To create a new file, just visit it using the same command, @kbd{C-x
180 C-f}. Emacs displays @samp{(New file)} in the echo area, but in other
181 respects behaves as if you had visited an existing empty file.
182
183 @cindex modified (buffer)
184 After visiting a file, the changes you make with editing commands are
185 made in the Emacs buffer. They do not take effect in the visited
186 file, until you @dfn{save} the buffer (@pxref{Saving}). If a buffer
187 contains changes that have not been saved, we say the buffer is
188 @dfn{modified}. This implies that some changes will be lost if the
189 buffer is not saved. The mode line displays two stars near the left
190 margin to indicate that the buffer is modified.
191
192 If you visit a file that is already in Emacs, @kbd{C-x C-f} switches
193 to the existing buffer instead of making another copy. Before doing
194 so, it checks whether the file has changed since you last visited or
195 saved it. If the file has changed, Emacs offers to reread it.
196
197 @vindex large-file-warning-threshold
198 @cindex file, warning when size is large
199 @cindex size of file, warning when visiting
200 @cindex maximum buffer size exceeded, error message
201 If you try to visit a file larger than
202 @code{large-file-warning-threshold} (the default is 10000000, which is
203 about 10 megabytes), Emacs asks you for confirmation first. You can
204 answer @kbd{y} to proceed with visiting the file. Note, however, that
205 Emacs cannot visit files that are larger than the maximum Emacs buffer
206 size, which is limited by the amount of memory Emacs can allocate and
207 by the integers that Emacs can represent (@pxref{Buffers}). If you
208 try, Emacs displays an error message saying that the maximum buffer
209 size has been exceeded.
210
211 @cindex wildcard characters in file names
212 @vindex find-file-wildcards
213 If the file name you specify contains shell-style wildcard
214 characters, Emacs visits all the files that match it. (On
215 case-insensitive filesystems, Emacs matches the wildcards disregarding
216 the letter case.) Wildcards include @samp{?}, @samp{*}, and
217 @samp{[@dots{}]} sequences. To enter the wild card @samp{?} in a file
218 name in the minibuffer, you need to type @kbd{C-q ?}. @xref{Quoted
219 File Names}, for information on how to visit a file whose name
220 actually contains wildcard characters. You can disable the wildcard
221 feature by customizing @code{find-file-wildcards}.
222
223 @kindex C-x C-v
224 @findex find-alternate-file
225 If you visit the wrong file unintentionally by typing its name
226 incorrectly, type @kbd{C-x C-v} (@code{find-alternate-file}) to visit
227 the file you really wanted. @kbd{C-x C-v} is similar to @kbd{C-x
228 C-f}, but it kills the current buffer (after first offering to save it
229 if it is modified). When @kbd{C-x C-v} reads the file name to visit,
230 it inserts the entire default file name in the buffer, with point just
231 after the directory part; this is convenient if you made a slight
232 error in typing the name.
233
234 @vindex find-file-run-dired
235 If you ``visit'' a file that is actually a directory, Emacs invokes
236 Dired, the Emacs directory browser. @xref{Dired}. You can disable
237 this behavior by setting the variable @code{find-file-run-dired} to
238 @code{nil}; in that case, it is an error to try to visit a directory.
239
240 Files which are actually collections of other files, or @dfn{file
241 archives}, are visited in special modes which invoke a Dired-like
242 environment to allow operations on archive members. @xref{File
243 Archives}, for more about these features.
244
245 If you visit a file that the operating system won't let you modify,
246 or that is marked read-only, Emacs makes the buffer read-only too, so
247 that you won't go ahead and make changes that you'll have trouble
248 saving afterward. You can make the buffer writable with @kbd{C-x C-q}
249 (@code{toggle-read-only}). @xref{Misc Buffer}.
250
251 @kindex C-x C-r
252 @findex find-file-read-only
253 If you want to visit a file as read-only in order to protect
254 yourself from entering changes accidentally, visit it with the command
255 @kbd{C-x C-r} (@code{find-file-read-only}) instead of @kbd{C-x C-f}.
256
257 @kindex C-x 4 f
258 @findex find-file-other-window
259 @kbd{C-x 4 f} (@code{find-file-other-window}) is like @kbd{C-x C-f}
260 except that the buffer containing the specified file is selected in another
261 window. The window that was selected before @kbd{C-x 4 f} continues to
262 show the same buffer it was already showing. If this command is used when
263 only one window is being displayed, that window is split in two, with one
264 window showing the same buffer as before, and the other one showing the
265 newly requested file. @xref{Windows}.
266
267 @kindex C-x 5 f
268 @findex find-file-other-frame
269 @kbd{C-x 5 f} (@code{find-file-other-frame}) is similar, but opens a
270 new frame, or selects any existing frame showing the specified file.
271 @xref{Frames}.
272
273 @cindex file selection dialog
274 On graphical displays, there are two additional methods for visiting
275 files. Firstly, when Emacs is built with a suitable GUI toolkit,
276 commands invoked with the mouse (by clicking on the menu bar or tool
277 bar) use the toolkit's standard ``File Selection'' dialog instead of
278 prompting for the file name in the minibuffer. On GNU/Linux and Unix
279 platforms, Emacs does this when built with GTK, LessTif, and Motif
280 toolkits; on MS-Windows and Mac, the GUI version does that by default.
281 For information on how to customize this, see @ref{Dialog Boxes}.
282
283 Secondly, Emacs supports ``drag and drop'': dropping a file into an
284 ordinary Emacs window visits the file using that window. As an
285 exception, dropping a file into a window displaying a Dired buffer
286 moves or copies the file into the displayed directory. For details,
287 see @ref{Drag and Drop}, and @ref{Misc Dired Features}.
288
289 Each time you visit a file, Emacs automatically scans its contents
290 to detect what character encoding and end-of-line convention it uses,
291 and converts these to Emacs' internal encoding and end-of-line
292 convention within the buffer. When you save the buffer, Emacs
293 performs the inverse conversion, writing the file to disk with its
294 original encoding and end-of-line convention. @xref{Coding Systems}.
295
296 @findex find-file-literally
297 If you wish to edit a file as a sequence of @acronym{ASCII}
298 characters with no special encoding or conversion, use the @kbd{M-x
299 find-file-literally} command. This visits a file, like @kbd{C-x C-f},
300 but does not do format conversion (@pxref{Format Conversion,, Format
301 Conversion, elisp, the Emacs Lisp Reference Manual}), character code
302 conversion (@pxref{Coding Systems}), or automatic uncompression
303 (@pxref{Compressed Files}), and does not add a final newline because
304 of @code{require-final-newline} (@pxref{Customize Save}). If you have
305 already visited the same file in the usual (non-literal) manner, this
306 command asks you whether to visit it literally instead.
307
308 @vindex find-file-hook
309 @vindex find-file-not-found-functions
310 Two special hook variables allow extensions to modify the operation
311 of visiting files. Visiting a file that does not exist runs the
312 functions in @code{find-file-not-found-functions}; this variable holds
313 a list of functions, which are called one by one (with no arguments)
314 until one of them returns non-@code{nil}. This is not a normal hook,
315 and the name ends in @samp{-functions} rather than @samp{-hook} to
316 indicate that fact.
317
318 Successful visiting of any file, whether existing or not, calls the
319 functions in @code{find-file-hook}, with no arguments. This variable
320 is a normal hook. In the case of a nonexistent file, the
321 @code{find-file-not-found-functions} are run first. @xref{Hooks}.
322
323 There are several ways to specify automatically the major mode for
324 editing the file (@pxref{Choosing Modes}), and to specify local
325 variables defined for that file (@pxref{File Variables}).
326
327 @node Saving
328 @section Saving Files
329
330 @dfn{Saving} a buffer in Emacs means writing its contents back into the file
331 that was visited in the buffer.
332
333 @menu
334 * Save Commands:: Commands for saving files.
335 * Backup:: How Emacs saves the old version of your file.
336 * Customize Save:: Customizing the saving of files.
337 * Interlocking:: How Emacs protects against simultaneous editing
338 of one file by two users.
339 * Shadowing: File Shadowing. Copying files to "shadows" automatically.
340 * Time Stamps:: Emacs can update time stamps on saved files.
341 @end menu
342
343 @node Save Commands
344 @subsection Commands for Saving Files
345
346 These are the commands that relate to saving and writing files.
347
348 @table @kbd
349 @item C-x C-s
350 Save the current buffer to its file (@code{save-buffer}).
351 @item C-x s
352 Save any or all buffers to their files (@code{save-some-buffers}).
353 @item M-~
354 Forget that the current buffer has been changed (@code{not-modified}).
355 With prefix argument (@kbd{C-u}), mark the current buffer as changed.
356 @item C-x C-w
357 Save the current buffer with a specified file name (@code{write-file}).
358 @item M-x set-visited-file-name
359 Change the file name under which the current buffer will be saved.
360 @end table
361
362 @kindex C-x C-s
363 @findex save-buffer
364 When you wish to save the file and make your changes permanent, type
365 @kbd{C-x C-s} (@code{save-buffer}). After saving is finished, @kbd{C-x C-s}
366 displays a message like this:
367
368 @example
369 Wrote /u/rms/gnu/gnu.tasks
370 @end example
371
372 @noindent
373 If the current buffer is not modified (no changes have been made in it
374 since the buffer was created or last saved), saving is not really
375 done, because it would have no effect. Instead, @kbd{C-x C-s}
376 displays a message like this in the echo area:
377
378 @example
379 (No changes need to be saved)
380 @end example
381
382 With a prefix argument, @kbd{C-u C-x C-s}, Emacs also marks the buffer
383 to be backed up when the next save is done. @xref{Backup}.
384
385 @kindex C-x s
386 @findex save-some-buffers
387 The command @kbd{C-x s} (@code{save-some-buffers}) offers to save any
388 or all modified buffers. It asks you what to do with each buffer. The
389 possible responses are analogous to those of @code{query-replace}:
390
391 @table @kbd
392 @item y
393 Save this buffer and ask about the rest of the buffers.
394 @item n
395 Don't save this buffer, but ask about the rest of the buffers.
396 @item !
397 Save this buffer and all the rest with no more questions.
398 @c following generates acceptable underfull hbox
399 @item @key{RET}
400 Terminate @code{save-some-buffers} without any more saving.
401 @item .
402 Save this buffer, then exit @code{save-some-buffers} without even asking
403 about other buffers.
404 @item C-r
405 View the buffer that you are currently being asked about. When you exit
406 View mode, you get back to @code{save-some-buffers}, which asks the
407 question again.
408 @item d
409 Diff the buffer against its corresponding file, so you can see what
410 changes you would be saving. This calls the command
411 @code{diff-buffer-with-file} (@pxref{Comparing Files}).
412 @item C-h
413 Display a help message about these options.
414 @end table
415
416 @kbd{C-x C-c}, the key sequence to exit Emacs, invokes
417 @code{save-some-buffers} and therefore asks the same questions.
418
419 @kindex M-~
420 @findex not-modified
421 If you have changed a buffer but do not wish to save the changes,
422 you should take some action to prevent it. Otherwise, each time you
423 use @kbd{C-x s} or @kbd{C-x C-c}, you are liable to save this buffer
424 by mistake. One thing you can do is type @kbd{M-~}
425 (@code{not-modified}), which clears out the indication that the buffer
426 is modified. If you do this, none of the save commands will believe
427 that the buffer needs to be saved. (@samp{~} is often used as a
428 mathematical symbol for `not'; thus @kbd{M-~} is `not', metafied.)
429 Alternatively, you can cancel all the changes made since the file was
430 visited or saved, by reading the text from the file again. This is
431 called @dfn{reverting}. @xref{Reverting}. (You could also undo all
432 the changes by repeating the undo command @kbd{C-x u} until you have
433 undone all the changes; but reverting is easier.)
434
435 @findex set-visited-file-name
436 @kbd{M-x set-visited-file-name} alters the name of the file that the
437 current buffer is visiting. It reads the new file name using the
438 minibuffer. Then it marks the buffer as visiting that file name, and
439 changes the buffer name correspondingly. @code{set-visited-file-name}
440 does not save the buffer in the newly visited file; it just alters the
441 records inside Emacs in case you do save later. It also marks the
442 buffer as ``modified'' so that @kbd{C-x C-s} in that buffer
443 @emph{will} save.
444
445 @kindex C-x C-w
446 @findex write-file
447 If you wish to mark the buffer as visiting a different file and save
448 it right away, use @kbd{C-x C-w} (@code{write-file}). This is
449 equivalent to @code{set-visited-file-name} followed by @kbd{C-x C-s},
450 except that @kbd{C-x C-w} asks for confirmation if the file exists.
451 @kbd{C-x C-s} used on a buffer that is not visiting a file has the
452 same effect as @kbd{C-x C-w}; that is, it reads a file name, marks the
453 buffer as visiting that file, and saves it there. The default file
454 name in a buffer that is not visiting a file is made by combining the
455 buffer name with the buffer's default directory (@pxref{File Names}).
456
457 If the new file name implies a major mode, then @kbd{C-x C-w} switches
458 to that major mode, in most cases. The command
459 @code{set-visited-file-name} also does this. @xref{Choosing Modes}.
460
461 If Emacs is about to save a file and sees that the date of the latest
462 version on disk does not match what Emacs last read or wrote, Emacs
463 notifies you of this fact, because it probably indicates a problem caused
464 by simultaneous editing and requires your immediate attention.
465 @xref{Interlocking,, Simultaneous Editing}.
466
467 @node Backup
468 @subsection Backup Files
469 @cindex backup file
470 @vindex make-backup-files
471 @vindex vc-make-backup-files
472
473 On most operating systems, rewriting a file automatically destroys all
474 record of what the file used to contain. Thus, saving a file from Emacs
475 throws away the old contents of the file---or it would, except that
476 Emacs carefully copies the old contents to another file, called the
477 @dfn{backup} file, before actually saving.
478
479 Emacs makes a backup for a file only the first time the file is
480 saved from a buffer. No matter how many times you subsequently save
481 the file, its backup remains unchanged. However, if you kill the
482 buffer and then visit the file again, a new backup file will be made.
483
484 For most files, the variable @code{make-backup-files} determines
485 whether to make backup files. On most operating systems, its default
486 value is @code{t}, so that Emacs does write backup files.
487
488 For files managed by a version control system (@pxref{Version
489 Control}), the variable @code{vc-make-backup-files} determines whether
490 to make backup files. By default it is @code{nil}, since backup files
491 are redundant when you store all the previous versions in a version
492 control system.
493 @iftex
494 @xref{General VC Options,,,emacs-xtra, Specialized Emacs Features}.
495 @end iftex
496 @ifnottex
497 @xref{General VC Options}.
498 @end ifnottex
499
500 At your option, Emacs can keep either a single backup for each file,
501 or make a series of numbered backup files for each file that you edit.
502 @xref{Backup Names}.
503
504 @vindex backup-enable-predicate
505 @vindex temporary-file-directory
506 @vindex small-temporary-file-directory
507 The default value of the @code{backup-enable-predicate} variable
508 prevents backup files being written for files in the directories used
509 for temporary files, specified by @code{temporary-file-directory} or
510 @code{small-temporary-file-directory}.
511
512 You can explicitly tell Emacs to make another backup file from a
513 buffer, even though that buffer has been saved before. If you save
514 the buffer with @kbd{C-u C-x C-s}, the version thus saved will be made
515 into a backup file if you save the buffer again. @kbd{C-u C-u C-x
516 C-s} saves the buffer, but first makes the previous file contents into
517 a new backup file. @kbd{C-u C-u C-u C-x C-s} does both things: it
518 makes a backup from the previous contents, and arranges to make
519 another from the newly saved contents if you save again.
520
521 @menu
522 * Names: Backup Names. How backup files are named.
523 * Deletion: Backup Deletion. Emacs deletes excess numbered backups.
524 * Copying: Backup Copying. Backups can be made by copying or renaming.
525 @end menu
526
527 @node Backup Names
528 @subsubsection Single or Numbered Backups
529
530 When Emacs makes a backup file, its name is normally constructed by
531 appending @samp{~} to the file name being edited; thus, the backup
532 file for @file{eval.c} would be @file{eval.c~}.
533
534 If access control stops Emacs from writing backup files under the
535 usual names, it writes the backup file as @file{~/.emacs.d/%backup%~}.
536 Only one such file can exist, so only the most recently made such
537 backup is available.
538
539 Emacs can also make @dfn{numbered backup files}. Numbered backup
540 file names contain @samp{.~}, the number, and another @samp{~} after
541 the original file name. Thus, the backup files of @file{eval.c} would
542 be called @file{eval.c.~1~}, @file{eval.c.~2~}, and so on, all the way
543 through names like @file{eval.c.~259~} and beyond.
544
545 @vindex version-control
546 The variable @code{version-control} determines whether to make
547 single backup files or multiple numbered backup files. Its possible
548 values are:
549
550 @table @code
551 @item nil
552 Make numbered backups for files that have numbered backups already.
553 Otherwise, make single backups. This is the default.
554 @item t
555 Make numbered backups.
556 @item never
557 Never make numbered backups; always make single backups.
558 @end table
559
560 @noindent
561 The usual way to set this variable is globally, through your init file
562 or the customization buffer. However, you can set
563 @code{version-control} locally in an individual buffer to control the
564 making of backups for that buffer's file (@pxref{Locals}). You can
565 have Emacs set @code{version-control} locally whenever you visit a
566 given file (@pxref{File Variables}). Some modes, such as Rmail mode,
567 set this variable.
568
569 @cindex @env{VERSION_CONTROL} environment variable
570 If you set the environment variable @env{VERSION_CONTROL}, to tell
571 various GNU utilities what to do with backup files, Emacs also obeys the
572 environment variable by setting the Lisp variable @code{version-control}
573 accordingly at startup. If the environment variable's value is @samp{t}
574 or @samp{numbered}, then @code{version-control} becomes @code{t}; if the
575 value is @samp{nil} or @samp{existing}, then @code{version-control}
576 becomes @code{nil}; if it is @samp{never} or @samp{simple}, then
577 @code{version-control} becomes @code{never}.
578
579 @vindex backup-directory-alist
580 You can customize the variable @code{backup-directory-alist} to
581 specify that files matching certain patterns should be backed up in
582 specific directories. This variable applies to both single and
583 numbered backups. A typical use is to add an element @code{("."
584 . @var{dir})} to make all backups in the directory with absolute name
585 @var{dir}; Emacs modifies the backup file names to avoid clashes
586 between files with the same names originating in different
587 directories. Alternatively, adding, @code{("." . ".~")} would make
588 backups in the invisible subdirectory @file{.~} of the original file's
589 directory. Emacs creates the directory, if necessary, to make the
590 backup.
591
592 @vindex make-backup-file-name-function
593 If you define the variable @code{make-backup-file-name-function} to
594 a suitable Lisp function, that overrides the usual way Emacs
595 constructs backup file names.
596
597 @node Backup Deletion
598 @subsubsection Automatic Deletion of Backups
599
600 To prevent excessive consumption of disk space, Emacs can delete numbered
601 backup versions automatically. Generally Emacs keeps the first few backups
602 and the latest few backups, deleting any in between. This happens every
603 time a new backup is made.
604
605 @vindex kept-old-versions
606 @vindex kept-new-versions
607 The two variables @code{kept-old-versions} and
608 @code{kept-new-versions} control this deletion. Their values are,
609 respectively, the number of oldest (lowest-numbered) backups to keep
610 and the number of newest (highest-numbered) ones to keep, each time a
611 new backup is made. The backups in the middle (excluding those oldest
612 and newest) are the excess middle versions---those backups are
613 deleted. These variables' values are used when it is time to delete
614 excess versions, just after a new backup version is made; the newly
615 made backup is included in the count in @code{kept-new-versions}. By
616 default, both variables are 2.
617
618 @vindex delete-old-versions
619 If @code{delete-old-versions} is @code{t}, Emacs deletes the excess
620 backup files silently. If it is @code{nil}, the default, Emacs asks
621 you whether it should delete the excess backup versions. If it has
622 any other value, then Emacs never automatically deletes backups.
623
624 Dired's @kbd{.} (Period) command can also be used to delete old versions.
625 @xref{Dired Deletion}.
626
627 @node Backup Copying
628 @subsubsection Copying vs.@: Renaming
629
630 Backup files can be made by copying the old file or by renaming it.
631 This makes a difference when the old file has multiple names (hard
632 links). If the old file is renamed into the backup file, then the
633 alternate names become names for the backup file. If the old file is
634 copied instead, then the alternate names remain names for the file
635 that you are editing, and the contents accessed by those names will be
636 the new contents.
637
638 The method of making a backup file may also affect the file's owner
639 and group. If copying is used, these do not change. If renaming is used,
640 you become the file's owner, and the file's group becomes the default
641 (different operating systems have different defaults for the group).
642
643 @vindex backup-by-copying
644 @vindex backup-by-copying-when-linked
645 @vindex backup-by-copying-when-mismatch
646 @vindex backup-by-copying-when-privileged-mismatch
647 @cindex file ownership, and backup
648 @cindex backup, and user-id
649 The choice of renaming or copying is made as follows:
650
651 @itemize
652 @item
653 If the variable @code{backup-by-copying} is non-@code{nil} (the
654 default is @code{nil}), use copying.
655
656 @item
657 Otherwise, if the variable @code{backup-by-copying-when-linked} is
658 non-@code{nil} (the default is @code{nil}), and the file has multiple
659 names, use copying.
660
661 @item
662 Otherwise, if the variable @code{backup-by-copying-when-mismatch} is
663 non-@code{nil} (the default is @code{t}), and renaming would change
664 the file's owner or group, use copying.
665
666 If you change @code{backup-by-copying-when-mismatch} to @code{nil},
667 Emacs checks the numeric user-id of the file's owner. If this is
668 higher than @code{backup-by-copying-when-privileged-mismatch}, then it
669 behaves as though @code{backup-by-copying-when-mismatch} is
670 non-@code{nil} anyway.
671
672 @item
673 Otherwise, renaming is the default choice.
674 @end itemize
675
676 When a file is managed with a version control system (@pxref{Version
677 Control}), Emacs does not normally make backups in the usual way for
678 that file. But check-in and check-out are similar in some ways to
679 making backups. One unfortunate similarity is that these operations
680 typically break hard links, disconnecting the file name you visited from
681 any alternate names for the same file. This has nothing to do with
682 Emacs---the version control system does it.
683
684 @node Customize Save
685 @subsection Customizing Saving of Files
686
687 @vindex require-final-newline
688 If the value of the variable @code{require-final-newline} is
689 @code{t}, saving or writing a file silently puts a newline at the end
690 if there isn't already one there. If the value is @code{visit}, Emacs
691 adds a newline at the end of any file that doesn't have one, just
692 after it visits the file. (This marks the buffer as modified, and you
693 can undo it.) If the value is @code{visit-save}, Emacs adds such
694 newlines both on visiting and on saving. If the value is @code{nil},
695 Emacs leaves the end of the file unchanged; any other non-@code{nil}
696 value means to asks you whether to add a newline. The default is
697 @code{nil}.
698
699 @vindex mode-require-final-newline
700 Some major modes are designed for specific kinds of files that are
701 always supposed to end in newlines. Such major modes set the variable
702 @code{require-final-newline} to the value of
703 @code{mode-require-final-newline}, which defaults to @code{t}. By
704 setting the latter variable, you can control how these modes handle
705 final newlines.
706
707 @vindex write-region-inhibit-fsync
708 When Emacs saves a file, it invokes the @code{fsync} system call to
709 force the data immediately out to disk. This is important for safety
710 if the system crashes or in case of power outage. However, it can be
711 disruptive on laptops using power saving, as it may force a disk
712 spin-up each time you save a file. If you accept an increased risk of
713 data loss, you can set @code{write-region-inhibit-fsync} to a
714 non-@code{nil} value to disable the synchronization.
715
716 @node Interlocking
717 @subsection Protection against Simultaneous Editing
718
719 @cindex file dates
720 @cindex simultaneous editing
721 Simultaneous editing occurs when two users visit the same file, both
722 make changes, and then both save them. If nobody is informed that
723 this is happening, whichever user saves first would later find that
724 his changes were lost.
725
726 On some systems, Emacs notices immediately when the second user starts
727 to change the file, and issues an immediate warning. On all systems,
728 Emacs checks when you save the file, and warns if you are about to
729 overwrite another user's changes. You can prevent loss of the other
730 user's work by taking the proper corrective action instead of saving the
731 file.
732
733 @findex ask-user-about-lock
734 @cindex locking files
735 When you make the first modification in an Emacs buffer that is
736 visiting a file, Emacs records that the file is @dfn{locked} by you.
737 (It does this by creating a specially-named symbolic link in the same
738 directory.) Emacs removes the lock when you save the changes. The
739 idea is that the file is locked whenever an Emacs buffer visiting it
740 has unsaved changes.
741
742 @cindex collision
743 If you begin to modify the buffer while the visited file is locked by
744 someone else, this constitutes a @dfn{collision}. When Emacs detects a
745 collision, it asks you what to do, by calling the Lisp function
746 @code{ask-user-about-lock}. You can redefine this function for the sake
747 of customization. The standard definition of this function asks you a
748 question and accepts three possible answers:
749
750 @table @kbd
751 @item s
752 Steal the lock. Whoever was already changing the file loses the lock,
753 and you gain the lock.
754 @item p
755 Proceed. Go ahead and edit the file despite its being locked by someone else.
756 @item q
757 Quit. This causes an error (@code{file-locked}), and the buffer
758 contents remain unchanged---the modification you were trying to make
759 does not actually take place.
760 @end table
761
762 If Emacs or the operating system crashes, this may leave behind lock
763 files which are stale, so you may occasionally get warnings about
764 spurious collisions. When you determine that the collision is
765 spurious, just use @kbd{p} to tell Emacs to go ahead anyway.
766
767 Note that locking works on the basis of a file name; if a file has
768 multiple names, Emacs does not prevent two users from editing it
769 simultaneously under different names.
770
771 A lock file cannot be written in some circumstances, e.g. if Emacs
772 lacks the system permissions or the system does not support symbolic
773 links. In these cases, Emacs can still detect the collision when you
774 try to save a file, by checking the file's last-modification date. If
775 the file has changed since the last time Emacs visited or saved it,
776 that implies that changes have been made in some other way, and will
777 be lost if Emacs proceeds with saving. Emacs then displays a warning
778 message and asks for confirmation before saving; answer @kbd{yes} to
779 save, and @kbd{no} or @kbd{C-g} cancel the save.
780
781 If you are notified that simultaneous editing has already taken
782 place, one way to compare the buffer to its file is the @kbd{M-x
783 diff-buffer-with-file} command. @xref{Comparing Files}.
784
785 @node File Shadowing
786 @subsection Shadowing Files
787 @cindex shadow files
788 @cindex file shadows
789 @findex shadow-initialize
790
791 @table @kbd
792 @item M-x shadow-initialize
793 Set up file shadowing.
794 @item M-x shadow-define-literal-group
795 Declare a single file to be shared between sites.
796 @item M-x shadow-define-regexp-group
797 Make all files that match each of a group of files be shared between hosts.
798 @item M-x shadow-define-cluster @key{RET} @var{name} @key{RET}
799 Define a shadow file cluster @var{name}.
800 @item M-x shadow-copy-files
801 Copy all pending shadow files.
802 @item M-x shadow-cancel
803 Cancel the instruction to shadow some files.
804 @end table
805
806 You can arrange to keep identical @dfn{shadow} copies of certain files
807 in more than one place---possibly on different machines. To do this,
808 first you must set up a @dfn{shadow file group}, which is a set of
809 identically-named files shared between a list of sites. The file
810 group is permanent and applies to further Emacs sessions as well as
811 the current one. Once the group is set up, every time you exit Emacs,
812 it will copy the file you edited to the other files in its group. You
813 can also do the copying without exiting Emacs, by typing @kbd{M-x
814 shadow-copy-files}.
815
816 To set up a shadow file group, use @kbd{M-x
817 shadow-define-literal-group} or @kbd{M-x shadow-define-regexp-group}.
818 See their documentation strings for further information.
819
820 Before copying a file to its shadows, Emacs asks for confirmation.
821 You can answer ``no'' to bypass copying of this file, this time. If
822 you want to cancel the shadowing permanently for a certain file, use
823 @kbd{M-x shadow-cancel} to eliminate or change the shadow file group.
824
825 A @dfn{shadow cluster} is a group of hosts that share directories, so
826 that copying to or from one of them is sufficient to update the file
827 on all of them. Each shadow cluster has a name, and specifies the
828 network address of a primary host (the one we copy files to), and a
829 regular expression that matches the host names of all the other hosts
830 in the cluster. You can define a shadow cluster with @kbd{M-x
831 shadow-define-cluster}.
832
833 @node Time Stamps
834 @subsection Updating Time Stamps Automatically
835 @cindex time stamps
836 @cindex modification dates
837 @cindex locale, date format
838
839 You can arrange to put a time stamp in a file, so that it is updated
840 automatically each time you edit and save the file. The time stamp
841 must be in the first eight lines of the file, and you should insert it
842 like this:
843
844 @example
845 Time-stamp: <>
846 @end example
847
848 @noindent
849 or like this:
850
851 @example
852 Time-stamp: " "
853 @end example
854
855 @findex time-stamp
856 Then add the function @code{time-stamp} to the hook
857 @code{before-save-hook} (@pxref{Hooks}). When you save the file, this
858 function then automatically updates the time stamp with the current
859 date and time. You can also use the command @kbd{M-x time-stamp} to
860 update the time stamp manually. For other customizations, see the
861 Custom group @code{time-stamp}. Note that the time stamp is formatted
862 according to your locale setting (@pxref{Environment}).
863
864 @node Reverting
865 @section Reverting a Buffer
866 @findex revert-buffer
867 @cindex drastic changes
868 @cindex reread a file
869
870 If you have made extensive changes to a file-visiting buffer and
871 then change your mind, you can @dfn{revert} the changes and go back to
872 the saved version of the file. To do this, type @kbd{M-x
873 revert-buffer}. Since reverting unintentionally could lose a lot of
874 work, Emacs asks for confirmation first.
875
876 The @code{revert-buffer} command tries to position point in such a
877 way that, if the file was edited only slightly, you will be at
878 approximately the same part of the text as before. But if you have
879 made major changes, point may end up in a totally different location.
880
881 Reverting marks the buffer as ``not modified''. It also clears the
882 buffer's undo history (@pxref{Undo}). Thus, the reversion cannot be
883 undone---if you change your mind yet again, you can't use the undo
884 commands to bring the reverted changes back.
885
886 Some kinds of buffers that are not associated with files, such as
887 Dired buffers, can also be reverted. For them, reverting means
888 recalculating their contents. Buffers created explicitly with
889 @kbd{C-x b} cannot be reverted; @code{revert-buffer} reports an error
890 if you try.
891
892 @vindex revert-without-query
893 When you edit a file that changes automatically and frequently---for
894 example, a log of output from a process that continues to run---it may
895 be useful for Emacs to revert the file without querying you. To
896 request this behavior, set the variable @code{revert-without-query} to
897 a list of regular expressions. When a file name matches one of these
898 regular expressions, @code{find-file} and @code{revert-buffer} will
899 revert it automatically if it has changed---provided the buffer itself
900 is not modified. (If you have edited the text, it would be wrong to
901 discard your changes.)
902
903 @cindex Global Auto-Revert mode
904 @cindex mode, Global Auto-Revert
905 @cindex Auto-Revert mode
906 @cindex mode, Auto-Revert
907 @findex global-auto-revert-mode
908 @findex auto-revert-mode
909 @findex auto-revert-tail-mode
910 @vindex auto-revert-interval
911 You can also tell Emacs to revert buffers periodically. To do this
912 for a specific buffer, enable the minor mode Auto-Revert mode by
913 typing @kbd{M-x auto-revert-mode}. This automatically reverts the
914 current buffer every five seconds; you can change the interval through
915 the variable @code{auto-revert-interval}. To do the same for all file
916 buffers, type @kbd{M-x global-auto-revert-mode} to enable Global
917 Auto-Revert mode. These minor modes do not check or revert remote
918 files, because that is usually too slow.
919
920 One use of Auto-Revert mode is to ``tail'' a file such as a system
921 log, so that changes made to that file by other programs are
922 continuously displayed. To do this, just move the point to the end of
923 the buffer, and it will stay there as the file contents change.
924 However, if you are sure that the file will only change by growing at
925 the end, use Auto-Revert Tail mode instead
926 (@code{auto-revert-tail-mode}). It is more efficient for this.
927 Auto-Revert Tail mode works also for remote files.
928
929 @xref{VC Undo}, for commands to revert to earlier versions of files
930 under version control. @xref{VC Mode Line}, for Auto Revert
931 peculiarities when visiting files under version control.
932
933 @ifnottex
934 @include arevert-xtra.texi
935 @end ifnottex
936
937 @node Auto Save
938 @section Auto-Saving: Protection Against Disasters
939 @cindex Auto Save mode
940 @cindex mode, Auto Save
941 @cindex crashes
942
943 From time to time, Emacs automatically saves each visited file in a
944 separate file, without altering the file you actually use. This is
945 called @dfn{auto-saving}. It prevents you from losing more than a
946 limited amount of work if the system crashes.
947
948 When Emacs determines that it is time for auto-saving, it considers
949 each buffer, and each is auto-saved if auto-saving is enabled for it
950 and it has been changed since the last time it was auto-saved. The
951 message @samp{Auto-saving...} is displayed in the echo area during
952 auto-saving, if any files are actually auto-saved. Errors occurring
953 during auto-saving are caught so that they do not interfere with the
954 execution of commands you have been typing.
955
956 @menu
957 * Files: Auto Save Files. The file where auto-saved changes are
958 actually made until you save the file.
959 * Control: Auto Save Control. Controlling when and how often to auto-save.
960 * Recover:: Recovering text from auto-save files.
961 @end menu
962
963 @node Auto Save Files
964 @subsection Auto-Save Files
965
966 Auto-saving does not normally save in the files that you visited,
967 because it can be very undesirable to save a change that you did not
968 want to make permanent. Instead, auto-saving is done in a different
969 file called the @dfn{auto-save file}, and the visited file is changed
970 only when you request saving explicitly (such as with @kbd{C-x C-s}).
971
972 Normally, the auto-save file name is made by appending @samp{#} to the
973 front and rear of the visited file name. Thus, a buffer visiting file
974 @file{foo.c} is auto-saved in a file @file{#foo.c#}. Most buffers that
975 are not visiting files are auto-saved only if you request it explicitly;
976 when they are auto-saved, the auto-save file name is made by appending
977 @samp{#} to the front and rear of buffer name, then
978 adding digits and letters at the end for uniqueness. For
979 example, the @samp{*mail*} buffer in which you compose messages to be
980 sent might be auto-saved in a file named @file{#*mail*#704juu}. Auto-save file
981 names are made this way unless you reprogram parts of Emacs to do
982 something different (the functions @code{make-auto-save-file-name} and
983 @code{auto-save-file-name-p}). The file name to be used for auto-saving
984 in a buffer is calculated when auto-saving is turned on in that buffer.
985
986 @cindex auto-save for remote files
987 @vindex auto-save-file-name-transforms
988 The variable @code{auto-save-file-name-transforms} allows a degree
989 of control over the auto-save file name. It lets you specify a series
990 of regular expressions and replacements to transform the auto save
991 file name. The default value puts the auto-save files for remote
992 files (@pxref{Remote Files}) into the temporary file directory on the
993 local machine.
994
995 When you delete a substantial part of the text in a large buffer, auto
996 save turns off temporarily in that buffer. This is because if you
997 deleted the text unintentionally, you might find the auto-save file more
998 useful if it contains the deleted text. To reenable auto-saving after
999 this happens, save the buffer with @kbd{C-x C-s}, or use @kbd{C-u 1 M-x
1000 auto-save-mode}.
1001
1002 @vindex auto-save-visited-file-name
1003 If you want auto-saving to be done in the visited file rather than
1004 in a separate auto-save file, set the variable
1005 @code{auto-save-visited-file-name} to a non-@code{nil} value. In this
1006 mode, there is no real difference between auto-saving and explicit
1007 saving.
1008
1009 @vindex delete-auto-save-files
1010 A buffer's auto-save file is deleted when you save the buffer in its
1011 visited file. (You can inhibit this by setting the variable
1012 @code{delete-auto-save-files} to @code{nil}.) Changing the visited
1013 file name with @kbd{C-x C-w} or @code{set-visited-file-name} renames
1014 any auto-save file to go with the new visited name.
1015
1016 @node Auto Save Control
1017 @subsection Controlling Auto-Saving
1018
1019 @vindex auto-save-default
1020 @findex auto-save-mode
1021 Each time you visit a file, auto-saving is turned on for that file's
1022 buffer if the variable @code{auto-save-default} is non-@code{nil} (but
1023 not in batch mode; @pxref{Initial Options}). The default for this
1024 variable is @code{t}, so auto-saving is the usual practice for
1025 file-visiting buffers. To toggle auto-saving in the current buffer,
1026 type @kbd{M-x auto-save-mode}. Auto Save mode acts as a buffer-local
1027 minor mode (@pxref{Minor Modes}).
1028
1029 @vindex auto-save-interval
1030 Emacs auto-saves periodically based on how many characters you have
1031 typed since the last auto-save. The variable
1032 @code{auto-save-interval} specifies how many characters there are
1033 between auto-saves. By default, it is 300. Emacs doesn't accept
1034 values that are too small: if you customize @code{auto-save-interval}
1035 to a value less than 20, Emacs will behave as if the value is 20.
1036
1037 @vindex auto-save-timeout
1038 Auto-saving also takes place when you stop typing for a while. By
1039 default, it does this after 30 seconds of idleness (at this time,
1040 Emacs may also perform garbage collection; @pxref{Garbage
1041 Collection,,, elisp, The Emacs Lisp Reference Manual}). To change
1042 this interval, customize the variable @code{auto-save-timeout}. The
1043 actual time period is longer if the current buffer is long; this is a
1044 heuristic which aims to keep out of your way when you are editing long
1045 buffers, in which auto-save takes an appreciable amount of time.
1046 Auto-saving during idle periods accomplishes two things: first, it
1047 makes sure all your work is saved if you go away from the terminal for
1048 a while; second, it may avoid some auto-saving while you are actually
1049 typing.
1050
1051 Emacs also does auto-saving whenever it gets a fatal error. This
1052 includes killing the Emacs job with a shell command such as @samp{kill
1053 %emacs}, or disconnecting a phone line or network connection.
1054
1055 @findex do-auto-save
1056 You can perform an auto-save explicitly with the command @kbd{M-x
1057 do-auto-save}.
1058
1059 @node Recover
1060 @subsection Recovering Data from Auto-Saves
1061
1062 @findex recover-file
1063 You can use the contents of an auto-save file to recover from a loss
1064 of data with the command @kbd{M-x recover-file @key{RET} @var{file}
1065 @key{RET}}. This visits @var{file} and then (after your confirmation)
1066 restores the contents from its auto-save file @file{#@var{file}#}.
1067 You can then save with @kbd{C-x C-s} to put the recovered text into
1068 @var{file} itself. For example, to recover file @file{foo.c} from its
1069 auto-save file @file{#foo.c#}, do:@refill
1070
1071 @example
1072 M-x recover-file @key{RET} foo.c @key{RET}
1073 yes @key{RET}
1074 C-x C-s
1075 @end example
1076
1077 Before asking for confirmation, @kbd{M-x recover-file} displays a
1078 directory listing describing the specified file and the auto-save file,
1079 so you can compare their sizes and dates. If the auto-save file
1080 is older, @kbd{M-x recover-file} does not offer to read it.
1081
1082 @findex recover-session
1083 If Emacs or the computer crashes, you can recover all the files you
1084 were editing from their auto save files with the command @kbd{M-x
1085 recover-session}. This first shows you a list of recorded interrupted
1086 sessions. Move point to the one you choose, and type @kbd{C-c C-c}.
1087
1088 Then @code{recover-session} asks about each of the files that were
1089 being edited during that session, asking whether to recover that file.
1090 If you answer @kbd{y}, it calls @code{recover-file}, which works in its
1091 normal fashion. It shows the dates of the original file and its
1092 auto-save file, and asks once again whether to recover that file.
1093
1094 When @code{recover-session} is done, the files you've chosen to
1095 recover are present in Emacs buffers. You should then save them. Only
1096 this---saving them---updates the files themselves.
1097
1098 @vindex auto-save-list-file-prefix
1099 Emacs records information about interrupted sessions for later
1100 recovery in files named @file{.saves-@var{pid}-@var{hostname}} in the
1101 directory @file{~/.emacs.d/auto-save-list/}. This directory is
1102 determined by the variable @code{auto-save-list-file-prefix}. If you
1103 set @code{auto-save-list-file-prefix} to @code{nil}, sessions are not
1104 recorded for recovery.
1105
1106 @node File Aliases
1107 @section File Name Aliases
1108 @cindex symbolic links (visiting)
1109 @cindex hard links (visiting)
1110
1111 Symbolic links and hard links both make it possible for several file
1112 names to refer to the same file. Hard links are alternate names that
1113 refer directly to the file; all the names are equally valid, and no one
1114 of them is preferred. By contrast, a symbolic link is a kind of defined
1115 alias: when @file{foo} is a symbolic link to @file{bar}, you can use
1116 either name to refer to the file, but @file{bar} is the real name, while
1117 @file{foo} is just an alias. More complex cases occur when symbolic
1118 links point to directories.
1119
1120 @vindex find-file-existing-other-name
1121 @vindex find-file-suppress-same-file-warnings
1122 Normally, if you visit a file which Emacs is already visiting under
1123 a different name, Emacs displays a message in the echo area and uses
1124 the existing buffer visiting that file. This can happen on systems
1125 that support hard or symbolic links, or if you use a long file name on
1126 a system that truncates long file names, or on a case-insensitive file
1127 system. You can suppress the message by setting the variable
1128 @code{find-file-suppress-same-file-warnings} to a non-@code{nil}
1129 value. You can disable this feature entirely by setting the variable
1130 @code{find-file-existing-other-name} to @code{nil}: then if you visit
1131 the same file under two different names, you get a separate buffer for
1132 each file name.
1133
1134 @vindex find-file-visit-truename
1135 @cindex truenames of files
1136 @cindex file truenames
1137 If the variable @code{find-file-visit-truename} is non-@code{nil},
1138 then the file name recorded for a buffer is the file's @dfn{truename}
1139 (made by replacing all symbolic links with their target names), rather
1140 than the name you specify. Setting @code{find-file-visit-truename} also
1141 implies the effect of @code{find-file-existing-other-name}.
1142
1143 @cindex directory name abbreviation
1144 @vindex directory-abbrev-alist
1145 Sometimes, a directory is ordinarily accessed through a symbolic
1146 link, and you may want Emacs to preferentially show its ``linked''
1147 name. To do this, customize @code{directory-abbrev-alist}. Each
1148 element in this list should have the form @code{(@var{from}
1149 . @var{to})}, which means to replace @var{from} with @var{to} whenever
1150 @var{from} appears in a directory name. The @var{from} string is a
1151 regular expression (@pxref{Regexps}). It is matched against directory
1152 names anchored at the first character, and should start with @samp{\`}
1153 (to support directory names with embedded newlines, which would defeat
1154 @samp{^}). The @var{to} string should be an ordinary absolute
1155 directory name pointing to the same directory. Do not use @samp{~} to
1156 stand for a home directory in the @var{to} string; Emacs performs
1157 these substitutions separately. Here's an example, from a system on
1158 which @file{/home/fsf} is normally accessed through a symbolic link
1159 named @file{/fsf}:
1160
1161 @example
1162 (("\\`/home/fsf" . "/fsf"))
1163 @end example
1164
1165 @node Directories
1166 @section File Directories
1167
1168 @cindex file directory
1169 @cindex directory listing
1170 The file system groups files into @dfn{directories}. A @dfn{directory
1171 listing} is a list of all the files in a directory. Emacs provides
1172 commands to create and delete directories, and to make directory
1173 listings in brief format (file names only) and verbose format (sizes,
1174 dates, and authors included). Emacs also includes a directory browser
1175 feature called Dired; see @ref{Dired}.
1176
1177 @table @kbd
1178 @item C-x C-d @var{dir-or-pattern} @key{RET}
1179 Display a brief directory listing (@code{list-directory}).
1180 @item C-u C-x C-d @var{dir-or-pattern} @key{RET}
1181 Display a verbose directory listing.
1182 @item M-x make-directory @key{RET} @var{dirname} @key{RET}
1183 Create a new directory named @var{dirname}.
1184 @item M-x delete-directory @key{RET} @var{dirname} @key{RET}
1185 Delete the directory named @var{dirname}. If it isn't empty,
1186 you will be asked whether you want to delete it recursively.
1187 @end table
1188
1189 @findex list-directory
1190 @kindex C-x C-d
1191 The command to display a directory listing is @kbd{C-x C-d}
1192 (@code{list-directory}). It reads using the minibuffer a file name
1193 which is either a directory to be listed or a wildcard-containing
1194 pattern for the files to be listed. For example,
1195
1196 @example
1197 C-x C-d /u2/emacs/etc @key{RET}
1198 @end example
1199
1200 @noindent
1201 lists all the files in directory @file{/u2/emacs/etc}. Here is an
1202 example of specifying a file name pattern:
1203
1204 @example
1205 C-x C-d /u2/emacs/src/*.c @key{RET}
1206 @end example
1207
1208 Normally, @kbd{C-x C-d} displays a brief directory listing containing
1209 just file names. A numeric argument (regardless of value) tells it to
1210 make a verbose listing including sizes, dates, and owners (like
1211 @samp{ls -l}).
1212
1213 @vindex list-directory-brief-switches
1214 @vindex list-directory-verbose-switches
1215 The text of a directory listing is mostly obtained by running
1216 @code{ls} in an inferior process. Two Emacs variables control the
1217 switches passed to @code{ls}: @code{list-directory-brief-switches} is
1218 a string giving the switches to use in brief listings (@code{"-CF"} by
1219 default), and @code{list-directory-verbose-switches} is a string
1220 giving the switches to use in a verbose listing (@code{"-l"} by
1221 default).
1222
1223 @vindex directory-free-space-program
1224 @vindex directory-free-space-args
1225 In verbose directory listings, Emacs adds information about the
1226 amount of free space on the disk that contains the directory. To do
1227 this, it runs the program specified by
1228 @code{directory-free-space-program} with arguments
1229 @code{directory-free-space-args}.
1230
1231 The command @kbd{M-x delete-directory} prompts for a directory name
1232 using the minibuffer, and deletes the directory if it is empty. If
1233 the directory is not empty, you will be asked whether you want to
1234 delete it recursively. On systems that have a ``Trash'' (or ``Recycle
1235 Bin'') feature, you can make this command move the specified directory
1236 to the Trash instead of deleting it outright, by changing the variable
1237 @code{delete-by-moving-to-trash} to @code{t}. @xref{Misc File Ops},
1238 for more information about using the Trash.
1239
1240 @node Comparing Files
1241 @section Comparing Files
1242 @cindex comparing files
1243
1244 @findex diff
1245 @vindex diff-switches
1246 The command @kbd{M-x diff} prompts for two file names, using the
1247 minibuffer, and displays the differences between the two files in a
1248 buffer named @samp{*diff*}. This works by running the @command{diff}
1249 program, using options taken from the variable @code{diff-switches}.
1250 The value of @code{diff-switches} should be a string; the default is
1251 @code{"-c"} to specify a context diff. @xref{Top,, Diff, diff,
1252 Comparing and Merging Files}, for more information about the
1253 @command{diff} program.
1254
1255 The output of the @code{diff} command is shown using a major mode
1256 called Diff mode. @xref{Diff Mode}.
1257
1258 @findex diff-backup
1259 The command @kbd{M-x diff-backup} compares a specified file with its
1260 most recent backup. If you specify the name of a backup file,
1261 @code{diff-backup} compares it with the source file that it is a
1262 backup of. In all other respects, this behaves like @kbd{M-x diff}.
1263
1264 @findex diff-buffer-with-file
1265 The command @kbd{M-x diff-buffer-with-file} compares a specified
1266 buffer with its corresponding file. This shows you what changes you
1267 would make to the file if you save the buffer.
1268
1269 @findex compare-windows
1270 The command @kbd{M-x compare-windows} compares the text in the
1271 current window with that in the next window. (For more information
1272 about windows in Emacs, @ref{Windows}.) Comparison starts at point in
1273 each window, after pushing each initial point value on the mark ring
1274 in its respective buffer. Then it moves point forward in each window,
1275 one character at a time, until it reaches characters that don't match.
1276 Then the command exits.
1277
1278 If point in the two windows is followed by non-matching text when
1279 the command starts, @kbd{M-x compare-windows} tries heuristically to
1280 advance up to matching text in the two windows, and then exits. So if
1281 you use @kbd{M-x compare-windows} repeatedly, each time it either
1282 skips one matching range or finds the start of another.
1283
1284 @vindex compare-ignore-case
1285 @vindex compare-ignore-whitespace
1286 With a numeric argument, @code{compare-windows} ignores changes in
1287 whitespace. If the variable @code{compare-ignore-case} is
1288 non-@code{nil}, the comparison ignores differences in case as well.
1289 If the variable @code{compare-ignore-whitespace} is non-@code{nil},
1290 @code{compare-windows} normally ignores changes in whitespace, and a
1291 prefix argument turns that off.
1292
1293 @cindex Smerge mode
1294 @findex smerge-mode
1295 @cindex failed merges
1296 @cindex merges, failed
1297 @cindex comparing 3 files (@code{diff3})
1298 You can use @kbd{M-x smerge-mode} to turn on Smerge mode, a minor
1299 mode for editing output from the @command{diff3} program. This is
1300 typically the result of a failed merge from a version control system
1301 ``update'' outside VC, due to conflicting changes to a file. Smerge
1302 mode provides commands to resolve conflicts by selecting specific
1303 changes.
1304
1305 @iftex
1306 @xref{Emerge,,, emacs-xtra, Specialized Emacs Features},
1307 @end iftex
1308 @ifnottex
1309 @xref{Emerge},
1310 @end ifnottex
1311 for the Emerge facility, which provides a powerful interface for
1312 merging files.
1313
1314 @node Diff Mode
1315 @section Diff Mode
1316 @cindex Diff mode
1317 @findex diff-mode
1318 @cindex patches, editing
1319
1320 Diff mode is a major mode used for the output of @kbd{M-x diff} and
1321 other similar commands. This kind of output is called a @dfn{patch},
1322 because it can be passed to the @command{patch} command to
1323 automatically apply the specified changes. To select Diff mode
1324 manually, type @kbd{M-x diff-mode}.
1325
1326 @cindex hunk, diff
1327 The changes specified in a patch are grouped into @dfn{hunks}, which
1328 are contiguous chunks of text that contain one or more changed lines.
1329 Hunks can also include unchanged lines to provide context for the
1330 changes. Each hunk is preceded by a @dfn{hunk header}, which
1331 specifies the old and new line numbers at which the hunk occurs. Diff
1332 mode highlights each hunk header, to distinguish it from the actual
1333 contents of the hunk.
1334
1335 @vindex diff-update-on-the-fly
1336 You can edit a Diff mode buffer like any other buffer. (If it is
1337 read-only, you need to make it writable first. @xref{Misc Buffer}.)
1338 Whenever you change a hunk, Diff mode attempts to automatically
1339 correct the line numbers in the hunk headers, to ensure that the diff
1340 remains ``correct''. To disable automatic line number correction,
1341 change the variable @code{diff-update-on-the-fly} to @code{nil}.
1342
1343 Diff mode treats each hunk as an ``error message,'' similar to
1344 Compilation mode. Thus, you can use commands such as @kbd{C-x '} to
1345 visit the corresponding source locations. @xref{Compilation Mode}.
1346
1347 In addition, Diff mode provides the following commands to navigate,
1348 manipulate and apply parts of patches:
1349
1350 @table @kbd
1351 @item M-n
1352 @findex diff-hunk-next
1353 Move to the next hunk-start (@code{diff-hunk-next}).
1354
1355 @findex diff-auto-refine-mode
1356 @cindex mode, Diff Auto-Refine
1357 @cindex Diff Auto-Refine mode
1358 This command has a side effect: it @dfn{refines} the hunk you move to,
1359 highlighting its changes with better granularity. To disable this
1360 feature, type @kbd{M-x diff-auto-refine-mode} to toggle off the minor
1361 mode Diff Auto-Refine mode. To disable Diff Auto Refine mode by
1362 default, add this to your init file (@pxref{Hooks}):
1363
1364 @example
1365 (add-hook 'diff-mode-hook
1366 (lambda () (diff-auto-refine-mode -1)))
1367 @end example
1368
1369 @item M-p
1370 @findex diff-hunk-prev
1371 Move to the previous hunk-start (@code{diff-hunk-prev}). Like
1372 @kbd{M-n}, this has the side-effect of refining the hunk you move to,
1373 unless you disable Diff Auto-Refine mode.
1374
1375 @item M-@}
1376 @findex diff-file-next
1377 Move to the next file-start, in a multi-file patch
1378 (@code{diff-file-next}).
1379
1380 @item M-@{
1381 @findex diff-file-prev
1382 Move to the previous file-start, in a multi-file patch
1383 (@code{diff-file-prev}).
1384
1385 @item M-k
1386 @findex diff-hunk-kill
1387 Kill the hunk at point (@code{diff-hunk-kill}).
1388
1389 @item M-K
1390 @findex diff-file-kill
1391 In a multi-file patch, kill the current file part.
1392 (@code{diff-file-kill}).
1393
1394 @item C-c C-a
1395 @findex diff-apply-hunk
1396 Apply this hunk to its target file (@code{diff-apply-hunk}). With a
1397 prefix argument of @kbd{C-u}, revert this hunk.
1398
1399 @item C-c C-b
1400 @findex diff-refine-hunk
1401 Highlight the changes of the hunk at point with a finer granularity
1402 (@code{diff-refine-hunk}). This allows you to see exactly which parts
1403 of each changed line were actually changed.
1404
1405 @item C-c C-c
1406 @findex diff-goto-source
1407 Go to the source file and line corresponding to this hunk
1408 (@code{diff-goto-source}).
1409
1410 @item C-c C-e
1411 @findex diff-ediff-patch
1412 Start an Ediff session with the patch (@code{diff-ediff-patch}).
1413 @xref{Top, Ediff, Ediff, ediff, The Ediff Manual}.
1414
1415 @item C-c C-n
1416 @findex diff-restrict-view
1417 Restrict the view to the current hunk (@code{diff-restrict-view}).
1418 @xref{Narrowing}. With a prefix argument of @kbd{C-u}, restrict the
1419 view to the current file of a multiple-file patch. To widen again,
1420 use @kbd{C-x n w} (@code{widen}).
1421
1422 @item C-c C-r
1423 @findex diff-reverse-direction
1424 Reverse the direction of comparison for the entire buffer
1425 (@code{diff-reverse-direction}).
1426
1427 @item C-c C-s
1428 @findex diff-split-hunk
1429 Split the hunk at point (@code{diff-split-hunk}). This is for
1430 manually editing patches, and only works with the @dfn{unified diff
1431 format} produced by the @option{-u} or @option{--unified} options to
1432 the @command{diff} program. If you need to split a hunk in the
1433 @dfn{context diff format} produced by the @option{-c} or
1434 @option{--context} options to @command{diff}, first convert the buffer
1435 to the unified diff format with @kbd{C-c C-u}.
1436
1437 @item C-c C-d
1438 @findex diff-unified->context
1439 Convert the entire buffer to the @dfn{context diff format}
1440 (@code{diff-unified->context}). With a prefix argument, convert only
1441 the text within the region.
1442
1443 @item C-c C-u
1444 @findex diff-context->unified
1445 Convert the entire buffer to unified diff format
1446 (@code{diff-context->unified}). With a prefix argument, convert
1447 unified format to context format. When the mark is active, convert
1448 only the text within the region.
1449
1450 @item C-c C-w
1451 @findex diff-refine-hunk
1452 Refine the current hunk so that it disregards changes in whitespace
1453 (@code{diff-refine-hunk}).
1454
1455 @item C-x 4 A
1456 @findex diff-add-change-log-entries-other-window
1457 @findex add-change-log-entry-other-window@r{, in Diff mode}
1458 Generate a ChangeLog entry, like @kbd{C-x 4 a} does (@pxref{Change
1459 Log}), for each one of the hunks
1460 (@code{diff-add-change-log-entries-other-window}). This creates a
1461 skeleton of the log of changes that you can later fill with the actual
1462 descriptions of the changes. @kbd{C-x 4 a} itself in Diff mode
1463 operates on behalf of the current hunk's file, but gets the function
1464 name from the patch itself. This is useful for making log entries for
1465 functions that are deleted by the patch.
1466 @end table
1467
1468 By default, Diff mode highlights trailing whitespace on modified
1469 lines, so that they are more obvious. This is done by enabling
1470 Whitespace mode in the Diff buffer (@pxref{Useless Whitespace}). Diff
1471 mode buffers are set up so that Whitespace mode avoids highlighting
1472 trailing whitespace occurring in the diff context.
1473
1474 @node Misc File Ops
1475 @section Miscellaneous File Operations
1476
1477 Emacs has commands for performing many other operations on files.
1478 All operate on one file; they do not accept wildcard file names.
1479
1480 @findex delete-file
1481 @cindex deletion (of files)
1482 @kbd{M-x delete-file} prompts for a file and deletes it. If you are
1483 deleting many files in one directory, it may be more convenient to use
1484 Dired rather than @code{delete-file}. @xref{Dired Deletion}.
1485
1486 @cindex trash
1487 @cindex recycle bin
1488 @kbd{M-x move-file-to-trash} moves a file into the system
1489 @dfn{Trash} (or @dfn{Recycle Bin}). This is a facility available on
1490 most operating systems; files that are moved into the Trash can be
1491 brought back later if you change your mind.
1492
1493 @vindex delete-by-moving-to-trash
1494 By default, Emacs deletion commands do @emph{not} use the Trash. To
1495 use the Trash (when it is available) for common deletion commands,
1496 change the variable @code{delete-by-moving-to-trash} to @code{t}.
1497 This affects the commands @kbd{M-x delete-file} and @kbd{M-x
1498 delete-directory} (@pxref{Directories}), as well as the deletion
1499 commands in Dired (@pxref{Dired Deletion}). Supplying a prefix
1500 argument to @kbd{M-x delete-file} or @kbd{M-x delete-directory} makes
1501 them delete outright, instead of using the Trash, regardless of
1502 @code{delete-by-moving-to-trash}.
1503
1504 @ifnottex
1505 If a file is under version control (@pxref{Version Control}), you
1506 should delete it using @kbd{M-x vc-delete-file} instead of @kbd{M-x
1507 delete-file}. @xref{VC Delete/Rename}.
1508 @end ifnottex
1509
1510 @findex copy-file
1511 @cindex copying files
1512 @kbd{M-x copy-file} reads the file @var{old} and writes a new file
1513 named @var{new} with the same contents.
1514
1515 @findex copy-directory
1516 @kbd{M-x copy-directory} copies directories, similar to the
1517 @command{cp -r} shell command. It prompts for a directory @var{old}
1518 and a destination @var{new}. If @var{new} is an existing directory,
1519 it creates a copy of the @var{old} directory and puts it in @var{new}.
1520 If @var{new} is not an existing directory, it copies all the contents
1521 of @var{old} into a new directory named @var{new}.
1522
1523 @cindex renaming files
1524 @findex rename-file
1525 @kbd{M-x rename-file} reads two file names @var{old} and @var{new}
1526 using the minibuffer, then renames file @var{old} as @var{new}. If
1527 the file name @var{new} already exists, you must confirm with
1528 @kbd{yes} or renaming is not done; this is because renaming causes the
1529 old meaning of the name @var{new} to be lost. If @var{old} and
1530 @var{new} are on different file systems, the file @var{old} is copied
1531 and deleted. If the argument @var{new} is just a directory name, the
1532 real new name is in that directory, with the same non-directory
1533 component as @var{old}. For example, @kbd{M-x rename-file RET ~/foo
1534 RET /tmp RET} renames @file{~/foo} to @file{/tmp/foo}. The same rule
1535 applies to all the remaining commands in this section. All of them
1536 ask for confirmation when the new file name already exists, too.
1537
1538 @ifnottex
1539 If a file is under version control (@pxref{Version Control}), you
1540 should rename it using @kbd{M-x vc-rename-file} instead of @kbd{M-x
1541 rename-file}. @xref{VC Delete/Rename}.
1542 @end ifnottex
1543
1544 @findex add-name-to-file
1545 @cindex hard links (creation)
1546 @kbd{M-x add-name-to-file} adds an additional name to an existing
1547 file without removing its old name. The new name is created as a
1548 ``hard link'' to the existing file. The new name must belong on the
1549 same file system that the file is on. On MS-Windows, this command
1550 works only if the file resides in an NTFS file system. On MS-DOS, it
1551 works by copying the file.
1552
1553 @findex make-symbolic-link
1554 @cindex symbolic links (creation)
1555 @kbd{M-x make-symbolic-link} reads two file names @var{target} and
1556 @var{linkname}, then creates a symbolic link named @var{linkname},
1557 which points at @var{target}. The effect is that future attempts to
1558 open file @var{linkname} will refer to whatever file is named
1559 @var{target} at the time the opening is done, or will get an error if
1560 the name @var{target} is nonexistent at that time. This command does
1561 not expand the argument @var{target}, so that it allows you to specify
1562 a relative name as the target of the link. Not all systems support
1563 symbolic links; on systems that don't support them, this command is
1564 not defined.
1565
1566 @kindex C-x i
1567 @findex insert-file
1568 @kbd{M-x insert-file} (also @kbd{C-x i}) inserts a copy of the
1569 contents of the specified file into the current buffer at point,
1570 leaving point unchanged before the contents. The position after the
1571 inserted contents is added to the mark ring, without activating the
1572 mark (@pxref{Mark Ring}).
1573
1574 @findex insert-file-literally
1575 @kbd{M-x insert-file-literally} is like @kbd{M-x insert-file},
1576 except the file is inserted ``literally'': it is treated as a sequence
1577 of @acronym{ASCII} characters with no special encoding or conversion,
1578 similar to the @kbd{M-x find-file-literally} command
1579 (@pxref{Visiting}).
1580
1581 @findex write-region
1582 @kbd{M-x write-region} is the inverse of @kbd{M-x insert-file}; it
1583 copies the contents of the region into the specified file. @kbd{M-x
1584 append-to-file} adds the text of the region to the end of the
1585 specified file. @xref{Accumulating Text}. The variable
1586 @code{write-region-inhibit-fsync} applies to these commands, as well
1587 as saving files; see @ref{Customize Save}.
1588
1589 @findex set-file-modes
1590 @cindex file modes
1591 @cindex file permissions
1592 @kbd{M-x set-file-modes} reads a file name followed by a @dfn{file
1593 mode}, and applies that file mode to the specified file. File modes,
1594 also called @dfn{file permissions}, determine whether a file can be
1595 read, written to, or executed, and by whom. This command reads file
1596 modes using the same symbolic or octal format accepted by the
1597 @command{chmod} command; for instance, @samp{u+x} means to add
1598 execution permission for the user who owns the file. It has no effect
1599 on operating systems that do not support file modes. @code{chmod} is a
1600 convenience alias for this function.
1601
1602 @node Compressed Files
1603 @section Accessing Compressed Files
1604 @cindex compression
1605 @cindex uncompression
1606 @cindex Auto Compression mode
1607 @cindex mode, Auto Compression
1608 @pindex gzip
1609
1610 Emacs automatically uncompresses compressed files when you visit
1611 them, and automatically recompresses them if you alter them and save
1612 them. Emacs recognizes compressed files by their file names. File
1613 names ending in @samp{.gz} indicate a file compressed with
1614 @code{gzip}. Other endings indicate other compression programs.
1615
1616 Automatic uncompression and compression apply to all the operations in
1617 which Emacs uses the contents of a file. This includes visiting it,
1618 saving it, inserting its contents into a buffer, loading it, and byte
1619 compiling it.
1620
1621 @findex auto-compression-mode
1622 @vindex auto-compression-mode
1623 To disable this feature, type the command @kbd{M-x
1624 auto-compression-mode}. You can disable it permanently by
1625 customizing the variable @code{auto-compression-mode}.
1626
1627 @node File Archives
1628 @section File Archives
1629 @cindex mode, tar
1630 @cindex Tar mode
1631 @cindex file archives
1632
1633 A file whose name ends in @samp{.tar} is normally an @dfn{archive}
1634 made by the @code{tar} program. Emacs views these files in a special
1635 mode called Tar mode which provides a Dired-like list of the contents
1636 (@pxref{Dired}). You can move around through the list just as you
1637 would in Dired, and visit the subfiles contained in the archive.
1638 However, not all Dired commands are available in Tar mode.
1639
1640 If Auto Compression mode is enabled (@pxref{Compressed Files}), then
1641 Tar mode is used also for compressed archives---files with extensions
1642 @samp{.tgz}, @code{.tar.Z} and @code{.tar.gz}.
1643
1644 The keys @kbd{e}, @kbd{f} and @key{RET} all extract a component file
1645 into its own buffer. You can edit it there, and if you save the
1646 buffer, the edited version will replace the version in the Tar buffer.
1647 Clicking with the mouse on the file name in the Tar buffer does
1648 likewise. @kbd{v} extracts a file into a buffer in View mode
1649 (@pxref{View Mode}). @kbd{o} extracts the file and displays it in
1650 another window, so you could edit the file and operate on the archive
1651 simultaneously.
1652
1653 @kbd{d} marks a file for deletion when you later use @kbd{x}, and
1654 @kbd{u} unmarks a file, as in Dired. @kbd{C} copies a file from the
1655 archive to disk and @kbd{R} renames a file within the archive.
1656 @kbd{g} reverts the buffer from the archive on disk. The keys
1657 @kbd{M}, @kbd{G}, and @kbd{O} change the file's permission bits,
1658 group, and owner, respectively.
1659
1660 Saving the Tar buffer writes a new version of the archive to disk with
1661 the changes you made to the components.
1662
1663 You don't need the @code{tar} program to use Tar mode---Emacs reads
1664 the archives directly. However, accessing compressed archives
1665 requires the appropriate uncompression program.
1666
1667 @cindex Archive mode
1668 @cindex mode, archive
1669 @cindex @code{arc}
1670 @cindex @code{jar}
1671 @cindex @code{rar}
1672 @cindex @code{zip}
1673 @cindex @code{lzh}
1674 @cindex @code{zoo}
1675 @cindex @code{7z}
1676 @pindex arc
1677 @pindex jar
1678 @pindex zip
1679 @pindex rar
1680 @pindex lzh
1681 @pindex zoo
1682 @pindex 7z
1683 @cindex Java class archives
1684 @cindex unzip archives
1685 A separate but similar Archive mode is used for @code{arc},
1686 @code{jar}, @code{lzh}, @code{zip}, @code{rar}, @code{7z}, and
1687 @code{zoo} archives, as well as @code{exe} files that are
1688 self-extracting executables.
1689
1690 The key bindings of Archive mode are similar to those in Tar mode,
1691 with the addition of the @kbd{m} key which marks a file for subsequent
1692 operations, and @kbd{M-@key{DEL}} which unmarks all the marked files.
1693 Also, the @kbd{a} key toggles the display of detailed file
1694 information, for those archive types where it won't fit in a single
1695 line. Operations such as renaming a subfile, or changing its mode or
1696 owner, are supported only for some of the archive formats.
1697
1698 Unlike Tar mode, Archive mode runs the archiving programs to unpack
1699 and repack archives. However, you don't need these programs to look
1700 at the archive table of contents, only to extract or manipulate the
1701 subfiles in the archive. Details of the program names and their
1702 options can be set in the @samp{Archive} Customize group.
1703
1704 @node Remote Files
1705 @section Remote Files
1706
1707 @cindex Tramp
1708 @cindex FTP
1709 @cindex remote file access
1710 You can refer to files on other machines using a special file name
1711 syntax:
1712
1713 @example
1714 @group
1715 /@var{host}:@var{filename}
1716 /@var{user}@@@var{host}:@var{filename}
1717 /@var{user}@@@var{host}#@var{port}:@var{filename}
1718 /@var{method}:@var{user}@@@var{host}:@var{filename}
1719 /@var{method}:@var{user}@@@var{host}#@var{port}:@var{filename}
1720 @end group
1721 @end example
1722
1723 @noindent
1724 To carry out this request, Emacs uses a remote-login program such as
1725 @command{ftp}, @command{ssh}, @command{rlogin}, or @command{telnet}.
1726 You can always specify in the file name which method to use---for
1727 example, @file{/ftp:@var{user}@@@var{host}:@var{filename}} uses FTP,
1728 whereas @file{/ssh:@var{user}@@@var{host}:@var{filename}} uses
1729 @command{ssh}. When you don't specify a method in the file name,
1730 Emacs chooses the method as follows:
1731
1732 @enumerate
1733 @item
1734 If the host name starts with @samp{ftp.} (with dot), Emacs uses FTP.
1735 @item
1736 If the user name is @samp{ftp} or @samp{anonymous}, Emacs uses FTP.
1737 @item
1738 If the variable @code{tramp-default-method} is set to @samp{ftp},
1739 Emacs uses FTP.
1740 @item
1741 If @command{ssh-agent} is running, Emacs uses @command{scp}.
1742 @item
1743 Otherwise, Emacs uses @command{ssh}.
1744 @end enumerate
1745
1746 @cindex disabling remote files
1747 @noindent
1748 You can entirely turn off the remote file name feature by setting the
1749 variable @code{tramp-mode} to @code{nil}. You can turn off the
1750 feature in individual cases by quoting the file name with @samp{/:}
1751 (@pxref{Quoted File Names}).
1752
1753 @cindex ange-ftp
1754 Remote file access through FTP is handled by the Ange-FTP package, which
1755 is documented in the following. Remote file access through the other
1756 methods is handled by the Tramp package, which has its own manual.
1757 @xref{Top, The Tramp Manual,, tramp, The Tramp Manual}.
1758
1759 @vindex ange-ftp-default-user
1760 @cindex user name for remote file access
1761 When the Ange-FTP package is used, Emacs logs in through FTP using
1762 the name @var{user}, if that is specified in the remote file name. If
1763 @var{user} is unspecified, Emacs logs in using your user name on the
1764 local system; but if you set the variable @code{ange-ftp-default-user}
1765 to a string, that string is used instead. When logging in, Emacs may
1766 also ask for a password.
1767
1768 @cindex backups for remote files
1769 @vindex ange-ftp-make-backup-files
1770 For performance reasons, Emacs does not make backup files for files
1771 accessed via FTP by default. To make it do so, change the variable
1772 @code{ange-ftp-make-backup-files} to a non-@code{nil} value.
1773
1774 By default, auto-save files for remote files are made in the
1775 temporary file directory on the local machine, as specified by the
1776 variable @code{auto-save-file-name-transforms}. @xref{Auto Save
1777 Files}.
1778
1779 @cindex anonymous FTP
1780 @vindex ange-ftp-generate-anonymous-password
1781 To visit files accessible by anonymous FTP, you use special user
1782 names @samp{anonymous} or @samp{ftp}. Passwords for these user names
1783 are handled specially. The variable
1784 @code{ange-ftp-generate-anonymous-password} controls what happens: if
1785 the value of this variable is a string, then that string is used as
1786 the password; if non-@code{nil} (the default), then the value of
1787 @code{user-mail-address} is used; if @code{nil}, then Emacs prompts
1788 you for a password as usual (@pxref{Passwords}).
1789
1790 @cindex firewall, and accessing remote files
1791 @cindex gateway, and remote file access with @code{ange-ftp}
1792 @vindex ange-ftp-smart-gateway
1793 @vindex ange-ftp-gateway-host
1794 Sometimes you may be unable to access files on a remote machine
1795 because a @dfn{firewall} in between blocks the connection for security
1796 reasons. If you can log in on a @dfn{gateway} machine from which the
1797 target files @emph{are} accessible, and whose FTP server supports
1798 gatewaying features, you can still use remote file names; all you have
1799 to do is specify the name of the gateway machine by setting the
1800 variable @code{ange-ftp-gateway-host}, and set
1801 @code{ange-ftp-smart-gateway} to @code{t}. Otherwise you may be able
1802 to make remote file names work, but the procedure is complex. You can
1803 read the instructions by typing @kbd{M-x finder-commentary @key{RET}
1804 ange-ftp @key{RET}}.
1805
1806 @node Quoted File Names
1807 @section Quoted File Names
1808
1809 @cindex quoting file names
1810 @cindex file names, quote special characters
1811 You can @dfn{quote} an absolute file name to prevent special
1812 characters and syntax in it from having their special effects.
1813 The way to do this is to add @samp{/:} at the beginning.
1814
1815 For example, you can quote a local file name which appears remote, to
1816 prevent it from being treated as a remote file name. Thus, if you have
1817 a directory named @file{/foo:} and a file named @file{bar} in it, you
1818 can refer to that file in Emacs as @samp{/:/foo:/bar}.
1819
1820 @samp{/:} can also prevent @samp{~} from being treated as a special
1821 character for a user's home directory. For example, @file{/:/tmp/~hack}
1822 refers to a file whose name is @file{~hack} in directory @file{/tmp}.
1823
1824 Quoting with @samp{/:} is also a way to enter in the minibuffer a
1825 file name that contains @samp{$}. In order for this to work, the
1826 @samp{/:} must be at the beginning of the minibuffer contents. (You
1827 can also double each @samp{$}; see @ref{File Names with $}.)
1828
1829 You can also quote wildcard characters with @samp{/:}, for visiting.
1830 For example, @file{/:/tmp/foo*bar} visits the file
1831 @file{/tmp/foo*bar}.
1832
1833 Another method of getting the same result is to enter
1834 @file{/tmp/foo[*]bar}, which is a wildcard specification that matches
1835 only @file{/tmp/foo*bar}. However, in many cases there is no need to
1836 quote the wildcard characters because even unquoted they give the
1837 right result. For example, if the only file name in @file{/tmp} that
1838 starts with @samp{foo} and ends with @samp{bar} is @file{foo*bar},
1839 then specifying @file{/tmp/foo*bar} will visit only
1840 @file{/tmp/foo*bar}.
1841
1842 @node File Name Cache
1843 @section File Name Cache
1844
1845 @cindex file name caching
1846 @cindex cache of file names
1847 @pindex find
1848 @kindex C-TAB
1849 @findex file-cache-minibuffer-complete
1850 You can use the @dfn{file name cache} to make it easy to locate a
1851 file by name, without having to remember exactly where it is located.
1852 When typing a file name in the minibuffer, @kbd{C-@key{tab}}
1853 (@code{file-cache-minibuffer-complete}) completes it using the file
1854 name cache. If you repeat @kbd{C-@key{tab}}, that cycles through the
1855 possible completions of what you had originally typed. (However, note
1856 that the @kbd{C-@key{tab}} character cannot be typed on most text-only
1857 terminals.)
1858
1859 The file name cache does not fill up automatically. Instead, you
1860 load file names into the cache using these commands:
1861
1862 @findex file-cache-add-directory
1863 @table @kbd
1864 @item M-x file-cache-add-directory @key{RET} @var{directory} @key{RET}
1865 Add each file name in @var{directory} to the file name cache.
1866 @item M-x file-cache-add-directory-using-find @key{RET} @var{directory} @key{RET}
1867 Add each file name in @var{directory} and all of its nested
1868 subdirectories to the file name cache.
1869 @item M-x file-cache-add-directory-using-locate @key{RET} @var{directory} @key{RET}
1870 Add each file name in @var{directory} and all of its nested
1871 subdirectories to the file name cache, using @command{locate} to find
1872 them all.
1873 @item M-x file-cache-add-directory-list @key{RET} @var{variable} @key{RET}
1874 Add each file name in each directory listed in @var{variable}
1875 to the file name cache. @var{variable} should be a Lisp variable
1876 such as @code{load-path} or @code{exec-path}, whose value is a list
1877 of directory names.
1878 @item M-x file-cache-clear-cache @key{RET}
1879 Clear the cache; that is, remove all file names from it.
1880 @end table
1881
1882 The file name cache is not persistent: it is kept and maintained
1883 only for the duration of the Emacs session. You can view the contents
1884 of the cache with the @code{file-cache-display} command.
1885
1886 @node File Conveniences
1887 @section Convenience Features for Finding Files
1888
1889 In this section, we introduce some convenient facilities for finding
1890 recently-opened files, reading file names from a buffer, and viewing
1891 image files.
1892
1893 @findex recentf-mode
1894 @vindex recentf-mode
1895 @findex recentf-save-list
1896 @findex recentf-edit-list
1897 If you enable Recentf mode, with @kbd{M-x recentf-mode}, the
1898 @samp{File} menu includes a submenu containing a list of recently
1899 opened files. @kbd{M-x recentf-save-list} saves the current
1900 @code{recent-file-list} to a file, and @kbd{M-x recentf-edit-list}
1901 edits it.
1902
1903 The @kbd{M-x ffap} command generalizes @code{find-file} with more
1904 powerful heuristic defaults (@pxref{FFAP}), often based on the text at
1905 point. Partial Completion mode offers other features extending
1906 @code{find-file}, which can be used with @code{ffap}.
1907 @xref{Completion Options}.
1908
1909 @findex image-mode
1910 @findex image-toggle-display
1911 @cindex images, viewing
1912 Visiting image files automatically selects Image mode. This major
1913 mode allows you to toggle between displaying the file as an image in
1914 the Emacs buffer, and displaying its underlying text representation,
1915 using the command @kbd{C-c C-c} (@code{image-toggle-display}). This
1916 works only when Emacs can display the specific image type. If the
1917 displayed image is wider or taller than the frame, the usual point
1918 motion keys (@kbd{C-f}, @kbd{C-p}, and so forth) cause different parts
1919 of the image to be displayed.
1920
1921 @findex thumbs-mode
1922 @findex mode, thumbs
1923 See also the Image-Dired package (@pxref{Image-Dired}) for viewing
1924 images as thumbnails.
1925
1926 @node Filesets
1927 @section Filesets
1928 @cindex filesets
1929
1930 @findex filesets-init
1931 If you regularly edit a certain group of files, you can define them
1932 as a @dfn{fileset}. This lets you perform certain operations, such as
1933 visiting, @code{query-replace}, and shell commands on all the files at
1934 once. To make use of filesets, you must first add the expression
1935 @code{(filesets-init)} to your init file (@pxref{Init File}). This
1936 adds a @samp{Filesets} menu to the menu bar.
1937
1938 @findex filesets-add-buffer
1939 @findex filesets-remove-buffer
1940 The simplest way to define a fileset is by adding files to it one
1941 at a time. To add a file to fileset @var{name}, visit the file and
1942 type @kbd{M-x filesets-add-buffer @kbd{RET} @var{name} @kbd{RET}}. If
1943 there is no fileset @var{name}, this creates a new one, which
1944 initially creates only the current file. The command @kbd{M-x
1945 filesets-remove-buffer} removes the current file from a fileset.
1946
1947 You can also edit the list of filesets directly, with @kbd{M-x
1948 filesets-edit} (or by choosing @samp{Edit Filesets} from the
1949 @samp{Filesets} menu). The editing is performed in a Customize buffer
1950 (@pxref{Easy Customization}). Filesets need not be a simple list of
1951 files---you can also define filesets using regular expression matching
1952 file names. Some examples of these more complicated filesets are
1953 shown in the Customize buffer. Remember to select @samp{Save for
1954 future sessions} if you want to use the same filesets in future Emacs
1955 sessions.
1956
1957 You can use the command @kbd{M-x filesets-open} to visit all the
1958 files in a fileset, and @kbd{M-x filesets-close} to close them. Use
1959 @kbd{M-x filesets-run-cmd} to run a shell command on all the files in
1960 a fileset. These commands are also available from the @samp{Filesets}
1961 menu, where each existing fileset is represented by a submenu.
1962
1963 @xref{Version Control}, for a different concept of ``filesets'':
1964 groups of files bundled together for version control operations.
1965 Filesets of that type are unnamed, and do not persist across Emacs
1966 sessions.