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

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