home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / os2 / e17info.zip / EMACS / 19.17 / INFO / EMACS-6 (.txt) < prev    next >
GNU Info File  |  1993-07-18  |  49KB  |  837 lines

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