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

  1. This is Info file ../info/emacs, produced by Makeinfo-1.54 from the
  2. input file emacs.texi.
  3. File: emacs,  Node: Single Shell,  Next: Interactive Shell,  Up: Shell
  4. Single Shell Commands
  5. ---------------------
  6.    `M-!' (`shell-command') reads a line of text using the minibuffer
  7. executes it as a shell command in a subshell made just for this
  8. command.  Standard input for the command comes from the null device.
  9. If the shell command produces any output, the output goes into an Emacs
  10. buffer named `*Shell Command Output*', which is displayed in another
  11. window but not selected.  A numeric argument, as in `M-1 M-!', directs
  12. this command to insert any output into the current buffer.  In that
  13. case, point is left before the output and the mark is set after the
  14. output.
  15.    If the shell command line ends in `&', it runs asynchronously.
  16.    `M-|' (`shell-command-on-region') is like `M-!' but passes the
  17. contents of the region as input to the shell command, instead of no
  18. input.  If a numeric argument is used, meaning insert output in the
  19. current buffer, then the old region is deleted first and the output
  20. replaces it as the contents of the region.
  21.    Both `M-!' and `M-|' use `shell-file-name' to specify the shell to
  22. use.  This variable is initialized based on your `SHELL' environment
  23. variable when Emacs is started.  If the file name does not specify a
  24. directory, the directories in the list `exec-path' are searched; this
  25. list is initialized based on the environment variable `PATH' when Emacs
  26. is started.  Your `.emacs' file can override either or both of these
  27. default initializations.
  28.    With `M-!' and `M-|', Emacs has to wait until the shell command
  29. completes.  To stop waiting, type `C-g' to quit; that also kills the
  30. shell command.
  31. File: emacs,  Node: Interactive Shell,  Next: Shell Mode,  Prev: Single Shell,  Up: Shell
  32. Interactive Inferior Shell
  33. --------------------------
  34.    To run a subshell interactively, putting its typescript in an Emacs
  35. buffer, use `M-x shell'.  This creates (or reuses) a buffer named
  36. `*shell*' and runs a subshell with input coming from and output going
  37. to that buffer.  That is to say, any "terminal output" from the subshell
  38. goes into the buffer, advancing point, and any "terminal input" for the
  39. subshell comes from text in the buffer.  To give input to the subshell,
  40. go to the end of the buffer and type the input, terminated by RET.
  41.    Emacs does not wait for the subshell to do anything.  You can switch
  42. windows or buffers and edit them while the shell is waiting, or while
  43. it is running a command.  Output from the subshell waits until Emacs
  44. has time to process it; this happens whenever Emacs is waiting for
  45. keyboard input or for time to elapse.
  46.    To make multiple subshells, rename the buffer `*shell*' to something
  47. different using `M-x rename-uniquely'.  Then type `M-x shell' again to
  48. create a new buffer `*shell*' with its own subshell.  If you rename
  49. this buffer as well, you can create a third one, and so on.  All the
  50. subshells run independently and in parallel.
  51.    The file name used to load the subshell is the value of the variable
  52. `explicit-shell-file-name', if that is non-`nil'.  Otherwise, the
  53. environment variable `ESHELL' is used, or the environment variable
  54. `SHELL' if there is no `ESHELL'.  If the file name specified is
  55. relative, the directories in the list `exec-path' are searched (*note
  56. Single Shell Commands: Single Shell.).
  57.    As soon as the subshell is started, it is sent as input the contents
  58. of the file `~/.emacs_SHELLNAME', if that file exists, where SHELLNAME
  59. is the name of the file that the shell was loaded from.  For example,
  60. if you use `bash', the file sent to it is `~/.emacs_bash'.
  61.    `cd', `pushd' and `popd' commands given to the inferior shell are
  62. watched by Emacs so it can keep the `*shell*' buffer's default
  63. directory the same as the shell's working directory.  These commands
  64. are recognized syntactically by examining lines of input that are sent.
  65. If you use aliases for these commands, you can tell Emacs to recognize
  66. them also.  For example, if the value of the variable
  67. `shell-pushd-regexp' matches the beginning of a shell command line,
  68. that line is regarded as a `pushd' command.  Change this variable when
  69. you add aliases for `pushd'.  Likewise, `shell-popd-regexp' and
  70. `shell-cd-regexp' are used to recognize commands with the meaning of
  71. `popd' and `cd'.  These commands are recognized only at the beginning
  72. of a shell command line.
  73.    If Emacs gets an error while trying to handle what it believes is a
  74. `cd', `pushd' or `popd' command, it runs the hook
  75. `shell-set-directory-error-hook' (*note Hooks::.).
  76.    If Emacs does not properly track changes in the current directory of
  77. the subshell, use the command `M-x dirs' to ask the shell what its
  78. current directory is.  This command works for shells that support the
  79. most common command syntax; it may not work for unusual shells.
  80. File: emacs,  Node: Shell Mode,  Next: Shell History,  Prev: Interactive Shell,  Up: Shell
  81. Shell Mode
  82. ----------
  83.    The shell buffer uses Shell mode, which defines several special keys
  84. attached to the `C-c' prefix.  They are chosen to resemble the usual
  85. editing and job control characters present in shells that are not under
  86. Emacs, except that you must type `C-c' first.  Here is a complete list
  87. of the special key bindings of Shell mode:
  88. `RET'
  89.      At end of buffer send line as input; otherwise, copy current line
  90.      to end of buffer and send it (`comint-send-input').  When a line is
  91.      copied, any text at the beginning of the line that matches the
  92.      variable `shell-prompt-pattern' is left out; this variable's value
  93.      should be a regexp string that matches the prompts that your shell
  94.      uses.
  95. `TAB'
  96.      Complete the file name before point in the shell buffer
  97.      (`comint-dynamic-complete').
  98. `M-?'
  99.      Display temporarily a list of the possible completions of the file
  100.      name before point in the shell buffer
  101.      (`comint-dynamic-list-completions').
  102. `C-a'
  103.      Move to the beginning of the line, but after the prompt if any
  104.      (`comint-bol').
  105. `C-d'
  106.      Either delete a character or send EOF
  107.      (`comint-delchar-or-maybe-eof').  Typed at the end of the shell
  108.      buffer, `C-d' sends EOF to the subshell.  Typed at any other
  109.      position in the buffer, `C-d' deletes a character as usual.
  110. `C-c C-u'
  111.      Kill all text pending at end of buffer to be sent as input
  112.      (`comint-kill-input').
  113. `C-c C-w'
  114.      Kill a word before point (`backward-kill-word').
  115. `C-c C-c'
  116.      Interrupt the shell or its current subjob if any
  117.      (`comint-interrupt-subjob').
  118. `C-c C-z'
  119.      Stop the shell or its current subjob if any (`comint-stop-subjob').
  120. `C-c C-\'
  121.      Send quit signal to the shell or its current subjob if any
  122.      (`comint-quit-subjob').
  123. `C-c C-o'
  124.      Kill the last batch of output from a shell command
  125.      (`comint-kill-output').  This is useful if a shell command spews
  126.      out lots of output that just gets in the way.
  127. `C-c C-r'
  128.      Scroll to display the beginning of the last batch of output at the
  129.      top of the window; also move the cursor there
  130.      (`comint-show-output').
  131. `M-x dirs'
  132.      Ask the shell what its current directory is, so that Emacs can
  133.      agree with the shell.
  134. `M-x send-invisible RET TEXT RET'
  135.      Send TEXT as input to the shell, after reading it without echoing.
  136.      This is useful when a shell command runs a program that asks for
  137.      a password.
  138. `M-x comint-continue-subjob'
  139.      Continue the shell process.  This is useful if you accidentally
  140.      suspend the shell process.(1)
  141.    ---------- Footnotes ----------
  142.    (1)  You should not suspend the shell process.  Suspending a subjob
  143. of the shell is a completely different matter-that is normal practice,
  144. but you must use the shell to continue the subjob; this command won't
  145. do it.
  146. File: emacs,  Node: Shell History,  Prev: Shell Mode,  Up: Shell
  147. Shell Command History
  148. ---------------------
  149.    Shell buffers support history commands much like the minibuffer
  150. history commands.
  151. `M-p'
  152.      Fetch the next earlier old shell command.
  153. `M-n'
  154.      Fetch the next later old shell command.
  155. `M-r REGEXP RET'
  156. `M-s REGEXP RET'
  157.      Search backwards or forwards for old shell commands that match
  158.      REGEXP.
  159.    Shell buffers provide a history of previously entered shell
  160. commands.  To reuse shell commands from the history, use the editing
  161. commands `M-p', `M-n', `M-r' and `M-s'.  These work just like the
  162. minibuffer history commands except that they operate on the text at the
  163. end of the shell buffer, the text that typing RET will send to the
  164. shell.
  165.    `M-p' fetches an earlier shell command to the end of the shell
  166. buffer.  Successive use of `M-p' fetches successively earlier shell
  167. commands, each replacing any text that was already present as potential
  168. shell input.  `M-n' does likewise except that it finds successively
  169. more recent shell commands from the buffer.
  170.    The history search commands `M-r' and `M-s' read a regular
  171. expression and search through the history for a matching command.  Aside
  172. from the choice of which command to fetch, they work just like `M-p'
  173. and `M-r'.  If you enter an empty regexp, these commands reuse the same
  174. regexp used last time.
  175.    When you find the previous input you want, you can resubmit it by
  176. typing RET, or you can edit it first and then resubmit it if you wish.
  177.    These commands get the text of previous shell commands from a special
  178. history list, not from the shell buffer itself.  Thus, editing the shell
  179. buffer, or even killing large parts of it, does not affect the history
  180. that these commands access.
  181. File: emacs,  Node: Narrowing,  Next: Hardcopy,  Prev: Shell,  Up: Top
  182. Narrowing
  183. =========
  184.    "Narrowing" means focusing in on some portion of the buffer, making
  185. the rest temporarily inaccessible.  The portion which you can still get
  186. to is called the "accessible portion".  Cancelling the narrowing, and
  187. making the entire buffer once again accessible, is called "widening".
  188. The amount of narrowing in effect in a buffer at any time is called the
  189. buffer's "restriction".
  190. `C-x n n'
  191.      Narrow down to between point and mark (`narrow-to-region').
  192. `C-x n w'
  193.      Widen to make the entire buffer accessible again (`widen').
  194. `C-x n p'
  195.      Narrow down to the current page (`narrow-to-page').
  196.    When you have narrowed down to a part of the buffer, that part
  197. appears to be all there is.  You can't see the rest, you can't move
  198. into it (motion commands won't go outside the accessible part), you
  199. can't change it in any way.  However, it is not gone, and if you save
  200. the file all the inaccessible text will be saved.  In addition to
  201. sometimes making it easier to concentrate on a single subroutine or
  202. paragraph by eliminating clutter, narrowing can be used to restrict the
  203. range of operation of a replace command or repeating keyboard macro.
  204. The word `Narrow' appears in the mode line whenever narrowing is in
  205. effect.
  206.    The primary narrowing command is `C-x n n' (`narrow-to-region').  It
  207. sets the current buffer's restrictions so that the text in the current
  208. region remains accessible but all text before the region or after the
  209. region is invisible.  Point and mark do not change.
  210.    Alternatively, use `C-x n p' (`narrow-to-page') to narrow down to
  211. the current page.  *Note Pages::, for the definition of a page.
  212.    The way to undo narrowing is to widen with `C-x n w' (`widen').
  213. This makes all text in the buffer accessible again.
  214.    You can get information on what part of the buffer you are narrowed
  215. down to using the `C-x =' command.  *Note Position Info::.
  216.    Because narrowing can easily confuse users who do not understand it,
  217. `narrow-to-region' is normally a disabled command.  Attempting to use
  218. this command asks for confirmation and gives you the option of enabling
  219. it; once you enable the command, confirmation will no longer be
  220. required for it.  *Note Disabling::.
  221. File: emacs,  Node: Hardcopy,  Next: Two-Column,  Prev: Narrowing,  Up: Top
  222. Hardcopy Output
  223. ===============
  224.    The Emacs commands for making hardcopy let you print either an entire
  225. buffer or just part of one, either with or without page headers.  See
  226. also the hardcopy commands of Dired (*note Misc File Ops::.) and the
  227. diary (*note Diary Commands::.).
  228. `M-x print-buffer'
  229.      Print hardcopy of current buffer using Unix command `print' (`lpr
  230.      -p').  This makes page headings containing the file name and page
  231.      number.
  232. `M-x lpr-buffer'
  233.      Print hardcopy of current buffer using Unix command `lpr'.  This
  234.      makes no page headings.
  235. `M-x print-region'
  236.      Like `print-buffer' but prints only the current region.
  237. `M-x lpr-region'
  238.      Like `lpr-buffer' but prints only the current region.
  239.    All the hardcopy commands pass extra switches to the `lpr' program
  240. based on the value of the variable `lpr-switches'.  Its value should be
  241. a list of strings, each string an option starting with `-'.  For
  242. example, to use a printer named `nearme', set `lpr-switches' like this:
  243.      (setq lpr-switches '("-Pnearme"))
  244. File: emacs,  Node: Two-Column,  Next: Editing Binary Files,  Prev: Hardcopy,  Up: Top
  245. Two-Column Editing
  246. ==================
  247.    Two-column mode lets you conveniently edit two side-by-side columns
  248. of text.  It uses two side-by-side windows, each showing its own buffer.
  249.    There are three ways to enter two-column mode:
  250. `C-x 6 2'
  251.      Enter two-column mode with the current buffer on the left, and on
  252.      the right, a buffer whose name is based on the current buffer's
  253.      name (`tc-two-columns').  If the right-hand buffer doesn't already
  254.      exist, it starts out empty; the current buffer's contents are not
  255.      changed.
  256.      This command is appropriate when the current buffer contains just
  257.      one column and you want to add another column.
  258. `C-x 6 s'
  259.      Split the current buffer, which contains two-column text, into two
  260.      buffers, and display them side by side (`tc-split').  The current
  261.      buffer becomes the left-hand buffer, but the text in the right-hand
  262.      column is moved into the right-hand buffer.  The current column
  263.      specifies the split point.  Splitting starts with the current line
  264.      and continues to the end of the buffer.
  265.      This command is appropriate when you have a buffer that already
  266.      contains two-column text, and you wish to separate the columns
  267.      temporarily.
  268. `C-x 6 b BUFFER RET'
  269.      Enter two-column mode using the current buffer as the left-hand
  270.      buffer, and using buffer BUFFER as the right-hand buffer
  271.      (`tc-associate-buffer').
  272.    `C-x 6 s' looks for a column separator which is a string that
  273. appears on each line between the two columns.  You can specify the width
  274. of the separator with a numeric argument to `C-x 6 s'; that many
  275. characters, before point, constitute the separator string.  By default,
  276. the width is 1, so the column separator is the character before point.
  277.    When a line has the separator at the proper place, `C-x 6 s' puts
  278. the text after the separator into the right-hand buffer, and deletes the
  279. separator.  Lines that don't have the column separator at the proper
  280. place remain unsplit; they stay in the left-hand buffer, and the
  281. right-hand buffer gets an empty line to correspond.  (This is the way
  282. to write a line which "spans both columns while in two-column mode:
  283. write it in the left-hand buffer, and put an empty line in the
  284. right-hand buffer.)
  285.    It's not a good idea to use ordinary scrolling commands during
  286. two-column editing, because that separates the two parts of each split
  287. line.  Instead, use these special scroll commands:
  288. `C-x 6 SPC'
  289.      Scroll both buffers up, in lockstep (`tc-scroll-up').
  290. `C-x 6 DEL'
  291.      Scroll both buffers down, in lockstep (`tc-scroll-down').
  292. `C-x 6 C-l'
  293.      Recenter both buffers, in lockstep (`tc-recenter').
  294.    When you have edited both buffers as you wish, merge them with `C-x
  295. 6 1' (`tc-merge').  This copies the text from the right-hand buffer as
  296. a second column in the other buffer.  To go back to two-column editing,
  297. use `C-x 6 s'.
  298.    Use `C-x 6 d' to disassociate the two buffers, leaving each as it
  299. stands (`tc-dissociate').  If the other buffer, the one not current
  300. when you type `C-x 6 d', is empty, `C-x 6 d' kills it.
  301. File: emacs,  Node: Editing Binary Files,  Next: Emacs Server,  Prev: Two-Column,  Up: Top
  302. Editing Binary Files
  303. ====================
  304.    There is a special major mode for editing binary files: Hexl mode.
  305. To use it, use `M-x hexl-find-file' instead of `C-x C-f' to visit the
  306. file.  This command converts the file's contents to hexadecimal and
  307. lets you edit the translation.  When you save the file, it is converted
  308. automatically back to binary.
  309.    You can also use `M-x hexl-mode' to translate an existing buffer
  310. into hex.  This is useful if you visit a file normally and then discover
  311. it is a binary file.
  312.    Ordinary text characters overwrite in Hexl mode.  This is to reduce
  313. the risk of accidentally spoiling the alignment of data in the file.
  314. There are special commands for insertion.  Here is a list of the
  315. commands of Hexl mode:
  316. `C-M-d'
  317.      Insert a byte with a code typed in decimal.
  318. `C-M-o'
  319.      Insert a byte with a code typed in octal.
  320. `C-M-x'
  321.      Insert a byte with a code typed in hex.
  322. `C-x ['
  323.      Move to the beginning of a 1k-byte "page".
  324. `C-x ]'
  325.      Move to the end of a 1k-byte "page".
  326. `M-g'
  327.      Move to an address specified in hex.
  328. `M-j'
  329.      Move to an address specified in decimal.
  330. `C-c C-c'
  331.      Leave Hexl mode, going back to the major mode this buffer had
  332.      before you invoked `hexl-mode'.
  333. File: emacs,  Node: Emacs Server,  Next: Recursive Edit,  Prev: Editing Binary Files,  Up: Top
  334. Using Emacs as a Server
  335. =======================
  336.    Various programs such as `mail' can invoke your choice of editor to
  337. edit a particular piece of text, such as a message that you are
  338. sending.  By convention, these programs use the environment variable
  339. `EDITOR' to specify which editor to run.  If you set `EDITOR' to
  340. `emacs', they invoke Emacs--but in an inconvenient fashion, by starting
  341. a new, separate Emacs process.  This is inconvenient because it takes
  342. time and because the new Emacs process doesn't share the buffers in the
  343. existing Emacs process.
  344.    You can arrange to use your existing Emacs process as the editor for
  345. programs like `mail' by using the Emacs client and Emacs server
  346. programs.  Here is how.
  347.    First, the preparation.  Within Emacs, call the function
  348. `server-start'.  (Your `.emacs' file can do this automatically if you
  349. add the expression `(server-start)' to it.)  Then, outside Emacs, set
  350. the `EDITOR' environment variable to `emacsclient'.
  351.    Then, whenever any program invokes your specified `EDITOR' program,
  352. the effect is to send a message to your principal Emacs telling it to
  353. visit a file.  (That's what the program `emacsclient' does.) Emacs
  354. obeys silently; it does not immediately switch to the new file's
  355. buffer.  When you want to do that, type `C-x #' (`server-edit').
  356.    When you've finished editing that buffer, type `C-x #' again.  This
  357. saves the file and sends a message back to the `emacsclient' program
  358. telling it to exit.  The programs that use `EDITOR' wait for the
  359. "editor" (actually, `emacsclient') to exit.  `C-x #' also checks to see
  360. if any other files are pending for you to edit, and selects the next
  361.    You can switch to a server buffer manually if you wish; you don't
  362. have to arrive at it with `C-x #'.  But `C-x #' is the only way to say
  363. that you are "finished" with one.
  364.    While `mail' or another application is waiting for `emacsclient' to
  365. finish, `emacsclient' does not read terminal input.  So the terminal
  366. that `mail' was using is effectively blocked for the duration.  In
  367. order to edit with your principal Emacs, you need to be able to use it
  368. without using that terminal.  There are two ways to do this:
  369.    * Using a window system, run `mail' and the principal Emacs in two
  370.      separate windows.  While `mail' is waiting for `emacsclient', the
  371.      window where it was running is blocked, but you can use Emacs by
  372.      switching windows.
  373.    * Use Shell mode in Emacs to run the other program such as `mail';
  374.      then, `emacsclient' blocks only the subshell under Emacs; you can
  375.      still use Emacs to edit the file.
  376. File: emacs,  Node: Recursive Edit,  Next: Dissociated Press,  Prev: Emacs Server,  Up: Top
  377. Recursive Editing Levels
  378. ========================
  379.    A "recursive edit" is a situation in which you are using Emacs
  380. commands to perform arbitrary editing while in the middle of another
  381. Emacs command.  For example, when you type `C-r' inside of a
  382. `query-replace', you enter a recursive edit in which you can change the
  383. current buffer.  On exiting from the recursive edit, you go back to the
  384. `query-replace'.
  385.    "Exiting" the recursive edit means returning to the unfinished
  386. command, which continues execution.  To exit, type `C-M-c'
  387. (`exit-recursive-edit').
  388.    You can also "abort" the recursive edit.  This is like exiting, but
  389. also quits the unfinished command immediately.  Use the command `C-]'
  390. (`abort-recursive-edit') for this.  *Note Quitting::.
  391.    The mode line shows you when you are in a recursive edit by
  392. displaying square brackets around the parentheses that always surround
  393. the major and minor mode names.  Every window's mode line shows this,
  394. in the same way, since being in a recursive edit is true of Emacs as a
  395. whole rather than any particular window or buffer.
  396.    It is possible to be in recursive edits within recursive edits.  For
  397. example, after typing `C-r' in a `query-replace', you may type a
  398. command that enters the debugger.  This begins a recursive editing level
  399. for the debugger, within the recursive editing level for `C-r'.  Mode
  400. lines display a pair of square brackets for each recursive editing
  401. level currently in progress.
  402.    Exiting the inner recursive edit (such as, with the debugger `c'
  403. command) resumes the command running in the next level up.  When that
  404. command finishes, you can then use `C-M-c' to exit another recursive
  405. editing level, and so on.  Exiting applies to the innermost level only.
  406. Aborting also gets out of only one level of recursive edit; it returns
  407. immediately to the command level of the previous recursive edit.  If you
  408. wish, you can then abort the next recursive editing level.
  409.    Alternatively, the command `M-x top-level' aborts all levels of
  410. recursive edits, returning immediately to the top level command reader.
  411.    The text being edited inside the recursive edit need not be the same
  412. text that you were editing at top level.  It depends on what the
  413. recursive edit is for.  If the command that invokes the recursive edit
  414. selects a different buffer first, that is the buffer you will edit
  415. recursively.  In any case, you can switch buffers within the recursive
  416. edit in the normal manner (as long as the buffer-switching keys have
  417. not been rebound).  You could probably do all the rest of your editing
  418. inside the recursive edit, visiting files and all.  But this could have
  419. surprising effects (such as stack overflow) from time to time.  So
  420. remember to exit or abort the recursive edit when you no longer need it.
  421.    In general, we try to minimize the use of recursive editing levels in
  422. GNU Emacs.  This is because they constrain you to "go back" in a
  423. particular order-from the innermost level toward the top level.  When
  424. possible, we present different activities in separate buffers.  Some
  425. commands switch to a new major mode but provide a way to switch back.
  426. These approaches give you more flexibility to go back to unfinished
  427. tasks in the order you choose.
  428. File: emacs,  Node: Dissociated Press,  Next: Amusements,  Prev: Recursive Edit,  Up: Top
  429. Dissociated Press
  430. =================
  431.    `M-x dissociated-press' is a command for scrambling a file of text
  432. either word by word or character by character.  Starting from a buffer
  433. of straight English, it produces extremely amusing output.  The input
  434. comes from the current Emacs buffer.  Dissociated Press writes its
  435. output in a buffer named `*Dissociation*', and redisplays that buffer
  436. after every couple of lines (approximately) to facilitate reading it.
  437.    Dissociated Press asks every so often whether to continue operating.
  438. Answer `n' to stop it.  You can also stop at any time by typing `C-g'.
  439. The dissociation output remains in the `*Dissociation*' buffer for you
  440. to copy elsewhere if you wish.
  441.    Dissociated Press operates by jumping at random from one point in the
  442. buffer to another.  In order to produce plausible output rather than
  443. gibberish, it insists on a certain amount of overlap between the end of
  444. one run of consecutive words or characters and the start of the next.
  445. That is, if it has just printed out `president' and then decides to jump
  446. to a different point in the file, it might spot the `ent' in `pentagon'
  447. and continue from there, producing `presidentagon'.(1)  Long sample
  448. texts produce the best results.
  449.    A positive argument to `M-x dissociated-press' tells it to operate
  450. character by character, and specifies the number of overlap characters.
  451. A negative argument tells it to operate word by word and specifies the
  452. number of overlap words.  In this mode, whole words are treated as the
  453. elements to be permuted, rather than characters.  No argument is
  454. equivalent to an argument of two.  For your againformation, the output
  455. goes only into the buffer `*Dissociation*'.  The buffer you start with
  456. is not changed.
  457.    Dissociated Press produces nearly the same results as a Markov chain
  458. based on a frequency table constructed from the sample text.  It is,
  459. however, an independent, ignoriginal invention.  Dissociated Press
  460. techniquitously copies several consecutive characters from the sample
  461. between random choices, whereas a Markov chain would choose randomly for
  462. each word or character.  This makes for more plausible sounding results,
  463. and runs faster.
  464.    It is a mustatement that too much use of Dissociated Press can be a
  465. developediment to your real work.  Sometimes to the point of outragedy.
  466. And keep dissociwords out of your documentation, if you want it to be
  467. well userenced and properbose.  Have fun.  Your buggestions are welcome.
  468.    ---------- Footnotes ----------
  469.    (1)  This dissociword actually appeared during the Vietnam War, when
  470. it was very appropriate.
  471. File: emacs,  Node: Amusements,  Next: Emulation,  Prev: Dissociated Press,  Up: Top
  472. Other Amusements
  473. ================
  474.    If you are a little bit bored, you can try `M-x hanoi'.  If you are
  475. considerably bored, give it a numeric argument.  If you are very very
  476. bored, try an argument of 9.  Sit back and watch.
  477.    If you want a little more personal involvement, try `M-x gomoku',
  478. which plays the game Go Moku with you.
  479.    `M-x blackbox' and `M-x mpuz' are two kinds of puzzles.  `blackbox'
  480. challenges you to determine the location of objects inside a box by
  481. tomography.  `mpuz' displays a multiplication puzzle with letters
  482. standing for digits in a code that you must guess--to guess a value,
  483. type a letter and then the digit you think it stands for.
  484.    When you are frustrated, try the famous Eliza program.  Just do `M-x
  485. doctor'.  End each input by typing `RET' twice.
  486.    When you are feeling strange, type `M-x yow'.
  487. File: emacs,  Node: Emulation,  Next: Customization,  Prev: Amusements,  Up: Top
  488. Emulation
  489. =========
  490.    GNU Emacs can be programmed to emulate (more or less) most other
  491. editors.  Standard facilities can emulate these:
  492. EDT (DEC VMS editor)
  493.      Turn on EDT emulation with `M-x edt-emulation-on'.  `M-x
  494.      edt-emulation-off' restores normal Emacs command bindings.
  495.      Most of the EDT emulation commands are keypad keys, and most
  496.      standard Emacs key bindings are still available.  The EDT
  497.      emulation rebindings are done in the global keymap, so there is no
  498.      problem switching buffers or major modes while in EDT emulation.
  499. Gosling Emacs
  500.      To turn on emulation of Gosling Emacs (alias Unipress Emacs), type
  501.      the command `M-x set-gosmacs-bindings'.  This redefines many keys,
  502.      mostly on the `C-x' and `ESC' prefixes, to work as they do in
  503.      Gosmacs.  `M-x set-gnu-bindings' returns to normal GNU Emacs by
  504.      rebinding the same keys to the definitions they had before you used
  505.      `M-x set-gosmacs-bindings'.
  506. vi (Berkeley Unix editor)
  507.      Turn on vi emulation with `M-x vi-mode'.  This is a major mode
  508.      that replaces the previously established major mode.  All of the
  509.      vi commands that, in real vi, enter "input" mode are programmed in
  510.      the Emacs emulator to return to the previous major mode.  Thus,
  511.      ordinary Emacs serves as vi's "input" mode.
  512.      Because vi emulation works through major modes, it does not work
  513.      to switch buffers during emulation.  Return to normal Emacs first.
  514.      If you plan to use vi emulation much, you probably want to bind a
  515.      key to the `vi-mode' command.
  516. vi (alternate emulator)
  517.      Another vi emulator said to resemble real vi more thoroughly is
  518.      invoked by `M-x vip-mode'.  "Input" mode in this emulator is
  519.      changed from ordinary Emacs so you can use ESC to go back to
  520.      emulated vi command mode.  To get from emulated vi command mode
  521.      back to ordinary Emacs, type `C-z'.
  522.      This emulation does not work through major modes, and it is
  523.      possible to switch buffers in various ways within the emulator.
  524.      It is not so necessary to assign a key to the command `vip-mode' as
  525.      it is with `vi-mode' because terminating insert mode does not use
  526.      it.
  527.      For full information, see the long comment at the beginning of the
  528.      source file, which is `lisp/vip.el' in the Emacs distribution.
  529.    I am interested in hearing which vi emulator users prefer, as well
  530. as in receiving more complete user documentation for either or both
  531. emulators.  Warning: loading both at once may cause name conflicts; no
  532. one has checked.
  533. File: emacs,  Node: Customization,  Next: Quitting,  Prev: Emulation,  Up: Top
  534. Customization
  535. *************
  536.    This chapter talks about various topics relevant to adapting the
  537. behavior of Emacs in minor ways.  See `The Emacs Lisp Reference Manual'
  538. for how to make more far-reaching changes.
  539.    All kinds of customization affect only the particular Emacs job that
  540. you do them in.  They are completely lost when you kill the Emacs job,
  541. and have no effect on other Emacs jobs you may run at the same time or
  542. later.  The only way an Emacs job can affect anything outside of it is
  543. by writing a file; in particular, the only way to make a customization
  544. `permanent' is to put something in your `.emacs' file or other
  545. appropriate file to do the customization in each session.  *Note Init
  546. File::.
  547. * Menu:
  548. * Minor Modes::              Each minor mode is one feature you can turn on
  549.                                independently of any others.
  550. * Variables::                Many Emacs commands examine Emacs variables
  551.                                to decide what to do; by setting variables,
  552.                                you can control their functioning.
  553. * Keyboard Macros::          A keyboard macro records a sequence of
  554.                                keystrokes to be replayed with a single
  555.                                command.
  556. * Key Bindings::             The keymaps say what command each key runs.
  557.                                By changing them, you can "redefine keys".
  558. * Keyboard Translations::    If your keyboard passes an undesired code
  559.                                for a key, you can tell Emacs to
  560.                                substitute another code.
  561. * Syntax::                   The syntax table controls how words and
  562.                                 expressions are parsed.
  563. * Init File::                How to write common customizations in the
  564.                                `.emacs' file.
  565. File: emacs,  Node: Minor Modes,  Next: Variables,  Up: Customization
  566. Minor Modes
  567. ===========
  568.    Minor modes are optional features which you can turn on or off.  For
  569. example, Auto Fill mode is a minor mode in which SPC breaks lines
  570. between words as you type.  All the minor modes are independent of each
  571. other and of the selected major mode.  Most minor modes say in the mode
  572. line when they are on; for example, `Fill' in the mode line means that
  573. Auto Fill mode is on.
  574.    Append `-mode' to the name of a minor mode to get the name of a
  575. command function that turns the mode on or off.  Thus, the command to
  576. enable or disable Auto Fill mode is called `M-x auto-fill-mode'.  These
  577. commands are usually invoked with `M-x', but you can bind keys to them
  578. if you wish.  With no argument, the function turns the mode on if it was
  579. off and off if it was on.  This is known as "toggling".  A positive
  580. argument always turns the mode on, and an explicit zero argument or a
  581. negative argument always turns it off.
  582.    Enabling or disabling some minor modes applies only to the current
  583. buffer; each buffer is independent of the other buffers.  Therefore, you
  584. can enable the mode in particular buffers and disable it in others.
  585.    Auto Fill mode allows you to enter filled text without breaking lines
  586. explicitly.  Emacs inserts newlines as necessary to prevent lines from
  587. becoming too long.  *Note Filling::.
  588.    Outline minor mode provides the same facilities as the major mode
  589. called Outline mode; but since it is a minor mode instead, you can
  590. combine it with any major mode.  *Note Outline Mode::.
  591.    Overwrite mode causes ordinary printing characters to replace
  592. existing text instead of shoving it over.  For example, if the point is
  593. in front of the `B' in `FOOBAR', then in Overwrite mode typing a `G'
  594. changes it to `FOOGAR', instead of making it `FOOGBAR' as usual.
  595.    Auto Save mode causes the contents of a buffer to be saved
  596. periodically to reduce the amount you will lose in case of a system
  597. crash.  *Note Auto Save::.
  598.    The following minor modes normally apply to all buffers at once.
  599. Since each is enabled or disabled by the value of a variable, you *can*
  600. set them differently for particular buffers, by explicitly making the
  601. corresponding variables local in those buffers.  *Note Locals::.
  602.    Abbrev mode allows you to define abbreviations that automatically
  603. expand as you type them.  For example, `amd' might expand to `abbrev
  604. mode'.  *Note Abbrevs::, for full information.
  605.    Line Number mode enables continuous display in the mode line of the
  606. line number of point.  *Note Mode Line::.
  607.    Scroll Bar mode gives each window a scroll bar (*note Scroll
  608. Bars::.).  Menu Bar mode gives each frame a menu bar (*note Menu
  609. Bars::.).  Both of these modes are enabled by default when you use the
  610. X Window System.
  611.    In Transient Mark mode, every change in the buffer "deactivates" the
  612. mark, so that commands that operate on the region will get an error.
  613. This means you must either set the mark, or explicitly "reactivate" it,
  614. before each command that uses the region.  The advantage of Transient
  615. Mark mode is that Emacs can display the region highlighted (currently
  616. only when using X).  *Note Setting Mark::.
  617. File: emacs,  Node: Variables,  Next: Keyboard Macros,  Prev: Minor Modes,  Up: Customization
  618. Variables
  619. =========
  620.    A "variable" is a Lisp symbol which has a value.  The symbol's name
  621. is also called the name of the variable.  A variable name can contain
  622. any characters that can appear in a file, but conventionally variable
  623. names consist of words separated by hyphens.  A variable can have a
  624. documentation string which describes what kind of value it should have
  625. and how the value will be used.
  626.    Lisp allows any variable to have any kind of value, but most
  627. variables that Emacs uses require a value of a certain type.  Often the
  628. value should always be a string, or should always be a number.
  629. Sometimes we say that a certain feature is turned on if a variable is
  630. "non-`nil'," meaning that if the variable's value is `nil', the feature
  631. is off, but the feature is on for *any* other value.  The conventional
  632. value to use to turn on the feature--since you have to pick one
  633. particular value when you set the variable--is `t'.
  634.    Emacs uses many Lisp variables for internal recordkeeping, as any
  635. Lisp program must, but the most interesting variables for you are the
  636. ones that exist for the sake of customization.  Emacs does not
  637. (usually) change the values of these variables; instead, you set the
  638. values, and thereby alter and control the behavior of certain Emacs
  639. commands.  These variables are called "options".  Most options are
  640. documented in this manual, and appear in the Variable Index (*note
  641. Variable Index::.).
  642.    One example of a variable which is an option is `fill-column', which
  643. specifies the position of the right margin (as a number of characters
  644. from the left margin) to be used by the fill commands (*note
  645. Filling::.).
  646. * Menu:
  647. * Examining::           Examining or setting one variable's value.
  648. * Edit Options::        Examining or editing list of all variables' values.
  649. * Hooks::        Hook variables let you specify programs for parts
  650.               of Emacs to run on particular occasions.
  651. * Locals::              Per-buffer values of variables.
  652. * File Variables::      How files can specify variable values.
  653. File: emacs,  Node: Examining,  Next: Edit Options,  Up: Variables
  654. Examining and Setting Variables
  655. -------------------------------
  656. `C-h v VAR RET'
  657.      Print the value and documentation of variable VAR
  658.      (`describe-variable').
  659. `M-x set-variable RET VAR RET VALUE RET'
  660.      Change the value of variable VAR to VALUE.
  661.    To examine the value of a single variable, use `C-h v'
  662. (`describe-variable'), which reads a variable name using the
  663. minibuffer, with completion.  It prints both the value and the
  664. documentation of the variable.  For example,
  665.      C-h v fill-column RET
  666. prints something like this:
  667.      fill-column's value is 75
  668.      
  669.      Documentation:
  670.      *Column beyond which automatic line-wrapping should happen.
  671.      Automatically becomes buffer-local when set in any fashion.
  672. The star at the beginning of the documentation indicates that this
  673. variable is an option.  `C-h v' is not restricted to options; it allows
  674. any variable name.
  675.    The most convenient way to set a specific option is with `M-x
  676. set-variable'.  This reads the variable name with the minibuffer (with
  677. completion), and then reads a Lisp expression for the new value using
  678. the minibuffer a second time.  For example,
  679.      M-x set-variable RET fill-column RET 75 RET
  680. sets `fill-column' to 75.
  681.    You can set any variable with a Lisp expression using the function
  682. `setq'.  Here's how to use it to set `fill-column':
  683.      (setq fill-column 75)
  684.    Setting variables, like all means of customizing Emacs except where
  685. explicitly stated, affects only the current Emacs session.
  686. File: emacs,  Node: Edit Options,  Next: Hooks,  Prev: Examining,  Up: Variables
  687. Editing Variable Values
  688. -----------------------
  689.    These two functions make it easy to display all the user edit options
  690. and change some of them.
  691. `M-x list-options'
  692.      Display a buffer listing names, values and documentation of all
  693.      options.
  694. `M-x edit-options'
  695.      Change option values by editing a list of options.
  696.    `M-x list-options' displays a list of all Emacs option variables, in
  697. an Emacs buffer named `*List Options*'.  Each option is shown with its
  698. documentation and its current value.  Here is what a portion of it might
  699. look like:
  700.      ;; exec-path:
  701.      ("." "/usr/local/bin" "/usr/ucb" "/bin" "/usr/bin" "/u2/emacs/etc")
  702.      *List of directories to search programs to run in subprocesses.
  703.      Each element is a string (directory name)
  704.      or nil (try the default directory).
  705.      ;;
  706.      ;; fill-column:
  707.      75
  708.      *Column beyond which automatic line-wrapping should happen.
  709.      Automatically becomes buffer-local when set in any fashion.
  710.      ;;
  711.    `M-x edit-options' goes one step further and immediately selects the
  712. `*List Options*' buffer; this buffer uses the major mode Options mode,
  713. which provides commands that allow you to point at an option and change
  714. its value:
  715.      Set the variable point is in or near to a new value read using the
  716.      minibuffer.
  717.      Toggle the variable point is in or near: if the value was `nil',
  718.      it becomes `t'; otherwise it becomes `nil'.
  719.      Set the variable point is in or near to `t'.
  720.      Set the variable point is in or near to `nil'.
  721.      Move to the next or previous variable.
  722.    Any changes take effect immediately, and last until you exit from
  723. Emacs.
  724. File: emacs,  Node: Hooks,  Next: Locals,  Prev: Edit Options,  Up: Variables
  725. Hooks
  726. -----
  727.    A "hook" is a variable where you can store a function or functions
  728. to be called on a particular occasion by an existing program.  Emacs
  729. provides a number of hooks for the sake of customization.
  730.    Most of the hooks in Emacs are "normal hooks".  These variables
  731. contain lists of functions to be called with no arguments.  The reason
  732. most hooks are normal hooks is so that you can use them in a uniform
  733. way.  Every variable in Emacs whose name ends in `-hook' is a normal
  734. hook.
  735.    Most major modes run hooks as the last step of initialization.  This
  736. makes it easy for a user to customize the behavior of the mode, by
  737. overriding the local variable assignments already made by the mode.  But
  738. hooks may also be used in other contexts.  For example, the hook
  739. `suspend-hook' runs just before Emacs suspends itself (*note
  740. Exiting::.).
  741.    The recommended way to add a hook function to a normal hook is by
  742. calling `add-hook'.  You can use any valid Lisp function as the hook
  743. function.  For example, here's how to set up a hook to turn on Auto
  744. Fill mode when entering Text mode and other modes based on Text mode:
  745.      (add-hook 'text-mode-hook 'turn-on-auto-fill)
  746.    The next example shows how to use a hook to customize the indentation
  747. of C code.  (People often have strong personal preferences for one
  748. format compared to another.)  Here the hook function is an anonymous
  749. lambda expression.
  750.      (add-hook 'c-mode-hook
  751.        (function (lambda ()
  752.                    (setq c-indent-level 4
  753.                          c-argdecl-indent 0
  754.                          c-label-offset -4
  755.                          c-continued-statement-indent 0
  756.                          c-brace-offset 0
  757.                          comment-column 40))))
  758.      
  759.      (setq c++-mode-hook c-mode-hook)
  760.    It is best to design your hook functions so that the order in which
  761. they are executed does not matter.  Any dependence on the order is
  762. "asking for trouble."  However, the order is predictable: the most
  763. recently added hook functions are executed first.
  764. File: emacs,  Node: Locals,  Next: File Variables,  Prev: Hooks,  Up: Variables
  765. Local Variables
  766. ---------------
  767. `M-x make-local-variable RET VAR RET'
  768.      Make variable VAR have a local value in the current buffer.
  769. `M-x kill-local-variable RET VAR RET'
  770.      Make variable VAR use its global value in the current buffer.
  771. `M-x make-variable-buffer-local RET VAR RET'
  772.      Mark variable VAR so that setting it will make it local to the
  773.      buffer that is current at that time.
  774.    Any variable can be made "local" to a specific Emacs buffer.  This
  775. means that its value in that buffer is independent of its value in other
  776. buffers.  A few variables are always local in every buffer.  Every other
  777. Emacs variable has a "global" value which is in effect in all buffers
  778. that have not made the variable local.
  779.    `M-x make-local-variable' reads the name of a variable and makes it
  780. local to the current buffer.  Further changes in this buffer will not
  781. affect others, and further changes in the global value will not affect
  782. this buffer.
  783.    `M-x make-variable-buffer-local' reads the name of a variable and
  784. changes the future behavior of the variable so that it will become local
  785. automatically when it is set.  More precisely, once a variable has been
  786. marked in this way, the usual ways of setting the variable automatically
  787. do `make-local-variable' first.  We call such variables "per-buffer"
  788. variables.
  789.    Major modes (*note Major Modes::.) always make the variables they set
  790. local to the buffer.  This is why changing major modes in one buffer has
  791. no effect on other buffers.  Minor modes also work by setting
  792. variables--normally, each minor mode has one controlling variable which
  793. is non-`nil' when the mode is enabled (*note Minor Modes::.).  For most
  794. minor modes, the controlling variable is per buffer.
  795.    Emacs contains a number of variables that are always per-buffer.
  796. These include `abbrev-mode', `auto-fill-function', `case-fold-search',
  797. `comment-column', `ctl-arrow', `fill-column', `fill-prefix',
  798. `indent-tabs-mode', `left-margin', `mode-line-format', `overwrite-mode',
  799. `selective-display-ellipses', `selective-display', `tab-width', and
  800. `truncate-lines'.  Some other variables are always local in every
  801. buffer, but they are used for internal purposes.
  802.    `M-x kill-local-variable' reads the name of a variable and makes it
  803. cease to be local to the current buffer.  The global value of the
  804. variable henceforth is in effect in this buffer.  Setting the major
  805. mode kills all the local variables of the buffer except for a few
  806. specially marked variables that are "permanent locals".
  807.    To set the global value of a variable, regardless of whether the
  808. variable has a local value in the current buffer, you can use the Lisp
  809. function `setq-default'.  It works like `setq'.  If there is a local
  810. value in the current buffer, the local value is not affected by
  811. `setq-default'; thus, the new global value may not be visible until you
  812. switch to another buffer.  For example,
  813.      (setq-default fill-column 75)
  814. `setq-default' is the only way to set the global value of a variable
  815. that has been marked with `make-variable-buffer-local'.
  816.    Lisp programs can look at a variable's default value with
  817. `default-value'.  This function takes a symbol as argument and returns
  818. its default value.  The argument is evaluated; usually you must quote
  819. it explicitly.  For example,
  820.      (default-value 'fill-column)
  821.