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