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