root/branches/2.1/info/emacs-8

Revision 3212, 48.4 kB (checked in by miyoshi, 5 years ago)

Sync up with Emacs-21.3.

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