Unify or relate missing combinations of M-XXXXX and CNS.
[chise/xemacs-chise.git-] / info / xemacs.info-7
1 This is ../info/xemacs.info, produced by makeinfo version 4.0 from
2 xemacs/xemacs.texi.
3
4 INFO-DIR-SECTION XEmacs Editor
5 START-INFO-DIR-ENTRY
6 * XEmacs: (xemacs).             XEmacs Editor.
7 END-INFO-DIR-ENTRY
8
9    This file documents the XEmacs editor.
10
11    Copyright (C) 1985, 1986, 1988 Richard M. Stallman.  Copyright (C)
12 1991, 1992, 1993, 1994 Lucid, Inc.  Copyright (C) 1993, 1994 Sun
13 Microsystems, Inc.  Copyright (C) 1995 Amdahl Corporation.
14
15    Permission is granted to make and distribute verbatim copies of this
16 manual provided the copyright notice and this permission notice are
17 preserved on all copies.
18
19    Permission is granted to copy and distribute modified versions of
20 this manual under the conditions for verbatim copying, provided also
21 that the sections entitled "The GNU Manifesto", "Distribution" and "GNU
22 General Public License" are included exactly as in the original, and
23 provided that the entire resulting derived work is distributed under the
24 terms of a permission notice identical to this one.
25
26    Permission is granted to copy and distribute translations of this
27 manual into another language, under the above conditions for modified
28 versions, except that the sections entitled "The GNU Manifesto",
29 "Distribution" and "GNU General Public License" may be included in a
30 translation approved by the author instead of in the original English.
31
32 \1f
33 File: xemacs.info,  Node: Transpose,  Next: Fixing Case,  Prev: Kill Errors,  Up: Fixit
34
35 Transposing Text
36 ================
37
38 `C-t'
39      Transpose two characters (`transpose-chars').
40
41 `M-t'
42      Transpose two words (`transpose-words').
43
44 `C-M-t'
45      Transpose two balanced expressions (`transpose-sexps').
46
47 `C-x C-t'
48      Transpose two lines (`transpose-lines').
49
50    The common error of transposing two adjacent characters can be fixed
51 with the `C-t' command (`transpose-chars').  Normally, `C-t' transposes
52 the two characters on either side of point.  When given at the end of a
53 line, `C-t' transposes the last two characters on the line, rather than
54 transposing the last character of the line with the newline, which
55 would be useless.  If you catch a transposition error right away, you
56 can fix it with just `C-t'.  If you catch the error later,  move the
57 cursor back to between the two transposed characters.  If you
58 transposed a space with the last character of the word before it, the
59 word motion commands are a good way of getting there.  Otherwise, a
60 reverse search (`C-r') is often the best way.  *Note Search::.
61
62    `Meta-t' (`transpose-words') transposes the word before point with
63 the word after point.  It moves point forward over a word, dragging the
64 word preceding or containing point forward as well.  The punctuation
65 characters between the words do not move.  For example, `FOO, BAR'
66 transposes into `BAR, FOO' rather than `BAR FOO,'.
67
68    `C-M-t' (`transpose-sexps') is a similar command for transposing two
69 expressions (*note Lists::), and `C-x C-t' (`transpose-lines')
70 exchanges lines.  It works like `M-t' but in determines the division of
71 the text into syntactic units differently.
72
73    A numeric argument to a transpose command serves as a repeat count:
74 it tells the transpose command to move the character (word, sexp, line)
75 before or containing point across several other characters (words,
76 sexps, lines).  For example, `C-u 3 C-t' moves the character before
77 point forward across three other characters.  This is equivalent to
78 repeating `C-t' three times.  `C-u - 4 M-t' moves the word before point
79 backward across four words.  `C-u - C-M-t' would cancel the effect of
80 plain `C-M-t'.
81
82    A numeric argument of zero transposes the character (word, sexp,
83 line) ending after point with the one ending after the mark (otherwise a
84 command with a repeat count of zero would do nothing).
85
86 \1f
87 File: xemacs.info,  Node: Fixing Case,  Next: Spelling,  Prev: Transpose,  Up: Fixit
88
89 Case Conversion
90 ===============
91
92 `M-- M-l'
93      Convert last word to lower case.  Note that `Meta--' is
94      "Meta-minus."
95
96 `M-- M-u'
97      Convert last word to all upper case.
98
99 `M-- M-c'
100      Convert last word to lower case with capital initial.
101
102    A  common error is to type words in the wrong case.  Because of this,
103 the word case-conversion commands `M-l', `M-u', and `M-c' do not move
104 the cursor when used with a negative argument.  As soon as you see you
105 have mistyped the last word, you can simply case-convert it and
106 continue typing.  *Note Case::.
107
108 \1f
109 File: xemacs.info,  Node: Spelling,  Prev: Fixing Case,  Up: Fixit
110
111 Checking and Correcting Spelling
112 ================================
113
114 `M-$'
115      Check and correct spelling of word (`spell-word').
116
117 `M-x spell-buffer'
118      Check and correct spelling of each word in the buffer.
119
120 `M-x spell-region'
121      Check and correct spelling of each word in the region.
122
123 `M-x spell-string'
124      Check spelling of specified word.
125
126    To check the spelling of the word before point, and optionally
127 correct it, use the command `M-$' (`spell-word').  This command runs an
128 inferior process containing the `spell' program to see whether the word
129 is correct English.  If it is not, it asks you to edit the word (in the
130 minibuffer) into a corrected spelling, and then performs a
131 `query-replace' to substitute the corrected spelling for the old one
132 throughout the buffer.
133
134    If you exit the minibuffer without altering the original spelling, it
135 means you do not want to do anything to that word.  In that case, the
136 `query-replace' is not done.
137
138    `M-x spell-buffer' checks each word in the buffer the same way that
139 `spell-word' does, doing a `query-replace' for every incorrect word if
140 appropriate.
141
142    `M-x spell-region' is similar to `spell-buffer' but operates only on
143 the region, not the entire buffer.
144
145    `M-x spell-string' reads a string as an argument and checks whether
146 that is a correctly spelled English word.  It prints a message giving
147 the answer in the echo area.
148
149 \1f
150 File: xemacs.info,  Node: Files,  Next: Buffers,  Prev: Fixit,  Up: Top
151
152 File Handling
153 *************
154
155    The basic unit of stored data in Unix is the "file".  To edit a file,
156 you must tell Emacs to examine the file and prepare a buffer containing
157 a copy of the file's text.  This is called "visiting" the file.  Editing
158 commands apply directly to text in the buffer; that is, to the copy
159 inside Emacs.  Your changes appear in the file itself only when you
160 "save" the buffer back into the file.
161
162    In addition to visiting and saving files, Emacs can delete, copy,
163 rename, and append to files, and operate on file directories.
164
165 * Menu:
166
167 * File Names::       How to type and edit file name arguments.
168 * Visiting::         Visiting a file prepares Emacs to edit the file.
169 * Saving::           Saving makes your changes permanent.
170 * Reverting::        Reverting cancels all the changes not saved.
171 * Auto Save::        Auto Save periodically protects against loss of data.
172 * Version Control::  Version control systems (RCS and SCCS).
173 * ListDir::          Listing the contents of a file directory.
174 * Comparing Files::  Finding where two files differ.
175 * Dired::            ``Editing'' a directory to delete, rename, etc.
176                      the files in it.
177 * Misc File Ops::    Other things you can do on files.
178
179 \1f
180 File: xemacs.info,  Node: File Names,  Next: Visiting,  Prev: Files,  Up: Files
181
182 File Names
183 ==========
184
185    Most Emacs commands that operate on a file require you to specify the
186 file name.  (Saving and reverting are exceptions; the buffer knows which
187 file name to use for them.)  File names are specified in the minibuffer
188 (*note Minibuffer::).  "Completion" is available, to make it easier to
189 specify long file names.  *Note Completion::.
190
191    There is always a "default file name" which is used if you enter an
192 empty argument by typing just <RET>.  Normally the default file name is
193 the name of the file visited in the current buffer; this makes it easy
194 to operate on that file with any of the Emacs file commands.
195
196    Each buffer has a default directory, normally the same as the
197 directory of the file visited in that buffer.  When Emacs reads a file
198 name, the default directory is used if you do not specify a directory.
199 If you specify a directory in a relative fashion, with a name that does
200 not start with a slash, it is interpreted with respect to the default
201 directory.  The default directory of the current buffer is kept in the
202 variable `default-directory', which has a separate value in every
203 buffer.  The value of the variable should end with a slash.
204
205    For example, if the default file name is `/u/rms/gnu/gnu.tasks' then
206 the default directory is `/u/rms/gnu/'.  If you type just `foo', which
207 does not specify a directory, it is short for `/u/rms/gnu/foo'.
208 `../.login' would stand for `/u/rms/.login'.  `new/foo' would stand for
209 the filename `/u/rms/gnu/new/foo'.
210
211    The variable `default-directory-alist' takes an alist of major modes
212 and their opinions on `default-directory' as a Lisp expression to
213 evaluate.  A resulting value of `nil' is ignored in favor of
214 `default-directory'.
215
216    You can create a new directory with the function `make-directory',
217 which takes as an argument a file name string. The current directory is
218 displayed in the minibuffer when the function is called; you can delete
219 the old directory name and supply a new directory name. For example, if
220 the current directory is `/u/rms/gnu', you can delete `gnu' and type
221 `oryx' and <RET> to create `/u/rms/oryx'.  Removing a directory is
222 similar to creating one.  To remove a directory, use
223 `remove-directory'; it takes one argument, a file name string.
224
225    The command `M-x pwd' prints the current buffer's default directory,
226 and the command `M-x cd' sets it (to a value read using the
227 minibuffer).  A buffer's default directory changes only when the `cd'
228 command is used.  A file-visiting buffer's default directory is
229 initialized to the directory of the file that is visited there.  If a
230 buffer is created with `C-x b', its default directory is copied from
231 that of the buffer that was current at the time.
232
233    The default directory name actually appears in the minibuffer when
234 the minibuffer becomes active to read a file name.  This serves two
235 purposes: it shows you what the default is, so that you can type a
236 relative file name and know with certainty what it will mean, and it
237 allows you to edit the default to specify a different directory.  To
238 inhibit the insertion of the default directory, set the variable
239 `insert-default-directory' to `nil'.
240
241    Note that it is legitimate to type an absolute file name after you
242 enter the minibuffer, ignoring the presence of the default directory
243 name.  The final minibuffer contents may look invalid, but that is not
244 so.  *Note Minibuffer File::.
245
246    `$' in a file name is used to substitute environment variables.  For
247 example, if you have used the shell command `setenv FOO rms/hacks' to
248 set up an environment variable named `FOO', then you can use
249 `/u/$FOO/test.c' or `/u/${FOO}/test.c' as an abbreviation for
250 `/u/rms/hacks/test.c'.  The environment variable name consists of all
251 the alphanumeric characters after the `$'; alternatively, it may be
252 enclosed in braces after the `$'.  Note that the `setenv' command
253 affects Emacs only if done before Emacs is started.
254
255    To access a file with `$' in its name, type `$$'.  This pair is
256 converted to a single `$' at the same time variable substitution is
257 performed for single `$'.  The Lisp function that performs the
258 substitution is called `substitute-in-file-name'.  The substitution is
259 performed only on filenames read as such using the minibuffer.
260
261 \1f
262 File: xemacs.info,  Node: Visiting,  Next: Saving,  Prev: File Names,  Up: Files
263
264 Visiting Files
265 ==============
266
267 `C-x C-f'
268      Visit a file (`find-file').
269
270 `C-x C-v'
271      Visit a different file instead of the one visited last
272      (`find-alternate-file').
273
274 `C-x 4 C-f'
275      Visit a file, in another window (`find-file-other-window').  Don't
276      change this window.
277
278 `C-x 5 C-f'
279      Visit a file, in another frame (`find-file-other-frame').  Don't
280      change this window or frame.
281
282    "Visiting" a file means copying its contents into an Emacs buffer so
283 you can edit it.  Emacs creates a new buffer for each file you visit.
284 We say that the buffer is visiting the file that it was created to
285 hold.  Emacs constructs the buffer name from the file name by throwing
286 away the directory and keeping just the file name.  For example, a file
287 named `/usr/rms/emacs.tex' is displayed in a buffer named `emacs.tex'.
288 If a buffer with that name exists, a unique name is constructed by
289 appending `<2>', `<3>',and so on, using the lowest number that makes a
290 name that is not already in use.
291
292    Each window's mode line shows the name of the buffer that is being
293 displayed in that window, so you can always tell what buffer you are
294 editing.
295
296    The changes you make with Emacs are made in the Emacs buffer.  They
297 do not take effect in the file that you visit, or any other permanent
298 place, until you "save" the buffer.  Saving the buffer means that Emacs
299 writes the current contents of the buffer into its visited file.  *Note
300 Saving::.
301
302    If a buffer contains changes that have not been saved, the buffer is
303 said to be "modified".  This is important because it implies that some
304 changes will be lost if the buffer is not saved.  The mode line displays
305 two stars near the left margin if the buffer is modified.
306
307    To visit a file, use the command `C-x C-f' (`find-file').  Follow
308 the command with the name of the file you wish to visit, terminated by a
309 <RET>.  If you are using XEmacs under X, you can also use the Open...
310 command from the File menu bar item.
311
312    The file name is read using the minibuffer (*note Minibuffer::), with
313 defaulting and completion in the standard manner (*note File Names::).
314 While in the minibuffer, you can abort `C-x C-f' by typing `C-g'.
315
316    `C-x C-f' has completed successfully when text appears on the screen
317 and a new buffer name appears in the mode line.  If the specified file
318 does not exist and could not be created or cannot be read, an error
319 results.  The error message is printed in the echo area, and includes
320 the name of the file that Emacs was trying to visit.
321
322    If you visit a file that is already in Emacs, `C-x C-f' does not make
323 another copy.  It selects the existing buffer containing that file.
324 However, before doing so, it checks that the file itself has not changed
325 since you visited or saved it last.  If the file has changed, Emacs
326 prints a warning message.  *Note Simultaneous Editing: Interlocking.
327
328    You can switch to a specific file called out in the current buffer by
329 calling the function `find-this-file'. By providing a prefix argument,
330 this function calls `filename-at-point' and switches to a buffer
331 visiting the file FILENAME. It creates one if none already exists. You
332 can use this function to edit the file mentioned in the buffer you are
333 working in or to test if the file exists. You can do that by using the
334 minibuffer completion after snatching the all or part of the filename.
335
336    If the variable `find-file-use-truenames''s value is non-`nil', a
337 buffer's visited filename will always be traced back to the real file.
338 The filename will never be a symbolic link, and there will never be a
339 symbolic link anywhere in its directory path. In other words, the
340 `buffer-file-name' and `buffer-file-truename' will be equal.
341
342    If the variable `find-file-compare-truenames' value is non-`nil',
343 the `find-file' command will check the `buffer-file-truename' of all
344 visited files when deciding whether a given file is already in a
345 buffer, instead of just `buffer-file-name'.  If you attempt to visit
346 another file which is a symbolic link to a file that is already in a
347 buffer, the existing buffer will be found instead of a newly created
348 one.  This works if any component of the pathname (including a
349 non-terminal component) is a symbolic link as well, but doesn't work
350 with hard links (nothing does).
351
352    If you want to create a file, just visit it.  Emacs prints `(New
353 File)' in the echo area, but in other respects behaves as if you had
354 visited an existing empty file.  If you make any changes and save them,
355 the file is created.
356
357    If you visit a nonexistent file unintentionally (because you typed
358 the wrong file name), use the `C-x C-v' (`find-alternate-file') command
359 to visit the file you wanted.  `C-x C-v' is similar to `C-x C-f', but
360 it kills the current buffer (after first offering to save it if it is
361 modified).  `C-x C-v' is allowed even if the current buffer is not
362 visiting a file.
363
364    If the file you specify is actually a directory, Dired is called on
365 that directory (*note Dired::).  To inhibit this, set the variable
366 `find-file-run-dired' to `nil'; then it is an error to try to visit a
367 directory.
368
369    `C-x 4 f' (`find-file-other-window') is like `C-x C-f' except that
370 the buffer containing the specified file is selected in another window.
371 The window that was selected before `C-x 4 f' continues to show the
372 same buffer it was already showing.  If you use this command when only
373 one window is being displayed, that window is split in two, with one
374 window showing the same buffer as before, and the other one showing the
375 newly requested file.  *Note Windows::.
376
377    `C-x 5 C-f' (`find-file-other-frame') is like `C-x C-f' except that
378 it creates a new frame in which the file is displayed.
379
380    Use the function `find-this-file-other-window' to edit a file
381 mentioned in the buffer you are editing or to test if that file exists.
382 To do this, use the minibuffer completion after snatching the part or
383 all of the filename. By providing a prefix argument, the function calls
384 `filename-at-point' and switches you to a buffer visiting the file
385 FILENAME in another window. The function creates a buffer if none
386 already exists. This function is similar to `find-file-other-window'.
387
388    There are two hook variables that allow extensions to modify the
389 operation of visiting files.  Visiting a file that does not exist runs
390 the functions in the list `find-file-not-found-hooks'; the value of this
391 variable is expected to be a list of functions which are called one by
392 one until one of them returns non-`nil'.  Any visiting of a file,
393 whether extant or not, expects `find-file-hooks' to contain list of
394 functions and calls them all, one by one.  In both cases the functions
395 receive no arguments.  Visiting a nonexistent file runs the
396 `find-file-not-found-hooks' first.
397
398 \1f
399 File: xemacs.info,  Node: Saving,  Next: Reverting,  Prev: Visiting,  Up: Files
400
401 Saving Files
402 ============
403
404    "Saving" a buffer in Emacs means writing its contents back into the
405 file that was visited in the buffer.
406
407 `C-x C-s'
408      Save the current buffer in its visited file (`save-buffer').
409
410 `C-x s'
411      Save any or all buffers in their visited files
412      (`save-some-buffers').
413
414 `M-~'
415      Forget that the current buffer has been changed (`not-modified').
416
417 `C-x C-w'
418      Save the current buffer in a specified file, and record that file
419      as the one visited in the buffer (`write-file').
420
421 `M-x set-visited-file-name'
422      Change file the name under which the current buffer will be saved.
423
424    To save a file and make your changes permanent, type `C-x C-s'
425 (`save-buffer').  After saving is finished, `C-x C-s' prints a message
426 such as:
427
428      Wrote /u/rms/gnu/gnu.tasks
429
430 If the selected buffer is not modified (no changes have been made in it
431 since the buffer was created or last saved), Emacs does not save it
432 because it would have no effect.  Instead, `C-x C-s' prints a message
433 in the echo area saying:
434
435      (No changes need to be saved)
436
437    The command `C-x s' (`save-some-buffers') can save any or all
438 modified buffers.  First it asks, for each modified buffer, whether to
439 save it.  The questions should be answered with `y' or `n'.  `C-x C-c',
440 the key that kills Emacs, invokes `save-some-buffers' and therefore
441 asks the same questions.
442
443    If you have changed a buffer and do not want the changes to be saved,
444 you should take some action to prevent it.  Otherwise, you are liable to
445 save it by mistake each time you use `save-some-buffers' or a related
446 command.  One thing you can do is type `M-~' (`not-modified'), which
447 removes the indication that the buffer is modified.  If you do this,
448 none of the save commands will believe that the buffer needs to be
449 saved.  (`~' is often used as a mathematical symbol for `not'; thus
450 `Meta-~' is `not', metafied.)  You could also use
451 `set-visited-file-name' (see below) to mark the buffer as visiting a
452 different file name, not in use for anything important.
453
454    You can also undo all the changes made since the file was visited or
455 saved, by reading the text from the file again.  This is called
456 "reverting".  *Note Reverting::.  Alternatively, you can undo all the
457 changes by repeating the undo command `C-x u'; but this only works if
458 you have not made more changes than the undo mechanism can remember.
459
460    `M-x set-visited-file-name' alters the name of the file that the
461 current buffer is visiting.  It prompts you for the new file name in the
462 minibuffer.  You can also use `set-visited-file-name' on a buffer that
463 is not visiting a file.  The buffer's name is changed to correspond to
464 the file it is now visiting unless the new name is already used by a
465 different buffer; in that case, the buffer name is not changed.
466 `set-visited-file-name' does not save the buffer in the newly visited
467 file; it just alters the records inside Emacs so that it will save the
468 buffer in that file.  It also marks the buffer as "modified" so that
469 `C-x C-s' will save.
470
471    If you wish to mark a buffer as visiting a different file and save it
472 right away, use `C-x C-w' (`write-file').  It is precisely equivalent
473 to `set-visited-file-name' followed by `C-x C-s'.  `C-x C-s' used on a
474 buffer that is not visiting  a file has the same effect as `C-x C-w';
475 that is, it reads a file name, marks the buffer as visiting that file,
476 and saves it there.  The default file name in a buffer that is not
477 visiting a file is made by combining the buffer name with the buffer's
478 default directory.
479
480    If Emacs is about to save a file and sees that the date of the latest
481 version on disk does not match what Emacs last read or wrote, Emacs
482 notifies you of this fact, because it probably indicates a problem
483 caused by simultaneous editing and requires your immediate attention.
484 *Note Simultaneous Editing: Interlocking.
485
486    If the variable `require-final-newline' is non-`nil', Emacs puts a
487 newline at the end of any file that doesn't already end in one, every
488 time a file is saved or written.
489
490    Use the hook variable `write-file-hooks' to implement other ways to
491 write files, and specify things to be done before files are written.
492 The value of this variable should be a list of Lisp functions.  When a
493 file is to be written, the functions in the list are called, one by
494 one, with no arguments.  If one of them returns a non-`nil' value, Emacs
495 takes this to mean that the file has been written in some suitable
496 fashion; the rest of the functions are not called, and normal writing is
497 not done. Use the hook variable `after-save-hook' to list all the
498 functions to be called after writing out a buffer to a file.
499
500 * Menu:
501
502 * Backup::       How Emacs saves the old version of your file.
503 * Interlocking:: How Emacs protects against simultaneous editing
504                   of one file by two users.
505
506 \1f
507 File: xemacs.info,  Node: Backup,  Next: Interlocking,  Prev: Saving,  Up: Saving
508
509 Backup Files
510 ------------
511
512    Because Unix does not provide version numbers in file names,
513 rewriting a file in Unix automatically destroys all record of what the
514 file used to contain.  Thus, saving a file from Emacs throws away the
515 old contents of the file--or it would, except that Emacs carefully
516 copies the old contents to another file, called the "backup" file,
517 before actually saving.  (Make sure that the variable
518 `make-backup-files' is non-`nil'.  Backup files are not written if this
519 variable is `nil').
520
521    At your option, Emacs can keep either a single backup file or a
522 series of numbered backup files for each file you edit.
523
524    Emacs makes a backup for a file only the first time a file is saved
525 from one buffer.  No matter how many times you save a file, its backup
526 file continues to contain the contents from before the file was visited.
527 Normally this means that the backup file contains the contents from
528 before the current editing session; however, if you kill the buffer and
529 then visit the file again, a new backup file is made by the next save.
530
531 * Menu:
532
533 * Names: Backup Names.          How backup files are named;
534                                 Choosing single or numbered backup files.
535 * Deletion: Backup Deletion.    Emacs deletes excess numbered backups.
536 * Copying: Backup Copying.      Backups can be made by copying or renaming.
537
538 \1f
539 File: xemacs.info,  Node: Backup Names,  Next: Backup Deletion,  Prev: Backup,  Up: Backup
540
541 Single or Numbered Backups
542 ..........................
543
544    If you choose to have a single backup file (the default), the backup
545 file's name is constructed by appending `~' to the file name being
546 edited; thus, the backup file for `eval.c' is `eval.c~'.
547
548    If you choose to have a series of numbered backup files, backup file
549 names are made by appending `.~', the number, and another `~' to the
550 original file name.  Thus, the backup files of `eval.c' would be called
551 `eval.c.~1~', `eval.c.~2~', and so on, through names like
552 `eval.c.~259~' and beyond.
553
554    If protection stops you from writing backup files under the usual
555 names, the backup file is written as `%backup%~' in your home directory.
556 Only one such file can exist, so only the most recently made backup is
557 available.
558
559    The choice of single backup or numbered backups is controlled by the
560 variable `version-control'.  Its possible values are:
561
562 `t'
563      Make numbered backups.
564
565 `nil'
566      Make numbered backups for files that have numbered backups already.
567      Otherwise, make single backups.
568
569 `never'
570      Never make numbered backups; always make single backups.
571
572 `version-control' may be set locally in an individual buffer to control
573 the making of backups for that buffer's file.  For example, Rmail mode
574 locally sets `version-control' to `never' to make sure that there is
575 only one backup for an Rmail file.  *Note Locals::.
576
577 \1f
578 File: xemacs.info,  Node: Backup Deletion,  Next: Backup Copying,  Prev: Backup Names,  Up: Backup
579
580 Automatic Deletion of Backups
581 .............................
582
583    To prevent unlimited consumption of disk space, Emacs can delete
584 numbered backup versions automatically.  Generally Emacs keeps the
585 first few backups and the latest few backups, deleting any in between.
586 This happens every time a new backup is made.  The two variables that
587 control the deletion are `kept-old-versions' and `kept-new-versions'.
588 Their values are, respectively the number of oldest (lowest-numbered)
589 backups to keep and the number of newest (highest-numbered) ones to
590 keep, each time a new backup is made.  The values are used just after a
591 new backup version is made; that newly made backup is included in the
592 count in `kept-new-versions'.  By default, both variables are 2.
593
594    If `delete-old-versions' is non-`nil',  excess middle versions are
595 deleted without notification.  If it is `nil', the default, you are
596 asked whether the excess middle versions should really be deleted.
597
598    You can also use Dired's `.' (Period) command to delete old versions.
599 *Note Dired::.
600
601 \1f
602 File: xemacs.info,  Node: Backup Copying,  Prev: Backup Deletion,  Up: Backup
603
604 Copying vs. Renaming
605 ....................
606
607    You can make backup files by copying the old file or by renaming it.
608 This makes a difference when the old file has multiple names.  If you
609 rename the old file into the backup file, the alternate names become
610 names for the backup file.  If you copy the old file instead, the
611 alternate names remain names for the file that you are editing, and the
612 contents accessed by those names will be the new contents.
613
614    How you make a backup file may also affect the file's owner and
615 group.  If you use copying, they do not change.  If renaming is used,
616 you become the file's owner, and the file's group becomes the default
617 (different operating systems have different defaults for the group).
618
619    Having the owner change is usually a good idea, because then the
620 owner is always the person who last edited the file.  Occasionally
621 there is a file whose owner should not change.  Since most files should
622 change owners, it is a good idea to use local variable lists to set
623 `backup-by-copying-when-mismatch' for the special cases where the owner
624 should not change (*note File Variables::).
625
626    Three variables control the choice of renaming or copying.
627 Normally, renaming is done.  If the variable `backup-by-copying' is
628 non-`nil', copying is used.  Otherwise, if the variable
629 `backup-by-copying-when-linked' is non-`nil', copying is done for files
630 that have multiple names, but renaming may still be done when the file
631 being edited has only one name.  If the variable
632 `backup-by-copying-when-mismatch' is non-`nil', copying is done if
633 renaming would cause the file's owner or group to change.
634
635 \1f
636 File: xemacs.info,  Node: Interlocking,  Prev: Backup,  Up: Saving
637
638 Protection Against Simultaneous Editing
639 ---------------------------------------
640
641    Simultaneous editing occurs when two users visit the same file, both
642 make changes, and both save their changes.  If no one was informed that
643 this was happening, and you saved first, you would later find that your
644 changes were lost.  On some systems, Emacs notices immediately when the
645 second user starts to change a file already being edited, and issues a
646 warning.  When this is not possible, or if the second user has started
647 to change the file despite the warning, Emacs checks when the file is
648 saved, and issues a second warning when a user is about to overwrite a
649 file containing another user's changes.  If you are the user editing the
650 file, you can take corrective action at this point and prevent actual
651 loss of work.
652
653    When you make the first modification in an Emacs buffer that is
654 visiting a file, Emacs records that you have locked the file.  (It does
655 this by writing another file in a directory reserved for this purpose.)
656 The lock is removed when you save the changes.  The idea is that the
657 file is locked whenever the buffer is modified.  If you begin to modify
658 the buffer while the visited file is locked by someone else, this
659 constitutes a collision, and Emacs asks you what to do.  It does this
660 by calling the Lisp function `ask-user-about-lock', which you can
661 redefine to customize what it does.  The standard definition of this
662 function asks you a question and accepts three possible answers:
663
664 `s'
665      Steal the lock.  Whoever was already changing the file loses the
666      lock, and you get the lock.
667
668 `p'
669      Proceed.  Go ahead and edit the file despite its being locked by
670      someone else.
671
672 `q'
673      Quit.  This causes an error (`file-locked') and the modification
674      you were trying to make in the buffer does not actually take place.
675
676    Note that locking works on the basis of a file name; if a file has
677 multiple names, Emacs does not realize that the two names are the same
678 file and cannot prevent two users from editing it simultaneously under
679 different names.  However, basing locking on names means that Emacs can
680 interlock the editing of new files that do not really exist until they
681 are saved.
682
683    Some systems are not configured to allow Emacs to make locks.  On
684 these systems, Emacs cannot detect trouble in advance, but it can still
685 detect it in time to prevent you from overwriting someone else's
686 changes.
687
688    Every time Emacs saves a buffer, it first checks the
689 last-modification date of the existing file on disk to see that it has
690 not changed since the file was last visited or saved.  If the date does
691 not match, it implies that changes were made in the file in some other
692 way, and these changes are about to be lost if Emacs actually does
693 save.  To prevent this, Emacs prints a warning message and asks for
694 confirmation before saving.  Occasionally you will know why the file
695 was changed and know that it does not matter; then you can answer `yes'
696 and proceed.  Otherwise, you should cancel the save with `C-g' and
697 investigate the situation.
698
699    The first thing you should do when notified that simultaneous editing
700 has already taken place is to list the directory with `C-u C-x C-d'
701 (*note Directory Listing: ListDir.).  This will show the file's current
702 author.  You should attempt to contact that person and ask him not to
703 continue editing.  Often the next step is to save the contents of your
704 Emacs buffer under a different name, and use `diff' to compare the two
705 files.
706
707    Simultaneous editing checks are also made when you visit a file that
708 is already visited with `C-x C-f' and when you start to modify a file.
709 This is not strictly necessary, but it is useful to find out about such
710 a problem as early as possible, when corrective action takes less work.
711
712    Another way to protect your file is to set the read, write, and
713 executable permissions for the file. Use the function
714 `set-default-file-modes' to set the UNIX `umask' value to the NMASK
715 argument. The `umask' value is the default protection mode for new
716 files.
717
718 \1f
719 File: xemacs.info,  Node: Reverting,  Next: Auto Save,  Prev: Saving,  Up: Files
720
721 Reverting a Buffer
722 ==================
723
724    If you have made extensive changes to a file and then change your
725 mind about them, you can get rid of all changes by reading in the
726 previous version of the file.  To do this, use `M-x revert-buffer',
727 which operates on the current buffer.  Since reverting a buffer can
728 result in very extensive changes, you must confirm it with `yes'.
729
730    If the current buffer has been auto-saved more recently than it has
731 been saved explicitly, `revert-buffer' offers to read the auto save file
732 instead of the visited file (*note Auto Save::).  Emacs asks you about
733 the auto-save file before the request for confirmation of the
734 `revert-buffer' operation, and demands `y' or `n' as an answer.  If you
735 have started to type `yes' for confirmation without realizing that the
736 auto-save question was going to be asked, the `y' will answer that
737 question, but the `es' will not be valid confirmation.  This gives you
738 a chance to cancel the operation with `C-g' and try again with the
739 answers you really intend.
740
741    `revert-buffer' keeps point at the same distance (measured in
742 characters) from the beginning of the file.  If the file was edited only
743 slightly, you will be at approximately the same piece of text after
744 reverting as before.  If you have made more extensive changes, the
745 value of point in the old file may bring you to a totally different
746 piece of text than your last editing point.
747
748    A buffer reverted from its visited file is marked "not modified"
749 until you make a change.
750
751    Some kinds of buffers whose contents reflect data bases other than
752 files, such as Dired buffers, can also be reverted.  For them,
753 reverting means recalculating their contents from the appropriate data.
754 Buffers created randomly with `C-x b' cannot be reverted;
755 `revert-buffer' reports an error when asked to do so.
756
757 \1f
758 File: xemacs.info,  Node: Auto Save,  Next: Version Control,  Prev: Reverting,  Up: Files
759
760 Auto-Saving: Protection Against Disasters
761 =========================================
762
763    Emacs saves all the visited files from time to time (based on
764 counting your keystrokes) without being asked.  This is called
765 "auto-saving".  It prevents you from losing more than a limited amount
766 of work if the system crashes.
767
768    When Emacs determines it is time for auto-saving, each buffer is
769 considered and is auto-saved if auto-saving is turned on for it and it
770 has changed since the last time it was auto-saved.  If any auto-saving
771 is done, the message `Auto-saving...' is displayed in the echo area
772 until auto-saving is finished.  Errors occurring during auto-saving are
773 caught so that they do not interfere with the execution of commands you
774 have been typing.
775
776 * Menu:
777
778 * Files: Auto Save Files.
779 * Control: Auto Save Control.
780 * Recover::             Recovering text from auto-save files.
781
782 \1f
783 File: xemacs.info,  Node: Auto Save Files,  Next: Auto Save Control,  Prev: Auto Save,  Up: Auto Save
784
785 Auto-Save Files
786 ---------------
787
788    Auto-saving does not normally write to the files you visited, because
789 it can be undesirable to save a program that is in an inconsistent
790 state when you have made only half of a planned change.  Instead,
791 auto-saving is done in a different file called the "auto-save file",
792 and the visited file is changed only when you save explicitly, for
793 example, with `C-x C-s'.
794
795    Normally, the name of the auto-save file is generated by appending
796 `#' to the front and back of the visited file name.  Thus, a buffer
797 visiting file `foo.c' would be auto-saved in a file `#foo.c#'.  Most
798 buffers that are not visiting files are auto-saved only if you request
799 it explicitly; when they are auto-saved, the auto-save file name is
800 generated by appending `#%' to the front and `#' to the back of buffer
801 name.  For example, the `*mail*' buffer in which you compose messages
802 to be sent is auto-saved in a file named `#%*mail*#'.  Names of
803 auto-save files are generated this way unless you customize the
804 functions `make-auto-save-file-name' and `auto-save-file-name-p' to do
805 something different.  The file name to be used for auto-saving a buffer
806 is calculated at the time auto-saving is turned on in that buffer.
807
808    If you want auto-saving to be done in the visited file, set the
809 variable `auto-save-visited-file-name' to be non-`nil'.  In this mode,
810 there is really no difference between auto-saving and explicit saving.
811
812    Emacs deletes a buffer's auto-save file when you explicitly save the
813 buffer.  To inhibit the deletion, set the variable
814 `delete-auto-save-files' to `nil'.  Changing the visited file name with
815 `C-x C-w' or `set-visited-file-name' renames any auto-save file to
816 correspond to the new visited name.
817
818 \1f
819 File: xemacs.info,  Node: Auto Save Control,  Next: Recover,  Prev: Auto Save Files,  Up: Auto Save
820
821 Controlling Auto-Saving
822 -----------------------
823
824    Each time you visit a file, auto-saving is turned on for that file's
825 buffer if the variable `auto-save-default' is non-`nil' (but not in
826 batch mode; *note Entering Emacs::).  The default for this variable is
827 `t', so Emacs auto-saves buffers that visit files by default.  You can
828 use the command `M-x auto-save-mode' to turn auto-saving for a buffer
829 on or off.  Like other minor mode commands, `M-x auto-save-mode' turns
830 auto-saving on with a positive argument, off with a zero or negative
831 argument; with no argument, it toggles.
832
833    Emacs performs auto-saving periodically based on counting how many
834 characters you have typed since the last time auto-saving happened.  The
835 variable `auto-save-interval' specifies the number of characters
836 between auto-saves.  By default, it is 300.  Emacs also auto-saves
837 whenever you call the function `do-auto-save'.
838
839    Emacs also does auto-saving whenever it gets a fatal error.  This
840 includes killing the Emacs job with a shell command such as `kill
841 -emacs', or disconnecting a phone line or network connection.
842
843    You can set the number of seconds of idle time before an auto-save is
844 done. Setting the value of the variable `auto-save-timeout' to zero or
845 `nil' will  disable auto-saving due to idleness.
846
847    The actual amount of idle time between auto-saves is logarithmically
848 related to the size of the current buffer.  This variable is the number
849 of seconds after which an auto-save will happen when the current buffer
850 is 50k or less; the timeout will be 2 1/4 times this in a 200k buffer, 3
851 3/4 times this in a 1000k buffer, and 4 1/2 times this in a 2000k
852 buffer.
853
854    For this variable to have any effect, you must do `(require 'timer)'.
855
856 \1f
857 File: xemacs.info,  Node: Recover,  Prev: Auto Save Control,  Up: Auto Save
858
859 Recovering Data from Auto-Saves
860 -------------------------------
861
862    If you want to use the contents of an auto-save file to recover from
863 a loss of data, use the command `M-x recover-file <RET> FILE <RET>'.
864 Emacs visits FILE and then (after your confirmation) restores the
865 contents from the auto-save file `#FILE#'.  You can then save the file
866 with `C-x C-s' to put the recovered text into FILE itself.  For
867 example, to recover file `foo.c' from its auto-save file `#foo.c#', do:
868
869      M-x recover-file <RET> foo.c <RET>
870      C-x C-s
871
872    Before asking for confirmation, `M-x recover-file' displays a
873 directory listing describing the specified file and the auto-save file,
874 so you can compare their sizes and dates.  If the auto-save file is
875 older, `M-x recover-file' does not offer to read it.
876
877    Auto-saving is disabled by `M-x recover-file' because using this
878 command implies that the auto-save file contains valuable data from a
879 past session.  If you save the data in the visited file and then go on
880 to make new changes, turn auto-saving back on with `M-x auto-save-mode'.
881
882 \1f
883 File: xemacs.info,  Node: Version Control,  Next: ListDir,  Prev: Auto Save,  Up: Files
884
885 Version Control
886 ===============
887
888    "Version control systems" are packages that can record multiple
889 versions of a source file, usually storing the unchanged parts of the
890 file just once.  Version control systems also record history information
891 such as the creation time of each version, who created it, and a
892 description of what was changed in that version.
893
894    The GNU project recommends the version control system known as RCS,
895 which is free software and available from the Free Software Foundation.
896 Emacs supports use of either RCS or SCCS (a proprietary, but widely
897 used, version control system that is not quite as powerful as RCS)
898 through a facility called VC.  The same Emacs commands work with either
899 RCS or SCCS, so you hardly have to know which one of them you are using.
900
901 * Menu:
902
903 * Concepts of VC::              Basic version control information;
904                                   checking files in and out.
905 * Editing with VC::             Commands for editing a file maintained
906                                   with version control.
907 * Variables for Check-in/out::  Variables that affect the commands used
908                                   to check files in or out.
909 * Log Entries::                 Logging your changes.
910 * Change Logs and VC::          Generating a change log file from log
911                                   entries.
912 * Old Versions::                Examining and comparing old versions.
913 * VC Status::                   Commands to view the VC status of files and
914                                   look at log entries.
915 * Renaming and VC::             A command to rename both the source and
916                                   master file correctly.
917 * Snapshots::                   How to make and use snapshots, a set of
918                                   file versions that can be treated as a unit.
919 * Version Headers::             Inserting version control headers into
920                                   working files.
921
922 \1f
923 File: xemacs.info,  Node: Concepts of VC,  Next: Editing with VC,  Prev: Version Control,  Up: Version Control
924
925 Concepts of Version Control
926 ---------------------------
927
928    When a file is under version control, we also say that it is
929 "registered" in the version control system.  Each registered file has a
930 corresponding "master file" which represents the file's present state
931 plus its change history, so that you can reconstruct from it either the
932 current version or any specified earlier version.  Usually the master
933 file also records a "log entry" for each version describing what was
934 changed in that version.
935
936    The file that is maintained under version control is sometimes called
937 the "work file" corresponding to its master file.
938
939    To examine a file, you "check it out".  This extracts a version of
940 the source file (typically, the most recent) from the master file.  If
941 you want to edit the file, you must check it out "locked".  Only one
942 user can do this at a time for any given source file.  (This kind of
943 locking is completely unrelated to the locking that Emacs uses to
944 detect simultaneous editing of a file.)
945
946    When you are done with your editing, you must "check in" the new
947 version.  This records the new version in the master file, and unlocks
948 the source file so that other people can lock it and thus modify it.
949
950    Checkin and checkout are the basic operations of version control.
951 You can do both of them with a single Emacs command: `C-x C-q'
952 (`vc-toggle-read-only').
953
954    A "snapshot" is a coherent collection of versions of the various
955 files that make up a program.  *Note Snapshots::.
956
957 \1f
958 File: xemacs.info,  Node: Editing with VC,  Next: Variables for Check-in/out,  Prev: Concepts of VC,  Up: Version Control
959
960 Editing with Version Control
961 ----------------------------
962
963    When you visit a file that is maintained using version control, the
964 mode line displays `RCS' or `SCCS' to inform you that version control
965 is in use, and also (in case you care) which low-level system the file
966 is actually stored in.  Normally, such a source file is read-only, and
967 the mode line indicates this with `%%'.  With RCS, the mode line also
968 indicates the number of the head version, which is normally also the
969 version you are looking at.
970
971    These are the commands for editing a file maintained with version
972 control:
973
974 `C-x C-q'
975      Check the visited file in or out.
976
977 `C-x v u'
978      Revert the buffer and the file to the last checked in version.
979
980 `C-x v c'
981      Remove the last-entered change from the master for the visited
982      file.  This undoes your last check-in.
983
984 `C-x v i'
985      Register the visited file in version control.
986
987 (`C-x v' is the prefix key for version control commands; all of these
988 commands except for `C-x C-q' start with `C-x v'.)
989
990    When you want to modify a file maintained with version control, type
991 `C-x C-q' (`vc-toggle-read-only').  This "checks out" the file, and
992 tells RCS or SCCS to lock the file.  This means making the file
993 writable for you (but not for anyone else).
994
995    When you are finished editing the file, type `C-x C-q' again.  When
996 used on a file that is checked out, this command checks the file in.
997 But check-in does not start immediately; first, you must enter the "log
998 entry"--a description of the changes in the new version.  `C-x C-q'
999 pops up a buffer for you to enter this in.  When you are finished
1000 typing in the log entry, type `C-c C-c' to terminate it; this is when
1001 actual check-in takes place.
1002
1003    Once you have checked in your changes, the file is unlocked, so that
1004 other users can lock it and modify it.
1005
1006    Emacs does not save backup files for source files that are maintained
1007 with version control.  If you want to make backup files despite version
1008 control, set the variable `vc-make-backup-files' to a non-`nil' value.
1009
1010    Normally the work file exists all the time, whether it is locked or
1011 not.  If you set `vc-keep-workfiles' to `nil', then checking in a new
1012 version with `C-x C-q' deletes the work file; but any attempt to visit
1013 the file with Emacs creates it again.
1014
1015    It is not impossible to lock a file that someone else has locked.  If
1016 you try to check out a file that is locked, `C-x C-q' asks you whether
1017 you want to "steal the lock."  If you say yes, the file becomes locked
1018 by you, but a message is sent to the person who had formerly locked the
1019 file, to inform him of what has happened.  The mode line indicates that
1020 a file is locked by someone else by displaying the login name of that
1021 person, before the version number.
1022
1023    If you want to discard your current set of changes and revert to the
1024 last version checked in, use `C-x v u' (`vc-revert-buffer').  This
1025 cancels your last check-out, leaving the file unlocked.  If you want to
1026 make a different set of changes, you must first check the file out
1027 again.  `C-x v u' requires confirmation, unless it sees that you
1028 haven't made any changes since the last checked-in version.
1029
1030    `C-x v u' is also the command to use if you lock a file and then
1031 don't actually change it.
1032
1033    You can cancel a change after checking it in, with `C-x v c'
1034 (`vc-cancel-version').  This command discards all record of the most
1035 recent checked in version, so be careful about using it.  It requires
1036 confirmation with `yes'.  By default, `C-x v c' reverts your workfile
1037 and buffer to the previous version (the one that precedes the version
1038 that is deleted), but you can prevent the reversion by giving the
1039 command a prefix argument.  Then the buffer does not change.
1040
1041    This command with a prefix argument is useful when you have checked
1042 in a change and then discover a trivial error in it; you can cancel the
1043 erroneous check-in, fix the error, and repeat the check-in.
1044
1045    Be careful when invoking `C-x v c', as it is easy to throw away a
1046 lot of work with it.  To help you be careful, this command always
1047 requires confirmation with `yes'.
1048
1049    You can register the visited file for version control using
1050 `C-x v i' (`vc-register').  If the variable `vc-default-back-end' is
1051 non-`nil', it specifies which version control system to use; otherwise,
1052 this uses RCS if it is installed on your system and SCCS if not.  After
1053 `C-x v i', the file is unlocked and read-only.  Type `C-x C-q' if you
1054 wish to edit it.
1055
1056    By default, the initial version number is 1.1.  If you want to use a
1057 different number, give `C-x v i' a prefix argument; then it reads the
1058 initial version number using the minibuffer.
1059
1060    If `vc-initial-comment' is non-`nil', `C-x v i' reads an initial
1061 comment (much like a log entry) to describe the purpose of this source
1062 file.
1063
1064    To specify the version number for a subsequent checkin, use the
1065 command `C-u C-x v v'.  `C-x v v' (`vc-next-action') is the command
1066 that `C-x C-q' uses to do the "real work" when the visited file uses
1067 version control.  When used for checkin, and given a prefix argument,
1068 it reads the version number with the minibuffer.
1069