home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / emacs.i05 (.txt) < prev    next >
GNU Info File  |  1993-06-14  |  52KB  |  861 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.47 from the
  2. input file emacs.tex.
  3.    This file documents the GNU Emacs editor.
  4.    Copyright (C) 1985, 1986, 1988 Richard M. Stallman.
  5.    Permission is granted to make and distribute verbatim copies of this
  6. manual provided the copyright notice and this permission notice are
  7. preserved on all copies.
  8.    Permission is granted to copy and distribute modified versions of
  9. this manual under the conditions for verbatim copying, provided also
  10. that the sections entitled "The GNU Manifesto", "Distribution" and "GNU
  11. General Public License" are included exactly as in the original, and
  12. provided that the entire resulting derived work is distributed under the
  13. terms of a permission notice identical to this one.
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that the sections entitled "The GNU Manifesto",
  17. "Distribution" and "GNU General Public License" may be included in a
  18. translation approved by the author instead of in the original English.
  19. File: emacs,  Node: Visiting,  Next: Saving,  Prev: File Names,  Up: Files
  20. Visiting Files
  21. ==============
  22. `C-x C-f'
  23.      Visit a file (`find-file').
  24. `C-x C-v'
  25.      Visit a different file instead of the one visited last
  26.      (`find-alternate-file').
  27. `C-x 4 C-f'
  28.      Visit a file, in another window (`find-file-other-window').  Don't
  29.      change this window.
  30.    "Visiting" a file means copying its contents into Emacs where you can
  31. edit them.  Emacs makes a new buffer for each file that you visit.  We
  32. say that the buffer is visiting the file that it was created to hold. 
  33. Emacs constructs the buffer name from the file name by throwing away the
  34. directory, keeping just the name proper.  For example, a file named
  35. `/usr/rms/emacs.tex' would get a buffer named `emacs.tex'.  If there is
  36. already a buffer with that name, a unique name is constructed by
  37. appending `<2>', `<3>', or so on, using the lowest number that makes a
  38. name that is not already in use.
  39.    Each window's mode line shows the name of the buffer that is being
  40. displayed in that window, so you can always tell what buffer you are
  41. editing.
  42.    The changes you make with Emacs are made in the Emacs buffer.  They
  43. do not take effect in the file that you visited, or any place
  44. permanent, until you "save" the buffer.  Saving the buffer means that
  45. Emacs writes the current contents of the buffer into its visited file. 
  46. *Note Saving::.
  47.    If a buffer contains changes that have not been saved, the buffer is
  48. said to be "modified".  This is important because it implies that some
  49. changes will be lost if the buffer is not saved.  The mode line displays
  50. two stars near the left margin if the buffer is modified.
  51.    To visit a file, use the command `C-x C-f' (`find-file').  Follow
  52. the command with the name of the file you wish to visit, terminated by a
  53.    The file name is read using the minibuffer (*note Minibuffer::.),
  54. with defaulting and completion in the standard manner (*note File
  55. Names::.). While in the minibuffer, you can abort `C-x C-f' by typing
  56. `C-g'.
  57.    Your confirmation that `C-x C-f' has completed successfully is the
  58. appearance of new text on the screen and a new buffer name in the mode
  59. line.  If the specified file does not exist and could not be created, or
  60. cannot be read, then an error results.  The error message is printed in
  61. the echo area, and includes the file name which Emacs was trying to
  62. visit.
  63.    If you visit a file that is already in Emacs, `C-x C-f' does not make
  64. another copy.  It selects the existing buffer containing that file.
  65. However, before doing so, it checks that the file itself has not changed
  66. since you visited or saved it last.  If the file has changed, a warning
  67. message is printed.  *Note Simultaneous Editing: Interlocking.
  68.    What if you want to create a file?  Just visit it.  Emacs prints
  69. `(New File)' in the echo area, but in other respects behaves as if you
  70. had visited an existing empty file.  If you make any changes and save
  71. them, the file is created.
  72.    If you visit a nonexistent file unintentionally (because you typed
  73. the wrong file name), use the `C-x C-v' (`find-alternate-file') command
  74. to visit the file you wanted.  `C-x C-v' is similar to `C-x C-f', but
  75. it kills the current buffer (after first offering to save it if it is
  76. modified).  `C-x C-v' is allowed even if the current buffer is not
  77. visiting a file.
  78.    If the file you specify is actually a directory, Dired is called on
  79. that directory (*note Dired::.).  This can be inhibited by setting the
  80. variable `find-file-run-dired' to `nil'; then it is an error to try to
  81. visit a directory.
  82.    `C-x 4 f' (`find-file-other-window') is like `C-x C-f' except that
  83. the buffer containing the specified file is selected in another window.
  84.  The window that was selected before `C-x 4 f' continues to show the
  85. same buffer it was already showing.  If this command is used when only
  86. one window is being displayed, that window is split in two, with one
  87. window showing the same before as before, and the other one showing the
  88. newly requested file.  *Note Windows::.
  89.    There are two hook variables that allow extensions to modify the
  90. operation of visiting files.  Visiting a file that does not exist runs
  91. the functions in the list `find-file-not-found-hooks'; the value of this
  92. variable is expected to be a list of functions, and the functions are
  93. called one by one until one of them returns non-`nil'.  Any visiting of
  94. a file, whether extant or not, expects `find-file-hooks' to contain
  95. list of functions and calls them all, one by one.  In both cases the
  96. functions receive no arguments.  Visiting a nonexistent file runs the
  97. `find-file-not-found-hooks' first.
  98. File: emacs,  Node: Saving,  Next: Reverting,  Prev: Visiting,  Up: Files
  99. Saving Files
  100. ============
  101.    "Saving" a buffer in Emacs means writing its contents back into the
  102. file that was visited in the buffer.
  103. `C-x C-s'
  104.      Save the current buffer in its visited file (`save-buffer').
  105. `C-x s'
  106.      Save any or all buffers in their visited files
  107.      (`save-some-buffers').
  108. `M-~'
  109.      Forget that the current buffer has been changed (`not-modified').
  110. `C-x C-w'
  111.      Save the current buffer in a specified file, and record that file
  112.      as the one visited in the buffer (`write-file').
  113. `M-x set-visited-file-name'
  114.      Change file the name under which the current buffer will be saved.
  115.    When you wish to save the file and make your changes permanent, type
  116. `C-x C-s' (`save-buffer').  After saving is finished, `C-x C-s' prints
  117. a message such as
  118.      Wrote /u/rms/gnu/gnu.tasks
  119. If the selected buffer is not modified (no changes have been made in it
  120. since the buffer was created or last saved), saving is not really done,
  121. because it would have no effect.  Instead, `C-x C-s' prints a message
  122. in the echo area saying
  123.      (No changes need to be written)
  124.    The command `C-x s' (`save-some-buffers') can save any or all
  125. modified buffers.  First it asks, for each modified buffer, whether to
  126. save it. These questions should be answered with `y' or `n'.  `C-x C-c',
  127. the key that kills Emacs, invokes `save-some-buffers' and therefore
  128. asks the same questions.
  129.    If you have changed a buffer and do not want the changes to be
  130. saved, you should take some action to prevent it.  Otherwise, each time
  131. you use `save-some-buffers' you are liable to save it by mistake.  One
  132. thing you can do is type `M-~' (`not-modified'), which clears out the
  133. indication that the buffer is modified.  If you do this, none of the
  134. save commands will believe that the buffer needs to be saved.  (`~' is
  135. often used as a mathematical symbol for `not'; thus `Meta-~' is `not',
  136. metafied.) You could also use `set-visited-file-name' (see below) to
  137. mark the buffer as visiting a different file name, one which is not in
  138. use for anything important.  Alternatively, you can undo all the
  139. changes made since the file was visited or saved, by reading the text
  140. from the file again. This is called "reverting".  *Note Reverting::. 
  141. You could also undo all the changes by repeating the undo command `C-x
  142. u' until you have undone all the changes; but this only works if you
  143. have not made more changes than the undo mechanism can remember.
  144.    `M-x set-visited-file-name' alters the name of the file that the
  145. current buffer is visiting.  It reads the new file name using the
  146. minibuffer.  It can be used on a buffer that is not visiting a file,
  147. too. The buffer's name is changed to correspond to the file it is now
  148. visiting in the usual fashion (unless the new name is in use already
  149. for some other buffer; in that case, the buffer name is not changed).
  150. `set-visited-file-name' does not save the buffer in the newly visited
  151. file; it just alters the records inside Emacs so that, if you save the
  152. buffer, it will be saved in that file.  It also marks the buffer as
  153. "modified" so that `C-x C-s' will save.
  154.    If you wish to mark the buffer as visiting a different file and save
  155. it right away, use `C-x C-w' (`write-file').  It is precisely
  156. equivalent to `set-visited-file-name' followed by `C-x C-s'. `C-x C-s'
  157. used on a buffer that is not visiting with a file has the same effect
  158. as `C-x C-w'; that is, it reads a file name, marks the buffer as
  159. visiting that file, and saves it there.  The default file name in a
  160. buffer that is not visiting a file is made by combining the buffer name
  161. with the buffer's default directory.
  162.    If Emacs is about to save a file and sees that the date of the latest
  163. version on disk does not match what Emacs last read or wrote, Emacs
  164. notifies you of this fact, because it probably indicates a problem
  165. caused by simultaneous editing and requires your immediate attention.
  166. *Note Simultaneous Editing: Interlocking.
  167.    If the variable `require-final-newline' is non-`nil', Emacs puts a
  168. newline at the end of any file that doesn't already end in one, every
  169. time a file is saved or written.
  170.    You can implement other ways to write files, and other things to be
  171. done before writing them, using the hook variable `write-file-hooks'. 
  172. The value of this variable should be a list of Lisp functions.  When a
  173. file is to be written, the functions in the list are called, one by
  174. one, with no arguments.  If one of them returns a non-`nil' value,
  175. Emacs takes this to mean that the file has been written in some
  176. suitable fashion; the rest of the functions are not called, and normal
  177. writing is not done.
  178. * Menu:
  179. * Backup::       How Emacs saves the old version of your file.
  180. * Interlocking:: How Emacs protects against simultaneous editing
  181.                   of one file by two users.
  182. File: emacs,  Node: Backup,  Next: Interlocking,  Prev: Saving,  Up: Saving
  183. Backup Files
  184. ------------
  185.    Because Unix does not provide version numbers in file names,
  186. rewriting a file in Unix automatically destroys all record of what the
  187. file used to contain.  Thus, saving a file from Emacs throws away the
  188. old contents of the file--or it would, except that Emacs carefully
  189. copies the old contents to another file, called the "backup" file,
  190. before actually saving. (Provided the variable `make-backup-files' is
  191. non-`nil'. Backup files are not written if this variable is `nil').
  192.    At your option, Emacs can keep either a single backup file or a
  193. series of numbered backup files for each file that you edit.
  194.    Emacs makes a backup for a file only the first time the file is saved
  195. from one buffer.  No matter how many times you save a file, its backup
  196. file continues to contain the contents from before the file was visited.
  197. Normally this means that the backup file contains the contents from
  198. before the current editing session; however, if you kill the buffer and
  199. then visit the file again, a new backup file will be made by the next
  200. save.
  201. * Menu:
  202. * Names: Backup Names.        How backup files are named;
  203.                 Choosing single or numbered backup files.
  204. * Deletion: Backup Deletion.    Emacs deletes excess numbered backups.
  205. * Copying: Backup Copying.    Backups can be made by copying or renaming.
  206. File: emacs,  Node: Backup Names,  Next: Backup Deletion,  Prev: Backup,  Up: Backup
  207. Single or Numbered Backups
  208. ..........................
  209.    If you choose to have a single backup file (this is the default),
  210. the backup file's name is constructed by appending `~' to the file name
  211. being edited; thus, the backup file for `eval.c' would be `eval.c~'.
  212.    If you choose to have a series of numbered backup files, backup file
  213. names are made by appending `.~', the number, and another `~' to the
  214. original file name.  Thus, the backup files of `eval.c' would be called
  215. `eval.c.~1~', `eval.c.~2~', and so on, through names like
  216. `eval.c.~259~' and beyond.
  217.    If protection stops you from writing backup files under the usual
  218. names, the backup file is written as `%backup%~' in your home directory.
  219. Only one such file can exist, so only the most recently made such
  220. backup is available.
  221.    The choice of single backup or numbered backups is controlled by the
  222. variable `version-control'.  Its possible values are
  223.      Make numbered backups.
  224. `nil'
  225.      Make numbered backups for files that have numbered backups already.
  226.      Otherwise, make single backups.
  227. `never'
  228.      Do not in any case make numbered backups; always make single
  229.      backups.
  230. `version-control' may be set locally in an individual buffer to control
  231. the making of backups for that buffer's file.  For example, Rmail mode
  232. locally sets `version-control' to `never' to make sure that there is
  233. only one backup for an Rmail file.  *Note Locals::.
  234. File: emacs,  Node: Backup Deletion,  Next: Backup Copying,  Prev: Backup Names,  Up: Backup
  235. Automatic Deletion of Backups
  236. .............................
  237.    To prevent unlimited consumption of disk space, Emacs can delete
  238. numbered backup versions automatically.  Generally Emacs keeps the
  239. first few backups and the latest few backups, deleting any in between. 
  240. This happens every time a new backup is made.  The two variables that
  241. control the deletion are `kept-old-versions' and `kept-new-versions'. 
  242. Their values are, respectively the number of oldest (lowest-numbered)
  243. backups to keep and the number of newest (highest-numbered) ones to
  244. keep, each time a new backup is made. Recall that these values are used
  245. just after a new backup version is made; that newly made backup is
  246. included in the count in `kept-new-versions'. By default, both
  247. variables are 2.
  248.    If `trim-versions-without-asking' is non-`nil', the excess middle
  249. versions are deleted without a murmur.  If it is `nil', the default,
  250. then you are asked whether the excess middle versions should really be
  251. deleted.
  252.    Dired's `.' (Period) command can also be used to delete old versions.
  253. *Note Dired::.
  254. File: emacs,  Node: Backup Copying,  Prev: Backup Deletion,  Up: Backup
  255. Copying vs. Renaming
  256. ....................
  257.    Backup files can be made by copying the old file or by renaming it. 
  258. This makes a difference when the old file has multiple names.  If the
  259. old file is renamed into the backup file, then the alternate names
  260. become names for the backup file.  If the old file is copied instead,
  261. then the alternate names remain names for the file that you are
  262. editing, and the contents accessed by those names will be the new
  263. contents.
  264.    The method of making a backup file may also affect the file's owner
  265. and group.  If copying is used, these do not change.  If renaming is
  266. used, you become the file's owner, and the file's group becomes the
  267. default (different operating systems have different defaults for the
  268. group).
  269.    Having the owner change is usually a good idea, because then the
  270. owner always shows who last edited the file.  Also, the owners of the
  271. backups show who produced those versions.  Occasionally there is a file
  272. whose owner should not change; it is a good idea for such files to
  273. contain local variable lists to set `backup-by-copying-when-mismatch'
  274. for them alone (*note File Variables::.).
  275.    The choice of renaming or copying is controlled by three variables.
  276. Normally, renaming is done.  If the variable `backup-by-copying' is
  277. non-`nil', copying is used.  Otherwise, if the variable
  278. `backup-by-copying-when-linked' is non-`nil', then copying is done for
  279. files that have multiple names, but renaming may still done when the
  280. file being edited has only one name.  If the variable
  281. `backup-by-copying-when-mismatch' is non-`nil', then copying is done if
  282. renaming would cause the file's owner or group to change.
  283. File: emacs,  Node: Interlocking,  Prev: Backup,  Up: Saving
  284. Protection against Simultaneous Editing
  285. ---------------------------------------
  286.    Simultaneous editing occurs when two users visit the same file, both
  287. make changes, and then both save them.  If nobody were informed that
  288. this was happening, whichever user saved first would later find that
  289. his changes were lost.  On some systems, Emacs notices immediately when
  290. the second user starts to change the file, and issues an immediate
  291. warning.  When this is not possible, or if the second user has gone on
  292. to change the file despite the warning, Emacs checks later when the
  293. file is saved, and issues a second warning when a user is about to
  294. overwrite a file containing another user's changes.  If the editing
  295. user takes the proper corrective action at this point, he can prevent
  296. actual loss of work.
  297.    When you make the first modification in an Emacs buffer that is
  298. visiting a file, Emacs records that you have locked the file.  (It does
  299. this by writing another file in a directory reserved for this purpose.)
  300.  The lock is removed when you save the changes.  The idea is that the
  301. file is locked whenever the buffer is modified.  If you begin to modify
  302. the buffer while the visited file is locked by someone else, this
  303. constitutes a collision, and Emacs asks you what to do.  It does this
  304. by calling the Lisp function `ask-user-about-lock', which you can
  305. redefine for the sake of customization.  The standard definition of
  306. this function asks you a question and accepts three possible answers:
  307.      Steal the lock.  Whoever was already changing the file loses the
  308.      lock, and you gain the lock.
  309.      Proceed.  Go ahead and edit the file despite its being locked by
  310.      someone else.
  311.      Quit.  This causes an error (`file-locked') and the modification
  312.      you were trying to make in the buffer does not actually take place.
  313.    Note that locking works on the basis of a file name; if a file has
  314. multiple names, Emacs does not realize that the two names are the same
  315. file and cannot prevent two user from editing it simultaneously under
  316. different names.  However, basing locking on names means that Emacs can
  317. interlock the editing of new files that will not really exist until
  318. they are saved.
  319.    Some systems are not configured to allow Emacs to make locks.  On
  320. these systems, Emacs cannot detect trouble in advance, but it still can
  321. detect it in time to prevent you from overwriting someone else's
  322. changes.
  323.    Every time Emacs saves a buffer, it first checks the
  324. last-modification date of the existing file on disk to see that it has
  325. not changed since the file was last visited or saved.  If the date does
  326. not match, it implies that changes were made in the file in some other
  327. way, and these changes are about to be lost if Emacs actually does
  328. save.  To prevent this, Emacs prints a warning message and asks for
  329. confirmation before saving. Occasionally you will know why the file was
  330. changed and know that it does not matter; then you can answer `yes' and
  331. proceed.  Otherwise, you should cancel the save with `C-g' and
  332. investigate the situation.
  333.    The first thing you should do when notified that simultaneous
  334. editing has already taken place is to list the directory with `C-u C-x
  335. C-d' (*note Directory Listing: ListDir.).  This will show the file's
  336. current author.  You should attempt to contact him to warn him not to
  337. continue editing.  Often the next step is to save the contents of your
  338. Emacs buffer under a different name, and use `diff' to compare the two
  339. files.
  340.    Simultaneous editing checks are also made when you visit with `C-x
  341. C-f' a file that is already visited and when you start to modify a file.
  342. This is not strictly necessary, but it can cause you to find out about
  343. the problem earlier, when perhaps correction takes less work.
  344. File: emacs,  Node: Reverting,  Next: Auto Save,  Prev: Saving,  Up: Files
  345. Reverting a Buffer
  346. ==================
  347.    If you have made extensive changes to a file and then change your
  348. mind about them, you can get rid of them by reading in the previous
  349. version of the file.  To do this, use `M-x revert-buffer', which
  350. operates on the current buffer.  Since this is a very dangerous thing
  351. to do, you must confirm it with `yes'.
  352.    If the current buffer has been auto-saved more recently than it has
  353. been saved for real, `revert-buffer' offers to read the auto save file
  354. instead of the visited file (*note Auto Save::.).  This question comes
  355. before the usual request for confirmation, and demands `y' or `n' as an
  356. answer.  If you have started to type `yes' for confirmation without
  357. realizing that the other question was going to be asked, the `y' will
  358. answer that question, but the `es' will not be valid confirmation.  So
  359. you will have a chance to cancel the operation with `C-g' and try it
  360. again with the answers that you really intend.
  361.    `revert-buffer' keeps point at the same distance (measured in
  362. characters) from the beginning of the file.  If the file was edited only
  363. slightly, you will be at approximately the same piece of text after
  364. reverting as before.  If you have made drastic changes, the same value
  365. of point in the old file may address a totally different piece of text.
  366.    A buffer reverted from its visited file is marked "not modified"
  367. until another change is made.
  368.    Some kinds of buffers whose contents reflect data bases other than
  369. files, such as Dired buffers, can also be reverted.  For them,
  370. reverting means recalculating their contents from the appropriate data
  371. base.  Buffers created randomly with `C-x b' cannot be reverted;
  372. `revert-buffer' reports an error when asked to do so.
  373. File: emacs,  Node: Auto Save,  Next: ListDir,  Prev: Reverting,  Up: Files
  374. Auto-Saving: Protection Against Disasters
  375. =========================================
  376.    Emacs saves all the visited files from time to time (based on
  377. counting your keystrokes) without being asked.  This is called
  378. "auto-saving". It prevents you from losing more than a limited amount
  379. of work if the system crashes.
  380.    When Emacs determines that it is time for auto-saving, each buffer is
  381. considered, and is auto-saved if auto-saving is turned on for it and it
  382. has been changed since the last time it was auto-saved.  If any
  383. auto-saving is done, the message `Auto-saving...' is displayed in the
  384. echo area until auto-saving is finished.  Errors occurring during
  385. auto-saving are caught so that they do not interfere with the execution
  386. of commands you have been typing.
  387. * Menu:
  388. * Files: Auto Save Files.
  389. * Control: Auto Save Control.
  390. * Recover::        Recovering text from auto-save files.
  391. File: emacs,  Node: Auto Save Files,  Next: Auto Save Control,  Prev: Auto Save,  Up: Auto Save
  392. Auto-Save Files
  393. ---------------
  394.    Auto-saving does not normally save in the files that you visited,
  395. because it can be very undesirable to save a program that is in an
  396. inconsistent state when you have made half of a planned change. 
  397. Instead, auto-saving is done in a different file called the "auto-save
  398. file", and the visited file is changed only when you request saving
  399. explicitly (such as with `C-x C-s').
  400.    Normally, the auto-save file name is made by appending `#' to the
  401. front and rear of the visited file name.  Thus, a buffer visiting file
  402. `foo.c' would be auto-saved in a file `#foo.c#'.  Most buffers that are
  403. not visiting files are auto-saved only if you request it explicitly;
  404. when they are auto-saved, the auto-save file name is made by appending
  405. `#%' to the front and `#' to the rear of buffer name. For example, the
  406. `*mail*' buffer in which you compose messages to be sent is auto-saved
  407. in a file named `#%*mail*#'.  Auto-save file names are made this way
  408. unless you reprogram parts of Emacs to do something different (the
  409. functions `make-auto-save-file-name' and `auto-save-file-name-p').  The
  410. file name to be used for auto-saving in a buffer is calculated when
  411. auto-saving is turned on in that buffer.
  412.    If you want auto-saving to be done in the visited file, set the
  413. variable `auto-save-visited-file-name' to be non-`nil'.  In this mode,
  414. there is really no difference between auto-saving and explicit saving.
  415.    A buffer's auto-save file is deleted when you save the buffer in its
  416. visited file.  To inhibit this, set the variable
  417. `delete-auto-save-files' to `nil'.  Changing the visited file name with
  418. `C-x C-w' or `set-visited-file-name' renames any auto-save file to go
  419. with the new visited name.
  420. File: emacs,  Node: Auto Save Control,  Next: Recover,  Prev: Auto Save Files,  Up: Auto Save
  421. Controlling Auto-Saving
  422. -----------------------
  423.    Each time you visit a file, auto-saving is turned on for that file's
  424. buffer if the variable `auto-save-default' is non-`nil' (but not in
  425. batch mode; *note Entering Emacs::.).  The default for this variable is
  426. `t', so auto-saving is the usual practice for file-visiting buffers.
  427. Auto-saving can be turned on or off for any existing buffer with the
  428. command `M-x auto-save-mode'.  Like other minor mode commands, `M-x
  429. auto-save-mode' turns auto-saving on with a positive argument, off with
  430. a zero or negative argument; with no argument, it toggles.
  431.    Emacs does auto-saving periodically based on counting how many
  432. characters you have typed since the last time auto-saving was done. 
  433. The variable `auto-save-interval' specifies how many characters there
  434. are between auto-saves.  By default, it is 300.  Emacs also auto-saves
  435. whenever you call the function `do-auto-save'.
  436.    Emacs also does auto-saving whenever it gets a fatal error.  This
  437. includes killing the Emacs job with a shell command such as `kill
  438. %emacs', or disconnecting a phone line or network connection.
  439. File: emacs,  Node: Recover,  Prev: Auto Save Control,  Up: Auto Save
  440. Recovering Data from Auto-Saves
  441. -------------------------------
  442.    The way to use the contents of an auto-save file to recover from a
  443. loss of data is with the command `M-x recover-file RET FILE RET'.  This
  444. visits FILE and then (after your confirmation) restores the contents
  445. from from its auto-save file `#FILE#'.  You can then save with `C-x
  446. C-s' to put the recovered text into FILE itself.  For example, to
  447. recover file `foo.c' from its auto-save file `#foo.c#', do:
  448.      M-x recover-file RET foo.c RET
  449.      C-x C-s
  450.    Before asking for confirmation, `M-x recover-file' displays a
  451. directory listing describing the specified file and the auto-save file,
  452. so you can compare their sizes and dates.  If the auto-save file is
  453. older, `M-x recover-file' does not offer to read it.
  454.    Auto-saving is disabled by `M-x recover-file' because using this
  455. command implies that the auto-save file contains valuable data from a
  456. past session.  If you save the data in the visited file and then go on
  457. to make new changes, you should turn auto-saving back on with `M-x
  458. auto-save-mode'.
  459. File: emacs,  Node: ListDir,  Next: Dired,  Prev: Auto Save,  Up: Files
  460. Listing a File Directory
  461. ========================
  462.    Files are classified by Unix into "directories".  A "directory
  463. listing" is a list of all the files in a directory.  Emacs provides
  464. directory listings in brief format (file names only) and verbose format
  465. (sizes, dates, and authors included).
  466. `C-x C-d DIR-OR-PATTERN'
  467.      Print a brief directory listing (`list-directory').
  468. `C-u C-x C-d DIR-OR-PATTERN'
  469.      Print a verbose directory listing.
  470.    The command to print a directory listing is `C-x C-d'
  471. (`list-directory'). It reads using the minibuffer a file name which is
  472. either a directory to be listed or a wildcard-containing pattern for
  473. the files to be listed.  For example,
  474.      C-x C-d /u2/emacs/etc RET
  475. lists all the files in directory `/u2/emacs/etc'.  An example of
  476. specifying a file name pattern is
  477.      C-x C-d /u2/emacs/src/*.c RET
  478.    Normally, `C-x C-d' prints a brief directory listing containing just
  479. file names.  A numeric argument (regardless of value) tells it to print
  480. a verbose listing (like `ls -l').
  481.    The text of a directory listing is obtained by running `ls' in an
  482. inferior process.  Two Emacs variables control the switches passed to
  483. `ls': `list-directory-brief-switches' is a string giving the switches
  484. to use in brief listings (`"-CF"' by default), and
  485. `list-directory-verbose-switches' is a string giving the switches to
  486. use in a verbose listing (`"-l"' by default).
  487. File: emacs,  Node: Dired,  Next: Misc File Ops,  Prev: ListDir,  Up: Files
  488. Dired, the Directory Editor
  489. ===========================
  490.    Dired makes it easy to delete or visit many of the files in a single
  491. directory at once.  It makes an Emacs buffer containing a listing of the
  492. directory.  You can use the normal Emacs commands to move around in this
  493. buffer, and special Dired commands to operate on the files.
  494. * Menu:
  495. * Enter: Dired Enter.         How to invoke Dired.
  496. * Edit: Dired Edit.           Editing the Dired buffer.
  497. * Deletion: Dired Deletion.   Deleting files with Dired.
  498. * Immed: Dired Immed.         Other file operations through Dired.
  499. File: emacs,  Node: Dired Enter,  Next: Dired Edit,  Prev: Dired,  Up: Dired
  500. Entering Dired
  501. --------------
  502.    To invoke dired, do `C-x d' or `M-x dired'.  The command reads a
  503. directory name or wildcard file name pattern as a minibuffer argument
  504. just like the `list-directory' command, `C-x C-d'.  Where `dired'
  505. differs from `list-directory' is in naming the buffer after the
  506. directory name or the wildcard pattern used for the listing, and putting
  507. the buffer into Dired mode so that the special commands of Dired are
  508. available in it.  The variable `dired-listing-switches' is a string
  509. used as an argument to `ls' in making the directory; this string must
  510. contain `-l'.
  511.    To display the Dired buffer in another window rather than in the
  512. selected window, use `C-x 4 d' (`dired-other-window)' instead of `C-x
  513. File: emacs,  Node: Dired Edit,  Next: Dired Deletion,  Prev: Dired Enter,  Up: Dired
  514. Editing in Dired
  515. ----------------
  516.    Once the Dired buffer exists, you can switch freely between it and
  517. other Emacs buffers.  Whenever the Dired buffer is selected, certain
  518. special commands are provided that operate on files that are listed. 
  519. The Dired buffer is "read-only", and inserting text in it is not
  520. useful, so ordinary printing characters such as `d' and `x' are used
  521. for Dired commands.  Most Dired commands operate on the file described
  522. by the line that point is on.  Some commands perform operations
  523. immediately; others "flag" the file to be operated on later.
  524.    Most Dired commands that operate on the current line's file also
  525. treat a numeric argument as a repeat count, meaning to act on the files
  526. of the next few lines.  A negative argument means to operate on the
  527. files of the preceding lines, and leave point on the first of those
  528. lines.
  529.    All the usual Emacs cursor motion commands are available in Dired
  530. buffers.  Some special purpose commands are also provided.  The keys
  531. `C-n' and `C-p' are redefined so that they try to position the cursor
  532. at the beginning of the filename on the line, rather than at the
  533. beginning of the line.
  534.    For extra convenience, SPC and `n' in Dired are equivalent to `C-n'.
  535.  `p' is equivalent to `C-p'.  Moving by lines is done so often in Dired
  536. that it deserves to be easy to type.  DEL (move up and unflag) is often
  537. useful simply for moving up.
  538.    The `g' command in Dired runs `revert-buffer' to reinitialize the
  539. buffer from the actual disk directory and show any changes made in the
  540. directory by programs other than Dired.  All deletion flags in the Dired
  541. buffer are lost when this is done.
  542. File: emacs,  Node: Dired Deletion,  Next: Dired Immed,  Prev: Dired Edit,  Up: Dired
  543. Deleting Files with Dired
  544. -------------------------
  545.    The primary use of Dired is to flag files for deletion and then
  546. delete them.
  547.      Flag this file for deletion.
  548.      Remove deletion-flag on this line.
  549. `DEL'
  550.      Remove deletion-flag on previous line, moving point to that line.
  551.      Delete the files that are flagged for deletion.
  552.      Flag all auto-save files (files whose names start and end with `#')
  553.      for deletion (*note Auto Save::.).
  554.      Flag all backup files (files whose names end with `~') for deletion
  555.      (*note Backup::.).
  556. `. (Period)'
  557.      Flag excess numeric backup files for deletion.  The oldest and
  558.      newest few backup files of any one file are exempt; the middle
  559.      ones are flagged.
  560.    You can flag a file for deletion by moving to the line describing the
  561. file and typing `d' or `C-d'.  The deletion flag is visible as a `D' at
  562. the beginning of the line.  Point is moved to the beginning of the next
  563. line, so that repeated `d' commands flag successive files.
  564.    The files are flagged for deletion rather than deleted immediately to
  565. avoid the danger of deleting a file accidentally.  Until you direct
  566. Dired to delete the flagged files, you can remove deletion flags using
  567. the commands `u' and DEL.  `u' works just like `d', but removes flags
  568. rather than making flags.  DEL moves upward, removing flags; it is like
  569. `u' with numeric argument automatically negated.
  570.    To delete the flagged files, type `x'.  This command first displays a
  571. list of all the file names flagged for deletion, and requests
  572. confirmation with `yes'.  Once you confirm, all the flagged files are
  573. deleted, and their lines are deleted from the text of the Dired buffer.
  574.  The shortened Dired buffer remains selected.  If you answer `no' or
  575. quit with `C-g', you return immediately to Dired, with the deletion
  576. flags still present and no files actually deleted.
  577.    The `#', `~' and `.' commands flag many files for deletion, based on
  578. their names.  These commands are useful precisely because they do not
  579. actually delete any files; you can remove the deletion flags from any
  580. flagged files that you really wish to keep.
  581.    `#' flags for deletion all files that appear to have been made by
  582. auto-saving (that is, files whose names begin and end with `#'). `~'
  583. flags for deletion all files that appear to have been made as backups
  584. for files that were edited (that is, files whose names end with `~').
  585.    `.' (Period) flags just some of the backup files for deletion: only
  586. numeric backups that are not among the oldest few nor the newest few
  587. backups of any one file.  Normally `dired-kept-versions' (not
  588. `kept-new-versions'; that applies only when saving) specifies the
  589. number of newest versions of each file to keep, and `kept-old-versions'
  590. specifies the number of oldest versions to keep. Period with a positive
  591. numeric argument, as in `C-u 3 .', specifies the number of newest
  592. versions to keep, overriding `dired-kept-versions'. A negative numeric
  593. argument overrides `kept-old-versions', using minus the value of the
  594. argument to specify the number of oldest versions of each file to keep.
  595. File: emacs,  Node: Dired Immed,  Prev: Dired Deletion,  Up: Dired
  596. Immediate File Operations in Dired
  597. ----------------------------------
  598.    Some file operations in Dired take place immediately when they are
  599. requested.
  600.      Copies the file described on the current line.  You must supply a
  601.      file name to copy to, using the minibuffer.
  602.      Visits the file described on the current line.  It is just like
  603.      typing `C-x C-f' and supplying that file name.  If the file on
  604.      this line is a subdirectory, `f' actually causes Dired to be
  605.      invoked on that subdirectory.  *Note Visiting::.
  606.      Like `f', but uses another window to display the file's buffer. 
  607.      The Dired buffer remains visible in the first window.  This is
  608.      like using `C-x 4 C-f' to visit the file.  *Note Windows::.
  609.      Renames the file described on the current line.  You must supply a
  610.      file name to rename to, using the minibuffer.
  611.      Views the file described on this line using `M-x view-file'. 
  612.      Viewing a file is like visiting it, but is slanted toward moving
  613.      around in the file conveniently and does not allow changing the
  614.      file.  *Note View File: Misc File Ops.  Viewing a file that is a
  615.      directory runs Dired on that directory.
  616. File: emacs,  Node: Misc File Ops,  Prev: Dired,  Up: Files
  617. Miscellaneous File Operations
  618. =============================
  619.    Emacs has commands for performing many other operations on files.
  620. All operate on one file; they do not accept wild card file names.
  621.    `M-x view-file' allows you to scan or read a file by sequential
  622. screenfuls.  It reads a file name argument using the minibuffer.  After
  623. reading the file into an Emacs buffer, `view-file' reads and displays
  624. one windowful.  You can then type SPC to scroll forward one windowful,
  625. or DEL to scroll backward.  Various other commands are provided for
  626. moving around in the file, but none for changing it; type `C-h' while
  627. viewing for a list of them.  They are mostly the same as normal Emacs
  628. cursor motion commands.  To exit from viewing, type `C-c'.
  629.    `M-x insert-file' inserts a copy of the contents of the specified
  630. file into the current buffer at point, leaving point unchanged before
  631. the contents and the mark after them.  *Note Mark::.
  632.    `M-x write-region' is the inverse of `M-x insert-file'; it copies
  633. the contents of the region into the specified file.  `M-x
  634. append-to-file' adds the text of the region to the end of the specified
  635. file.
  636.    `M-x delete-file' deletes the specified file, like the `rm' command
  637. in the shell.  If you are deleting many files in one directory, it may
  638. be more convenient to use Dired (*note Dired::.).
  639.    `M-x rename-file' reads two file names OLD and NEW using the
  640. minibuffer, then renames file OLD as NEW.  If a file named NEW already
  641. exists, you must confirm with `yes' or renaming is not done; this is
  642. because renaming causes the old meaning of the name NEW to be lost.  If
  643. OLD and NEW are on different file systems, the file OLD is copied and
  644. deleted.
  645.    The similar command `M-x add-name-to-file' is used to add an
  646. additional name to an existing file without removing its old name. The
  647. new name must belong on the same file system that the file is on.
  648.    `M-x copy-file' reads the file OLD and writes a new file named NEW
  649. with the same contents.  Confirmation is required if a file named NEW
  650. already exists, because copying has the consequence of overwriting the
  651. old contents of the file NEW.
  652.    `M-x make-symbolic-link' reads two file names OLD and LINKNAME, and
  653. then creates a symbolic link named LINKNAME and pointing at OLD. The
  654. effect is that future attempts to open file LINKNAME will refer to
  655. whatever file is named OLD at the time the opening is done, or will get
  656. an error if the name OLD is not in use at that time. Confirmation is
  657. required when creating the link if LINKNAME is in use.  Note that not
  658. all systems support symbolic links.
  659. File: emacs,  Node: Buffers,  Next: Windows,  Prev: Files,  Up: Top
  660. Using Multiple Buffers
  661. **********************
  662.    The text you are editing in Emacs resides in an object called a
  663. "buffer".  Each time you visit a file, a buffer is created to hold the
  664. file's text.  Each time you invoke Dired, a buffer is created to hold
  665. the directory listing.  If you send a message with `C-x m', a buffer
  666. named `*mail*' is used to hold the text of the message.  When you ask
  667. for a command's documentation, that appears in a buffer called `*Help*'.
  668.    At any time, one and only one buffer is "selected".  It is also
  669. called the "current buffer".  Often we say that a command operates on
  670. "the buffer" as if there were only one; but really this means that the
  671. command operates on the selected buffer (most commands do).
  672.    When Emacs makes multiple windows, each window has a chosen buffer
  673. which is displayed there, but at any time only one of the windows is
  674. selected and its chosen buffer is the selected buffer.  Each window's
  675. mode line displays the name of the buffer that the window is displaying
  676. (*note Windows::.).
  677.    Each buffer has a name, which can be of any length, and you can
  678. select any buffer by giving its name.  Most buffers are made by
  679. visiting files, and their names are derived from the files' names.  But
  680. you can also create an empty buffer with any name you want.  A newly
  681. started Emacs has a buffer named `*scratch*' which can be used for
  682. evaluating Lisp expressions in Emacs.  The distinction between upper
  683. and lower case matters in buffer names.
  684.    Each buffer records individually what file it is visiting, whether
  685. it is modified, and what major mode and minor modes are in effect in it
  686. (*note Major Modes::.).  Any Emacs variable can be made "local to" a
  687. particular buffer, meaning its value in that buffer can be different
  688. from the value in other buffers.  *Note Locals::.
  689. * Menu:
  690. * Select Buffer::   Creating a new buffer or reselecting an old one.
  691. * List Buffers::    Getting a list of buffers that exist.
  692. * Misc Buffer::     Renaming; changing read-onliness; copying text.
  693. * Kill Buffer::     Killing buffers you no longer need.
  694. * Several Buffers:: How to go through the list of all buffers
  695.                      and operate variously on several of them.
  696. File: emacs,  Node: Select Buffer,  Next: List Buffers,  Prev: Buffers,  Up: Buffers
  697. Creating and Selecting Buffers
  698. ==============================
  699. `C-x b BUFFER RET'
  700.      Select or create a buffer named BUFFER (`switch-to-buffer').
  701. `C-x 4 b BUFFER RET'
  702.      Similar but select a buffer named BUFFER in another window
  703.      (`switch-to-buffer-other-window').
  704.    To select the buffer named BUFNAME, type `C-x b BUFNAME RET'.  This
  705. is the command `switch-to-buffer' with argument BUFNAME.  You can use
  706. completion on an abbreviation for the buffer name you want (*note
  707. Completion::.).  An empty argument to `C-x b' specifies the most
  708. recently selected buffer that is not displayed in any window.
  709.    Most buffers are created by visiting files, or by Emacs commands that
  710. want to display some text, but you can also create a buffer explicitly
  711. by typing `C-x b BUFNAME RET'.  This makes a new, empty buffer which is
  712. not visiting any file, and selects it for editing.  Such buffers are
  713. used for making notes to yourself.  If you try to save one, you are
  714. asked for the file name to use.  The new buffer's major mode is
  715. determined by the value of `default-major-mode' (*note Major Modes::.).
  716.    Note that `C-x C-f', and any other command for visiting a file, can
  717. also be used to switch buffers.  *Note Visiting::.
  718. File: emacs,  Node: List Buffers,  Next: Misc Buffer,  Prev: Select Buffer,  Up: Buffers
  719. Listing Existing Buffers
  720. ========================
  721. `C-x C-b'
  722.      List the existing buffers (`list-buffers').
  723.    To print a list of all the buffers that exist, type `C-x C-b'. Each
  724. line in the list shows one buffer's name, major mode and visited file.
  725. `*' at the beginning of a line indicates the buffer is "modified". If
  726. several buffers are modified, it may be time to save some with `C-x s'
  727. (*note Saving::.).  `%' indicates a read-only buffer.  `.' marks the
  728. selected buffer.  Here is an example of a buffer list:
  729.       MR Buffer         Size  Mode           File
  730.       -- ------         ----  ----           ----
  731.      .*  emacs.tex      383402 Texinfo       /u2/emacs/man/emacs.tex
  732.          *Help*         1287  Fundamental
  733.          files.el       23076 Emacs-Lisp     /u2/emacs/lisp/files.el
  734.        % RMAIL          64042 RMAIL          /u/rms/RMAIL
  735.       *% man            747   Dired
  736.          net.emacs      343885 Fundamental   /u/rms/net.emacs
  737.          fileio.c       27691 C              /u2/emacs/src/fileio.c
  738.          NEWS           67340 Text           /u2/emacs/etc/NEWS
  739.          *scratch*       0     Lisp Interaction
  740. Note that the buffer `*Help*' was made by a help request; it is not
  741. visiting any file.  The buffer `man' was made by Dired on the directory
  742. `/u2/emacs/man/'.
  743. File: emacs,  Node: Misc Buffer,  Next: Kill Buffer,  Prev: List Buffers,  Up: Buffers
  744. Miscellaneous Buffer Operations
  745. ===============================
  746. `C-x C-q'
  747.      Toggle read-only status of buffer (`toggle-read-only').
  748. `M-x rename-buffer'
  749.      Change the name of the current buffer.
  750. `M-x view-buffer'
  751.      Scroll through a buffer.
  752.    A buffer can be "read-only", which means that commands to change its
  753. text are not allowed.  Normally, read-only buffers are made by
  754. subsystems such as Dired and Rmail that have special commands to
  755. operate on the text; a read-only buffer is also made if you visit a
  756. file that is protected so you cannot write it.  If you wish to make
  757. changes in a read-only buffer, use the command `C-x C-q'
  758. (`toggle-read-only').  It makes a read-only buffer writable, and makes
  759. a writable buffer read-only.  This works by setting the variable
  760. `buffer-read-only', which has a local value in each buffer and makes
  761. the buffer read-only if its value is non-`nil'.
  762.    `M-x rename-buffer' changes the name of the current buffer.  Specify
  763. the new name as a minibuffer argument.  There is no default.  If you
  764. specify a name that is in use for some other buffer, an error happens
  765. and no renaming is done.
  766.    `M-x view-buffer' is much like `M-x view-file' (*note Misc File
  767. Ops::.) except that it examines an already existing Emacs buffer.  View
  768. mode provides commands for scrolling through the buffer conveniently
  769. but not for changing it. When you exit View mode, the value of point
  770. that resulted from your perusal remains in effect.
  771.    The commands `C-x a' (`append-to-buffer') and `M-x insert-buffer'
  772. can be used to copy text from one buffer to another. *Note Accumulating
  773. Text::.
  774. File: emacs,  Node: Kill Buffer,  Next: Several Buffers,  Prev: Misc Buffer,  Up: Buffers
  775. Killing Buffers
  776. ===============
  777.    After you use Emacs for a while, you may accumulate a large number of
  778. buffers.  You may then find it convenient to eliminate the ones you no
  779. longer need.  There are several commands provided for doing this.
  780. `C-x k'
  781.      Kill a buffer, specified by name (`kill-buffer').
  782. `M-x kill-some-buffers'
  783.      Offer to kill each buffer, one by one.
  784.    `C-x k' (`kill-buffer') kills one buffer, whose name you specify in
  785. the minibuffer.  The default, used if you type just RET in the
  786. minibuffer, is to kill the current buffer.  If the current buffer is
  787. killed, another buffer is selected; a buffer that has been selected
  788. recently but does not appear in any window now is chosen to be selected.
  789. If the buffer being killed is modified (has unsaved editing) then you
  790. are asked to confirm with `yes' before the buffer is killed.
  791.    The command `M-x kill-some-buffers' asks about each buffer, one by
  792. one.  An answer of `y' means to kill the buffer.  Killing the current
  793. buffer or a buffer containing unsaved changes selects a new buffer or
  794. asks for confirmation just like `kill-buffer'.
  795. File: emacs,  Node: Several Buffers,  Prev: Kill Buffer,  Up: Buffers
  796. Operating on Several Buffers
  797. ============================
  798.    The "buffer-menu" facility is like a "Dired for buffers"; it allows
  799. you to request operations on various Emacs buffers by editing an Emacs
  800. buffer containing a list of them.  You can save buffers, kill them
  801. (here called "deleting" them, for consistency with Dired), or display
  802. them.
  803. `M-x buffer-menu'
  804.      Begin editing a buffer listing all Emacs buffers.
  805.    The command `buffer-menu' writes a list of all Emacs buffers into
  806. the buffer `*Buffer List*', and selects that buffer in Buffer Menu
  807. mode.  The buffer is read-only, and can only be changed through the
  808. special commands described in this section.  Most of these commands are
  809. graphic characters.  The usual Emacs cursor motion commands can be used
  810. in the `*Buffer List*' buffer.  The following special commands apply to
  811. the buffer described on the current line.
  812.      Request to delete (kill) the buffer, then move down.  The request
  813.      shows as a `D' on the line, before the buffer name.  Requested
  814.      deletions take place when the `x' command is used.
  815.      Synonym for `d'.
  816. `C-d'
  817.      Like `d' but move up afterwards instead of down.
  818.      Request to save the buffer.  The request shows as an `S' on the
  819.      line.  Requested saves take place when the `x' command is used.
  820.      You may request both saving and deletion for the same buffer.
  821.      Mark buffer "unmodified".  The command `~' does this immediately
  822.      when typed.
  823.      Perform previously requested deletions and saves.
  824.      Remove any request made for the current line, and move down.
  825. `DEL'
  826.      Move to previous line and remove any request made for that line.
  827.    All the commands that put in or remove flags to request later
  828. operations also move down a line, and accept a numeric argument as a
  829. repeat count, unless otherwise specified.
  830.    There are also special commands to use the buffer list to select
  831. another buffer, and to specify one or more other buffers for display in
  832. additional windows.
  833.      Select the buffer in a full-screen window.  This command takes
  834.      effect immediately.
  835.      Immediately set up two windows, with this buffer in one, and the
  836.      previously selected buffer (aside from the buffer `*Buffer List*')
  837.      in the other.
  838.      Immediately select the buffer in place of the `*Buffer List*'
  839.      buffer.
  840.      Immediately select the buffer in another window as if by `C-x 4 b',
  841.      leaving `*Buffer List*' visible.
  842.      Immediately select this buffer, and also display in other windows
  843.      any buffers previously flagged with the `m' command.  If there are
  844.      no such buffers, this command is equivalent to `1'.
  845.      Flag this buffer to be displayed in another window if the `q'
  846.      command is used.  The request shows as a `>' at the beginning of
  847.      the line.  The same buffer may not have both a delete request and a
  848.      display request.
  849.    All that `buffer-menu' does directly is create and select a suitable
  850. buffer, and turn on Buffer Menu mode.  Everything else described above
  851. is implemented by the special commands provided in Buffer Menu mode. 
  852. One consequence of this is that you can switch from the `*Buffer List*'
  853. buffer to another Emacs buffer, and edit there.  You can reselect the
  854. `buffer-menu' buffer later, to perform the operations already
  855. requested, or you can kill it, or pay no further attention to it.
  856.    The only difference between `buffer-menu' and `list-buffers' is that
  857. `buffer-menu' selects the `*Buffer List*' buffer and `list-buffers'
  858. does not.  If you run `list-buffers' (that is, type `C-x C-b') and
  859. select the buffer list manually, you can use all of the commands
  860. described here.
  861.