home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-User.iso / usr / lib / emacs / info / emacs-5 (.txt) < prev    next >
GNU Info File  |  1992-10-30  |  51KB  |  855 lines

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