home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / VRAC / E17INFO.ZIP / EMACS-6 < prev    next >
Encoding:
GNU Info File  |  1993-07-18  |  47.9 KB  |  1,090 lines

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