home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / VRAC / E17INFO.ZIP / EMACS-16 < prev    next >
Encoding:
GNU Info File  |  1993-07-18  |  48.4 KB  |  1,163 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: File Variables,  Prev: Locals,  Up: Variables
  6.  
  7. Local Variables in Files
  8. ------------------------
  9.  
  10.    A file can specify local variable values for use when you edit the
  11. file with Emacs.  Visiting the file checks for local variables
  12. specifications; it automatically makes these variables local to the
  13. buffer, and sets them to the values specified in the file.
  14.  
  15.    There are two ways to specify local variable values: in the first
  16. line, or with a local variables list.  Here's how to do this with the
  17. first line:
  18.  
  19.      -*- mode: MODENAME; VAR: VALUE; ... -*-
  20.  
  21. You can specify any number of variables/value pairs in this way, each
  22. pair with a colon and semicolon as shown above.  The major mode should
  23. come first, if it is mentioned at all.  Here is an example that
  24. specifies Lisp mode and sets two variables with numeric values:
  25.  
  26.      ;; -*-Mode: Lisp; fill-column: 75; comment-column: 50; -*-
  27.  
  28.    A "local variables list" goes near the end of the file, in the last
  29. page.  (It is often best to put it on a page by itself.)  The local
  30. variables list starts with a line containing the string `Local
  31. Variables:', and ends with a line containing the string `End:'.  In
  32. between come the variable names and values, one set per line, as
  33. `VARIABLE: VALUE'.  The VALUEs are not evaluated; they are used
  34. literally.
  35.  
  36.    Here is an example of a local variables list:
  37.  
  38.      ;;; Local Variables: ***
  39.      ;;; mode:lisp ***
  40.      ;;; comment-column:0 ***
  41.      ;;; comment-start: ";;; "  ***
  42.      ;;; comment-end:"***" ***
  43.      ;;; End: ***
  44.  
  45.    As you see, each line starts with the prefix `;;; ' and each line
  46. ends with the suffix ` ***'.  Emacs recognizes these as the prefix and
  47. suffix based on the first line of the list, by finding them surrounding
  48. the magic string `Local Variables:'; so it automatically discards them
  49. from the other lines of the list.
  50.  
  51.    The usual reason for using a prefix and/or suffix is to embed the
  52. local variables list in a comment, so it won't confuse other programs
  53. that the file is intended as input for.  The example above is for a
  54. language where comment lines start with `;;; ' and end with `***'; the
  55. local values for `comment-start' and `comment-end' customize the rest
  56. of Emacs for this unusual syntax.  Don't use a prefix (or a suffix) if
  57. you don't need one.
  58.  
  59.    Two "variable names" have special meanings in a local variables
  60. list: a value for the variable `mode' really sets the major mode, and a
  61. value for the variable `eval' is simply evaluated as an expression and
  62. the value is ignored.  `mode' and `eval' are not real variables;
  63. setting such variables in any other context has no such effect.  If
  64. `mode' is used in a local variables list, it should be the first entry
  65. in the list.
  66.  
  67.    The start of the local variables list must be no more than 3000
  68. characters from the end of the file, and must be in the last page if the
  69. file is divided into pages.  Otherwise, Emacs will not notice it is
  70. there.  The purpose of this is so that a stray `Local Variables:' not
  71. in the last page does not confuse Emacs, and so that visiting a long
  72. file that is all one page and has no local variables list need not take
  73. the time to search the whole file.
  74.  
  75.    You may be tempted to try to turn on Auto Fill mode with a local
  76. variable list.  That is a mistake.  The choice of Auto Fill mode or not
  77. is a matter of individual taste, not a matter of the contents of
  78. particular files.  If you want to use Auto Fill, set up major mode
  79. hooks with your `.emacs' file to turn it on (when appropriate) for you
  80. alone (*note Init File::.).  Don't try to use a local variable list
  81. that would impose your taste on everyone.
  82.  
  83.    The variable `enable-local-variables' controls whether to process
  84. local variables lists, and thus gives you a chance to override them.
  85. Its default value is `t', which means to process local variables lists.
  86. If you set the value to `nil', Emacs simply ignores local variables
  87. lists.  Any other value says to query you about each local variables
  88. list, showing you the local variables list to consider.
  89.  
  90.    The `eval' "variable" creates special risks, so there is a separate
  91. variable `enable-local-eval' to control whether Emacs processes `eval'
  92. variables.  The three possibilities for the value are `t', `nil', and
  93. anything else, just as for `enable-local-variables'.  The default is
  94. `maybe', which is neither `t' nor `nil', so normally Emacs queries about
  95. `eval' variable settings.
  96.  
  97.    Use the command `normal-mode' to reset the local variables and major
  98. mode of a buffer according to the file name and contents, including the
  99. local variables list if any.  *Note Choosing Modes::.
  100.  
  101. 
  102. File: emacs,  Node: Keyboard Macros,  Next: Key Bindings,  Prev: Variables,  Up: Customization
  103.  
  104. Keyboard Macros
  105. ===============
  106.  
  107.    A "keyboard macro" is a command defined by the user to abbreviate a
  108. sequence of keys.  For example, if you discover that you are about to
  109. type `C-n C-d' forty times, you can speed your work by defining a
  110. keyboard macro to do `C-n C-d' and calling it with a repeat count of
  111. forty.
  112.  
  113. `C-x ('
  114.      Start defining a keyboard macro (`start-kbd-macro').
  115.  
  116. `C-x )'
  117.      End the definition of a keyboard macro (`end-kbd-macro').
  118.  
  119. `C-x e'
  120.      Execute the most recent keyboard macro (`call-last-kbd-macro').
  121.  
  122. `C-u C-x ('
  123.      Re-execute last keyboard macro, then add more keys to its
  124.      definition.
  125.  
  126. `C-x q'
  127.      When this point is reached during macro execution, ask for
  128.      confirmation (`kbd-macro-query').
  129.  
  130. `M-x name-last-kbd-macro'
  131.      Give a command name (for the duration of the session) to the most
  132.      recently defined keyboard macro.
  133.  
  134. `M-x insert-kbd-macro'
  135.      Insert in the buffer a keyboard macro's definition, as Lisp code.
  136.  
  137.    Keyboard macros differ from ordinary Emacs commands in that they are
  138. written in the Emacs command language rather than in Lisp.  This makes
  139. it easier for the novice to write them, and makes them more convenient
  140. as temporary hacks.  However, the Emacs command language is not powerful
  141. enough as a programming language to be useful for writing anything
  142. intelligent or general.  For such things, Lisp must be used.
  143.  
  144.    You define a keyboard macro while executing the commands which are
  145. the definition.  Put differently, as you define a keyboard macro, the
  146. definition is being executed for the first time.  This way, you can see
  147. what the effects of your commands are, so that you don't have to figure
  148. them out in your head.  When you are finished, the keyboard macro is
  149. defined and also has been, in effect, executed once.  You can then do
  150. the whole thing over again by invoking the macro.
  151.  
  152. * Menu:
  153.  
  154. * Basic Kbd Macro::     Defining and running keyboard macros.
  155. * Save Kbd Macro::      Giving keyboard macros names; saving them in files.
  156. * Kbd Macro Query::     Keyboard macros that do different things each use.
  157.  
  158. 
  159. File: emacs,  Node: Basic Kbd Macro,  Next: Save Kbd Macro,  Up: Keyboard Macros
  160.  
  161. Basic Use
  162. ---------
  163.  
  164.    To start defining a keyboard macro, type the `C-x (' command
  165. (`start-kbd-macro').  From then on, your keys continue to be executed,
  166. but also become part of the definition of the macro.  `Def' appears in
  167. the mode line to remind you of what is going on.  When you are
  168. finished, the `C-x )' command (`end-kbd-macro') terminates the
  169. definition (without becoming part of it!).  For example
  170.  
  171.      C-x ( M-f foo C-x )
  172.  
  173. defines a macro to move forward a word and then insert `foo'.
  174.  
  175.    The macro thus defined can be invoked again with the `C-x e' command
  176. (`call-last-kbd-macro'), which may be given a repeat count as a numeric
  177. argument to execute the macro many times.  `C-x )' can also be given a
  178. repeat count as an argument, in which case it repeats the macro that
  179. many times right after defining it, but defining the macro counts as
  180. the first repetition (since it is executed as you define it).  So,
  181. giving `C-x )' an argument of 4 executes the macro immediately 3
  182. additional times.  An argument of zero to `C-x e' or `C-x )' means
  183. repeat the macro indefinitely (until it gets an error or you type
  184. `C-g').
  185.  
  186.    If you wish to repeat an operation at regularly spaced places in the
  187. text, define a macro and include as part of the macro the commands to
  188. move to the next place you want to use it.  For example, if you want to
  189. change each line, you should position point at the start of a line, and
  190. define a macro to change that line and leave point at the start of the
  191. next line.  Then repeating the macro will operate on successive lines.
  192.  
  193.    After you have terminated the definition of a keyboard macro, you
  194. can add to the end of its definition by typing `C-u C-x ('.  This is
  195. equivalent to plain `C-x (' followed by retyping the whole definition
  196. so far.  As a consequence it re-executes the macro as previously
  197. defined.
  198.  
  199.    You can use function keys in a keyboard macro, just like keyboard
  200. keys.  You can even use mouse events, but be careful about that: when
  201. the macro replays the mouse event, it uses the original mouse position
  202. of that event, the position that the mouse had while you were defining
  203. the macro.  The effect of this may be hard to predict.  (Using the
  204. current mouse position would be even less predictable.)
  205.  
  206.    One thing that doesn't always work well in a keyboard macro is the
  207. command `C-M-c' (`exit-recursive-edit').  When this command exits a
  208. recursive edit that started within the macro, it works as you'd expect.
  209. But if it exits a recursive edit that started before you invoked the
  210. keyboard macro, it also necessarily exits the keyboard macro as part of
  211. the process.
  212.  
  213. 
  214. File: emacs,  Node: Save Kbd Macro,  Next: Kbd Macro Query,  Prev: Basic Kbd Macro,  Up: Keyboard Macros
  215.  
  216. Naming and Saving Keyboard Macros
  217. ---------------------------------
  218.  
  219.    If you wish to save a keyboard macro for longer than until you
  220. define the next one, you must give it a name using `M-x
  221. name-last-kbd-macro'.  This reads a name as an argument using the
  222. minibuffer and defines that name to execute the macro.  The macro name
  223. is a Lisp symbol, and defining it in this way makes it a valid command
  224. name for calling with `M-x' or for binding a key to with
  225. `global-set-key' (*note Keymaps::.).  If you specify a name that has a
  226. prior definition other than another keyboard macro, an error message is
  227. printed and nothing is changed.
  228.  
  229.    Once a macro has a command name, you can save its definition in a
  230. file.  Then it can be used in another editing session.  First, visit
  231. the file you want to save the definition in.  Then use this command:
  232.  
  233.      M-x insert-kbd-macro RET MACRONAME RET
  234.  
  235. This inserts some Lisp code that, when executed later, will define the
  236. same macro with the same definition it has now.  (You need not
  237. understand Lisp code to do this, because `insert-kbd-macro' writes the
  238. Lisp code for you.)  Then save the file.  You can load the file later
  239. with `load-file' (*note Lisp Libraries::.).  If the file you save in is
  240. your init file `~/.emacs' (*note Init File::.) then the macro will be
  241. defined each time you run Emacs.
  242.  
  243.    If you give `insert-kbd-macro' a prefix argument, it makes
  244. additional Lisp code to record the keys (if any) that you have bound to
  245. the keyboard macro, so that the macro will be reassigned the same keys
  246. when you load the file.
  247.  
  248. 
  249. File: emacs,  Node: Kbd Macro Query,  Prev: Save Kbd Macro,  Up: Keyboard Macros
  250.  
  251. Executing Macros with Variations
  252. --------------------------------
  253.  
  254.    Using `C-x q' (`kbd-macro-query'), you can get an effect similar to
  255. that of `query-replace', where the macro asks you each time around
  256. whether to make a change.  When you are defining the macro, type `C-x
  257. q' at the point where you want the query to occur.  During macro
  258. definition, the `C-x q' does nothing, but when you run the macro later,
  259. `C-x q' asks you interactively whether to continue.
  260.  
  261.    The valid responses when `C-x q' asks are SPC (or `y'), DEL (or
  262. `n'), ESC (or `q'), `C-l' and `C-r'.  The answers are the same as in
  263. query replace, though not all of the query-replace options are
  264. meaningful.
  265.  
  266.    Specifically, SPC means to continue.  DEL means to skip the
  267. remainder of this repetition of the macro and start right away with the
  268. next repetition.  ESC means to skip the remainder of this repetition
  269. and cancel further repetition.  `C-l' redraws the screen and asks you
  270. again for a character to say what to do.
  271.  
  272.    `C-r' enters a recursive editing level, in which you can perform
  273. editing which is not part of the macro.  When you exit the recursive
  274. edit using `C-M-c', you are asked again how to continue with the
  275. keyboard macro.  If you type a SPC at this time, the rest of the macro
  276. definition is executed.  It is up to you to leave point and the text in
  277. a state such that the rest of the macro will do what you want.
  278.  
  279.    `C-u C-x q', which is `C-x q' with a numeric argument, performs a
  280. different function.  It enters a recursive edit reading input from the
  281. keyboard, both when you type it during the definition of the macro, and
  282. when it is executed from the macro.  During definition, the editing you
  283. do inside the recursive edit does not become part of the macro.  During
  284. macro execution, the recursive edit gives you a chance to do some
  285. particularized editing.  *Note Recursive Edit::.
  286.  
  287. 
  288. File: emacs,  Node: Key Bindings,  Next: Keyboard Translations,  Prev: Keyboard Macros,  Up: Customization
  289.  
  290. Customizing Key Bindings
  291. ========================
  292.  
  293.    This section describes "key bindings" which map keys to commands,
  294. and the "keymaps" which record key bindings.  It also explains how to
  295. customize key bindings.
  296.  
  297.    Recall that a command is a Lisp function whose definition provides
  298. for interactive use.  Like every Lisp function, a command has a function
  299. name which usually consists of lower case letters and hyphens.
  300.  
  301. * Menu:
  302.  
  303. * Keymaps::          Generalities.  The global keymap.
  304. * Prefix Keymaps::   Keymaps for prefix keys.
  305. * Local Keymaps::    Major and minor modes have their own keymaps.
  306. * Minibuffer Maps::  The minibuffer uses its own local keymaps.
  307. * Rebinding::        How to redefine one key's meaning conveniently.
  308. * Init Rebinding::   Rebinding keys with your init file, `.emacs'.
  309. * Function Keys::    Rebinding terminal function keys.
  310. * Mouse Buttons::    Rebinding mouse buttons in Emacs.
  311. * Disabling::        Disabling a command means confirmation is required
  312.                        before it can be executed.  This is done to protect
  313.                        beginners from surprises.
  314.  
  315. 
  316. File: emacs,  Node: Keymaps,  Next: Prefix Keymaps,  Up: Key Bindings
  317.  
  318. Keymaps
  319. -------
  320.  
  321.    The bindings between key sequences and command functions are recorded
  322. in data structures called "keymaps".  Emacs has many of these, each
  323. used on particular occasions.
  324.  
  325.    Recall that a "key sequence" ("key", for short) is a sequence of
  326. "input events" that have a meaning as a unit.  Input events include
  327. characters, function keys and mouse buttons--all the inputs that you
  328. can send to the computer with your terminal.  A key sequence gets its
  329. meaning from its "binding", which says what command it runs.  The
  330. function of keymaps is to record these bindings.
  331.  
  332.    The "global" keymap is the most important keymap because it is
  333. always in effect.  The global keymap defines keys for Fundamental mode;
  334. most of these definitions are common to all (or most) major modes.  Each
  335. major or minor mode can have its own keymap which overrides the
  336. definitions of some keys.
  337.  
  338.    For example, a self-inserting character such as `g' is
  339. self-inserting because the global keymap binds it to the command
  340. `self-insert-command'.  The standard Emacs editing characters such as
  341. `C-a' also get their standard meanings from the global keymap.
  342. Commands to rebind keys, such as `M-x global-set-key', actually work by
  343. storing the new binding in the proper place in the global map.  *Note
  344. Rebinding::.
  345.  
  346.    Meta characters work differently; Emacs translates each Meta
  347. character into a pair of characters starting with ESC.  When you type
  348. the character `M-a' in a key sequence, Emacs replaces it with `ESC a'.
  349. A meta key comes in as a single input event, but becomes two events for
  350. purposes of key bindings.  The reason for this is historical, and we
  351. might change in someday.
  352.  
  353.    Most modern keyboards have function keys as well as character keys.
  354. Function keys send input events just as character keys do, and keymaps
  355. can have bindings for them.
  356.  
  357.    On many terminals, typing a function key actually sends the computer
  358. a sequence of characters; the precise details of the sequence depends on
  359. which function key and on the model of terminal you are using.  (Often
  360. he sequence starts with `ESC ['.)  If Emacs understands your terminal
  361. type properly, it recognizes the character sequences forming function
  362. keys wherever they occur in a key sequence (not just at the beginning).
  363. Thus, for most purposes, you can pretend the function keys reach Emacs
  364. directly and ignore their encoding as character sequences.
  365.  
  366.    Mouse buttons also produce input events.  These events come with
  367. other data--the window and position where you pressed or released the
  368. button, and a timestamp.  But only the choice of button matters for key
  369. bindings; the other data matters only if a command looks at it.
  370. (Commands designed for mouse invocation usually do look at the other
  371. data.)
  372.  
  373.    A keymap records definitions for single events.  Interpreting a key
  374. sequence of multiple events involves a chain of keymaps.  The first
  375. keymap gives a definition for the first event; this definition is
  376. another keymap, which is used to look up the second event in the
  377. sequence, and so on.
  378.  
  379.    Key sequences can mix function keys and characters.  For example,
  380. `C-x SELECT' makes sense.  If you make SELECT a prefix key, then
  381. `SELECT C-n' makes sense.  You can even mix mouse events with keyboard
  382. events, but we recommend against it, because such sequences are
  383. inconvenient to type in.
  384.  
  385. 
  386. File: emacs,  Node: Prefix Keymaps,  Next: Local Keymaps,  Prev: Keymaps,  Up: Key Bindings
  387.  
  388. Prefix Keymaps
  389. --------------
  390.  
  391.    A prefix key such as `C-x' or ESC has its own keymap, which holds
  392. the definition for the event that immediately follows that prefix.
  393.  
  394.    The definition of a prefix key is the keymap to use for looking up
  395. the following event.  The definition can also be a Lisp symbol whose
  396. function definition is the following keymap; the effect is the same, but
  397. it provides a command name for the prefix key that can be used as a
  398. description of what the prefix key is for.  Thus, the binding of `C-x'
  399. is the symbol `Ctl-X-Prefix', whose function definition is the keymap
  400. for `C-x' commands.  The definitions of `C-c', `C-x', `C-h' and ESC as
  401. prefix keys appear in the global map, so these prefix keys are always
  402. available.
  403.  
  404.    Some prefix keymaps are stored in variables with names:
  405.  
  406.    * `ctl-x-map' is the variable name for the map used for characters
  407.      that follow `C-x'.
  408.  
  409.    * `help-map' is for characters that follow `C-h'.
  410.  
  411.    * `esc-map' is for characters that follow ESC.  Thus, all Meta
  412.      characters are actually defined by this map.
  413.  
  414.    * `ctl-x-4-map' is for characters that follow `C-x 4'.
  415.  
  416.    * `mode-specific-map' is for characters that follow `C-c'.
  417.  
  418. 
  419. File: emacs,  Node: Local Keymaps,  Next: Minibuffer Maps,  Prev: Prefix Keymaps,  Up: Key Bindings
  420.  
  421. Local Keymaps
  422. -------------
  423.  
  424.    So far we have explained the ins and outs of the global map.  Major
  425. modes customize Emacs by providing their own key bindings in "local
  426. keymaps".  For example, C mode overrides TAB to make it indent the
  427. current line for C code.  Portions of text in the buffer can specify
  428. their own keymaps to substitute for the keymap of the buffer's major
  429. mode.
  430.  
  431.    Minor modes can also have local keymaps.  Whenever a minor mode is
  432. in effect, the definitions in its keymap override both the major mode's
  433. local keymap and the global keymap.
  434.  
  435.    The local keymaps for Lisp mode, C mode, and several other major
  436. modes always exist even when not in use.  These are kept in variables
  437. named `lisp-mode-map', `c-mode-map', and so on.  For major modes less
  438. often used, the local keymap is normally constructed only when the mode
  439. is used for the first time in a session.  This is to save space.
  440.  
  441.    All minor mode keymaps are created in advance.  There is no way to
  442. defer their creation until the minor mode is enabled.
  443.  
  444.    A local keymap can locally redefine a key as a prefix key by defining
  445. it as a prefix keymap.  If the key is also defined globally as a prefix,
  446. then its local and global definitions (both keymaps) effectively
  447. combine: both of them are used to look up the event that follows the
  448. prefix key.  Thus, if the mode's local keymap defines `C-c' as another
  449. keymap, and that keymap defines `C-z' as a command, this provides a
  450. local meaning for `C-c C-z'.  This does not affect other sequences that
  451. start with `C-c'; If those sequences don't have their own local
  452. bindings, their global bindings remain in effect.
  453.  
  454.    Another way to think of this is that Emacs handles a multi-event key
  455. sequence by looking in several keymaps, one by one, for a binding of the
  456. whole key sequence.  First it checks the minor mode keymaps for minor
  457. modes that are enabled, then it checks the major mode's keymap, and then
  458. it checks the global keymap.  This is not precisely how key lookup
  459. works, but it's good enough for understanding ordinary circumstances.
  460.  
  461. 
  462. File: emacs,  Node: Minibuffer Maps,  Next: Rebinding,  Prev: Local Keymaps,  Up: Key Bindings
  463.  
  464. Minibuffer Keymaps
  465. ------------------
  466.  
  467.    The minibuffer has its own set of local keymaps; they contain various
  468. completion and exit commands.
  469.  
  470.    * `minibuffer-local-map' is used for ordinary input (no completion).
  471.  
  472.    * `minibuffer-local-ns-map' is similar, except that SPC exits just
  473.      like RET.  This is used mainly for Mocklisp compatibility.
  474.  
  475.    * `minibuffer-local-completion-map' is for permissive completion.
  476.  
  477.    * `minibuffer-local-must-match-map' is for strict completion and for
  478.      cautious completion.
  479.  
  480. 
  481. File: emacs,  Node: Rebinding,  Next: Init Rebinding,  Prev: Minibuffer Maps,  Up: Key Bindings
  482.  
  483. Changing Key Bindings Interactively
  484. -----------------------------------
  485.  
  486.    The way to redefine an Emacs key is to change its entry in a keymap.
  487. You can change the global keymap, in which case the change is effective
  488. in all major modes (except those that have their own overriding local
  489. definitions for the same key).  Or you can change the current buffer's
  490. local map, which affects all buffers using the same major mode.
  491.  
  492. `M-x global-set-key RET KEY CMD RET'
  493.      Define KEY globally to run CMD.
  494.  
  495. `M-x local-set-key RET KEY CMD RET'
  496.      Define KEY locally (in the major mode now in effect) to run CMD.
  497.  
  498. `M-x global-unset-key RET KEY'
  499.      Make KEY undefined in the global map.
  500.  
  501. `M-x local-unset-key RET KEY'
  502.      Make KEY undefined locally (in the major mode now in effect).
  503.  
  504.    For example, suppose you like to execute commands in a subshell
  505. within an Emacs buffer, instead of suspending Emacs and executing
  506. commands in your login shell.  Normally, `C-z' is bound to the function
  507. `suspend-emacs', but you can change `C-z' to invoke an interactive
  508. subshell within Emacs, by binding it to `shell' as follows:
  509.  
  510.      M-x global-set-key RET C-z shell RET
  511.  
  512. `global-set-key' reads the command name after the key.   After you
  513. press the key, a message like this appears so that you can confirm that
  514. you are binding the key you want:
  515.  
  516.      Set key C-z to command:
  517.  
  518.    You can redefine function keys and mouse events in the same way; just
  519. type the function key or click the mouse when it's time to specify the
  520. key to rebind.
  521.  
  522.    You can rebind a key that contains more than one event in the same
  523. way.  Emacs keeps reading the key to rebind until it is a complete key
  524. (that is, not a prefix key).  Thus, if you type `C-f' for KEY, that's
  525. the end; the minibuffer is entered immediately to read CMD.  But if you
  526. type `C-x', another character is read; if that is `4', another
  527. character is read, and so on.  For example,
  528.  
  529.      M-x global-set-key RET C-x 4 $ spell-other-window RET
  530.  
  531. would redefine `C-x 4 $' to run the (fictitious) command
  532. `spell-other-window'.
  533.  
  534.    You can remove the global definition of a key with
  535. `global-unset-key'.  This makes the key "undefined"; if you type it,
  536. Emacs will just beep.  Similarly, `local-unset-key' makes a key
  537. undefined in the current major mode keymap, which makes the global
  538. definition (or lack of one) come back into effect in that major mode.
  539.  
  540.    If you have redefined (or undefined) a key and you subsequently wish
  541. to retract the change, undefining the key will not do the job--you need
  542. to redefine the key with its standard definition.  To find the name of
  543. the standard definition of a key, go to a Fundamental mode buffer and
  544. use `C-h c'.  The documentation of keys in this manual also lists their
  545. command names.
  546.  
  547.    If you want to prevent yourself from invoking a command by mistake,
  548. it is better to disable the command than to undefine the key.  A
  549. disabled command is less work to invoke when you really want to.  *Note
  550. Disabling::.
  551.  
  552. 
  553. File: emacs,  Node: Init Rebinding,  Next: Function Keys,  Prev: Rebinding,  Up: Key Bindings
  554.  
  555. Rebinding Keys in Your Init File
  556. --------------------------------
  557.  
  558.    If you have a set of default definitions that you like to use all
  559. the time, you can put commands in your `.emacs' file by using their
  560. Lisp syntax.  Thus, the first `global-set-key' command in this section
  561. could be put in an `.emacs' file in either of the two following formats:
  562.  
  563.      (global-set-key "\C-z" 'shell)
  564.  
  565.    or as:
  566.  
  567.      (global-set-key [?\C-z] 'shell)
  568.  
  569. When the key sequence consists of characters, like this one, you can
  570. write it as a string or as a vector.  The first format specifies the key
  571. sequence as a string, `"\C-z"'.  The second format uses a vector to
  572. specify the key sequence.  The square brackets (`[...]') delimit the
  573. contents of the vector.  The vector in this example contains just one
  574. element, which is the integer code corresponding to `C-z'.  The
  575. question mark is the Lisp syntax for a character constant; the
  576. character must follow with no intervening spaces.
  577.  
  578.    The single-quote before `shell' marks it as a constant symbol rather
  579. than a variable.  If you omit the quote, Emacs tries to evaluate
  580. `shell' immediately as a variable.  This probably causes an error; it
  581. certainly isn't what you want.
  582.  
  583.    Here is another example that binds a key sequence two characters
  584. long:
  585.  
  586.      (global-set-key "\C-xl" 'make-symbolic-link)
  587.  
  588.    or:
  589.  
  590.      (global-set-key [?\C-x ?l] 'make-symbolic-link)
  591.  
  592. 
  593. File: emacs,  Node: Function Keys,  Next: Mouse Buttons,  Prev: Init Rebinding,  Up: Key Bindings
  594.  
  595. Rebinding Function Keys
  596. -----------------------
  597.  
  598.    Key sequences can contain function keys as well as ordinary
  599. characters.  Just as Lisp characters (actually integers) represent
  600. keyboard characters, Lisp symbols represent function keys.  If the
  601. function key has a word as its label, then that word is also the name
  602. of the corresponding Lisp symbol.  Here are the Lisp names for other
  603. function keys:
  604.  
  605. `left', `up', `right', `down'
  606.      Cursor arrow keys.
  607.  
  608. `begin', `end', `home', `next', `prior'
  609.      Other cursor repositioning keys.
  610.  
  611. `select', `print', `execute', `backtab'
  612. `insert', `undo', `redo', `clearline'
  613. `insertline', `deleteline', `insertchar', `deletechar',
  614.      Miscellaneous function keys.
  615.  
  616. `f1' ... `f35'
  617.      Numbered function keys (across the top of the keyboard).
  618.  
  619. `kp-add', `kp-subtract', `kp-multiply', `kp-divide'
  620. `kp-backtab', `kp-space', `kp-tab', `kp-enter'
  621. `kp-separator', `kp-decimal', `kp-equal'
  622.      Keypad keys (to the right of the regular keyboard), with names or
  623.      punctuation.
  624.  
  625. `kp-0', `kp-1', ... `kp-9'
  626.      Keypad keys with digits.
  627.  
  628. `kp-f1', `kp-f2', `kp-f3', `kp-f4'
  629.      Keypad PF keys.
  630.  
  631.    A key sequence which contains non-characters must be a vector rather
  632. than a string.  To write a vector, write square brackets containing the
  633. vector elements.  Write spaces to separate the elements.  If an element
  634. is a symbol, simply write the symbol's name--no delimiters or
  635. punctuation are needed.  If an element is a character, write a Lisp
  636. character constant, which is `?' followed by the character as it would
  637. appear in a string.
  638.  
  639.    Thus, to bind function key `f1' to the command `rmail', write the
  640. following:
  641.  
  642.      (global-set-key [f1] 'rmail)
  643.  
  644.    To bind the right-arrow key to the command `forward-char', you can
  645. use this expression:
  646.  
  647.      (global-set-key [right] 'forward-char)
  648.  
  649. using the Lisp syntax for a vector containing the symbol `right'.
  650. (This binding is present in Emacs by default.)
  651.  
  652.    You can mix function keys and characters in a key sequence.  This
  653. example binds `C-x RIGHT' to the command `forward-page'.
  654.  
  655.      (global-set-key [?\C-x right] 'forward-page)
  656.  
  657. where `?\C-x' is the Lisp character constant for the character `C-x'.
  658. The vector element `right' is a symbol and therefore does not take a
  659. question mark.
  660.  
  661.    You can use the modifier keys CTRL, META, HYPER, SUPER, ALT and
  662. SHIFT with function keys.  To represent these modifiers, prepend the
  663. strings `C-', `M-', `H-', `s-', `A-' and `S-' to the symbol name.
  664. Thus, here is how to make `Hyper-Meta-RIGHT' move forward a word:
  665.  
  666.      (global-set-key [H-M-right] 'forward-word)
  667.  
  668. 
  669. File: emacs,  Node: Mouse Buttons,  Next: Disabling,  Prev: Function Keys,  Up: Key Bindings
  670.  
  671. Rebinding Mouse Buttons
  672. -----------------------
  673.  
  674.    Emacs uses Lisp symbols to designate mouse buttons, too.  The
  675. ordinary mouse events in Emacs are "click" events; these happen when you
  676. press a button and release it without moving the mouse.  You can also
  677. get "drag" events, when you move the mouse while holding the button
  678. down.  Drag events happen when you finally let go of the button.
  679.  
  680.    The symbols for basic click events are `mouse-1' for the leftmost
  681. button, `mouse-2' for the next, and so on.  Here is how you can
  682. redefine the second mouse button to split the current window:
  683.  
  684.      (global-set-key [mouse-2] 'split-window-vertically)
  685.  
  686.    The symbols for drag events are similar, but have the prefix `drag-'
  687. before the word `mouse'.  For example, dragging the left button
  688. generates a `drag-mouse-1' event.
  689.  
  690.    You can also request events when the mouse button is pressed down.
  691. These events start with `down-' instead of `drag-'.  Such events are
  692. generated only if they have key bindings.  When you get a button-down
  693. event, a corresponding click or drag event will always follow.
  694.  
  695.    The symbols for mouse events also indicate the status of the modifier
  696. keys, with the usual prefixes `C-', `M-', `H-', `s-', `A-' and `S-'.
  697. These always follow `drag-' or `down-'.
  698.  
  699.    A frame includes areas that don't show text from the buffer, such as
  700. the mode line and the scroll bar.  You can tell whether a mouse button
  701. comes from a special area of the screen by means of dummy "prefix
  702. keys."  For example, if you click the mouse in the mode line, you get
  703. the prefix key `mode-line' before the ordinary mouse-button symbol.
  704. Thus, here is how to define the command for clicking the left button in
  705. a mode line to run `scroll-up':
  706.  
  707.      (global-set-key [mode-line mouse-1] 'scroll-up)
  708.  
  709.    Here is the complete list of these dummy prefix keys and their
  710. meanings:
  711.  
  712. `mode-line'
  713.      The mouse was in the mode line of a window.
  714.  
  715. `vertical-line'
  716.      The mouse was in the vertical line separating side-by-side windows.
  717.  
  718. `vertical-scroll-bar'
  719.      The mouse was in a horizontal scroll bar.  This is the kind of
  720.      scroll bar people normally use.
  721.  
  722. `horizontal-scroll-bar'
  723.      The mouse was in a horizontal scroll bar.  Horizontal scroll bars
  724.      do horizontal scrolling, and people don't use them often.
  725.  
  726.    You can put more than one mouse button in a key sequence, but it
  727. isn't usual to do so.
  728.  
  729. 
  730. File: emacs,  Node: Disabling,  Prev: Mouse Buttons,  Up: Key Bindings
  731.  
  732. Disabling Commands
  733. ------------------
  734.  
  735.    Disabling a command marks the command as requiring confirmation
  736. before it can be executed.  The purpose of disabling a command is to
  737. prevent beginning users from executing it by accident and being
  738. confused.
  739.  
  740.    Attempting to invoke a disabled command interactively in Emacs
  741. causes the display of a window containing the command's name, its
  742. documentation, and some instructions on what to do immediately; then
  743. Emacs asks for input saying whether to execute the command as
  744. requested, enable it and execute, or cancel it.  If you decide to
  745. enable the command, you are asked whether to do this permanently or
  746. just for the current session.  Enabling permanently works by
  747. automatically editing your `.emacs' file.
  748.  
  749.    The direct mechanism for disabling a command is to have a non-`nil'
  750. `disabled' property on the Lisp symbol for the command.  Here is the
  751. Lisp program to do this:
  752.  
  753.      (put 'delete-region 'disabled t)
  754.  
  755.    If the value of the `disabled' property is a string, that string is
  756. included in the message printed when the command is used:
  757.  
  758.      (put 'delete-region 'disabled
  759.           "Text deleted this way cannot be yanked back!\n")
  760.  
  761.    You can make a command disabled either by editing the `.emacs' file
  762. directly or with the command `M-x disable-command', which edits the
  763. `.emacs' file for you.  Likewise, `M-x enable-command' edits `.emacs'
  764. to enable a command permanently.  *Note Init File::.
  765.  
  766.    Whether a command is disabled is independent of what key is used to
  767. invoke it; it also applies if the command is invoked using `M-x'.
  768. Disabling a command has no effect on calling it as a function from Lisp
  769. programs.
  770.  
  771. 
  772. File: emacs,  Node: Keyboard Translations,  Next: Syntax,  Prev: Key Bindings,  Up: Customization
  773.  
  774. Keyboard Translations
  775. =====================
  776.  
  777.    Some keyboards do not make it convenient to send all the special
  778. characters that Emacs uses.  The most common problem case is the DEL
  779. character.  Some keyboards provide no convenient way to type this very
  780. important character--usually because they were designed to expect the
  781. character `C-h' to be used for deletion.  On these keyboard, if you
  782. press the key normally used for deletion, Emacs handles the `C-h' as a
  783. prefix character and offers you a list of help options, which is not
  784. what you want.
  785.  
  786.    You can work around this problem within Emacs by setting up keyboard
  787. translations to turn `C-h' into DEL and DEL into `C-h', as follows:
  788.  
  789.      ;; Translate `C-h' to DEL.
  790.      (keyboard-translate ?\C-h ?\C-?)
  791.      ;; Translate DEL to `C-h'.
  792.      (keyboard-translate ?\C-? ?\C-h)
  793.  
  794.    Keyboard translations are not the same as key bindings in keymaps
  795. (*note Keymaps::.).  Emacs contains numerous keymaps that apply in
  796. different situations, but there is only one set of keyboard
  797. translations, and it applies to every character that Emacs reads from
  798. the terminal.  Keyboard translations take place at the lowest level of
  799. input processing; the keys that are looked up in keymaps contain the
  800. characters that result from keyboard translation.
  801.  
  802.    For full information about how to use keyboard translations, see
  803. *Note Translating Input: (elisp)Translating Input.
  804.  
  805. 
  806. File: emacs,  Node: Syntax,  Next: Init File,  Prev: Keyboard Translations,  Up: Customization
  807.  
  808. The Syntax Table
  809. ================
  810.  
  811.    All the Emacs commands which parse words or balance parentheses are
  812. controlled by the "syntax table".  The syntax table says which
  813. characters are opening delimiters, which are parts of words, which are
  814. string quotes, and so on.  Each major mode has its own syntax table
  815. (though sometimes related major modes use the same one) which it
  816. installs in each buffer that uses that major mode.  The syntax table
  817. installed in the current buffer is the one that all commands use, so we
  818. call it "the" syntax table.  A syntax table is a Lisp object, a vector
  819. of length 256 whose elements are numbers.
  820.  
  821.    To display a description of the contents of the current syntax table,
  822. type `C-h s' (`describe-syntax').  The description of each character
  823. includes both the string you would have to give to
  824. `modify-syntax-entry' to set up that character's current syntax, and
  825. some English to explain that string if necessary.
  826.  
  827.    For full information on the syntax table, see *Note Syntax Table:
  828. (elisp)Syntax Table.
  829.  
  830. 
  831. File: emacs,  Node: Init File,  Prev: Syntax,  Up: Customization
  832.  
  833. The Init File, `~/.emacs'
  834. =========================
  835.  
  836.    When Emacs is started, it normally loads a Lisp program from the file
  837. `.emacs' in your home directory.  We call this file your "init file"
  838. because it specifies how to initialize Emacs for you.  You can use the
  839. command line switches `-q' and `-u' to tell Emacs whether to load an
  840. init file, and which one (*note Entering Emacs::.).
  841.  
  842.    There can also be a "default init file", which is the library named
  843. `default.el', found via the standard search path for libraries.  The
  844. Emacs distribution contains no such library; your site may create one
  845. for local customizations.  If this library exists, it is loaded
  846. whenever you start Emacs (except when you specify `-q').  But your init
  847. file, if any, is loaded first; if it sets `inhibit-default-init'
  848. non-`nil', then `default' is not loaded.
  849.  
  850.    If you have a large amount of code in your `.emacs' file, you should
  851. move it into another file such as `~/SOMETHING.el', byte-compile it,
  852. and make your `.emacs' file load it with `(load "~/SOMETHING")'.  *Note
  853. Byte Compilation: (elisp)Byte Compilation, for more information about
  854. compiling Emacs Lisp programs.
  855.  
  856. * Menu:
  857.  
  858. * Init Syntax::     Syntax of constants in Emacs Lisp.
  859. * Init Examples::   How to do some things with an init file.
  860. * Terminal Init::   Each terminal type can have an init file.
  861. * Find Init::        How Emacs finds the init file.
  862.  
  863. 
  864. File: emacs,  Node: Init Syntax,  Next: Init Examples,  Up: Init File
  865.  
  866. Init File Syntax
  867. ----------------
  868.  
  869.    The `.emacs' file contains one or more Lisp function call
  870. expressions.  Each of these consists of a function name followed by
  871. arguments, all surrounded by parentheses.  For example, `(setq
  872. fill-column 60)' calls the function `setq' to set the variable
  873. `fill-column' (*note Filling::.) to 60.
  874.  
  875.    The second argument to `setq' is an expression for the new value of
  876. the variable.  This can be a constant, a variable, or a function call
  877. expression.  In `.emacs', constants are used most of the time.  They
  878. can be:
  879.  
  880. Numbers:
  881.      Numbers are written in decimal, with an optional initial minus
  882.      sign.
  883.  
  884. Strings:
  885.      Lisp string syntax is the same as C string syntax with a few extra
  886.      features.  Use a double-quote character to begin and end a string
  887.      constant.
  888.  
  889.      In a string, you can include newlines and special characters
  890.      literally.  But often it is cleaner to use backslash sequences for
  891.      them: `\n' for newline, `\b' for backspace, `\r' for carriage
  892.      return, `\t' for tab, `\f' for formfeed (control-L), `\e' for
  893.      escape, `\\' for a backslash, `\"' for a double-quote, or `\OOO'
  894.      for the character whose octal code is OOO.  Backslash and
  895.      double-quote are the only characters for which backslash sequences
  896.      are mandatory.
  897.  
  898.      `\C-' can be used as a prefix for a control character, as in
  899.      `\C-s' for ASCII control-S, and `\M-' can be used as a prefix for
  900.      a Meta character, as in `\M-a' for `Meta-A' or `\M-\C-a' for
  901.      `Control-Meta-A'.
  902.  
  903. Characters:
  904.      Lisp character constant syntax consists of a `?' followed by
  905.      either a character or an escape sequence starting with `\'.
  906.      Examples: `?x', `?\n', `?\"', `?\)'.  Note that strings and
  907.      characters are not interchangeable in Lisp; some contexts require
  908.      one and some contexts require the other.
  909.  
  910. True:
  911.      `t' stands for `true'.
  912.  
  913. False:
  914.      `nil' stands for `false'.
  915.  
  916. Other Lisp objects:
  917.      Write a single-quote (') followed by the Lisp object you want.
  918.  
  919. 
  920. File: emacs,  Node: Init Examples,  Next: Terminal Init,  Prev: Init Syntax,  Up: Init File
  921.  
  922. Init File Examples
  923. ------------------
  924.  
  925.    Here are some examples of doing certain commonly desired things with
  926. Lisp expressions:
  927.  
  928.    * Make TAB in C mode just insert a tab if point is in the middle of a
  929.      line.
  930.  
  931.           (setq c-tab-always-indent nil)
  932.  
  933.      Here we have a variable whose value is normally `t' for `true' and
  934.      the alternative is `nil' for `false'.
  935.  
  936.    * Make searches case sensitive by default (in all buffers that do not
  937.      override this).
  938.  
  939.           (setq-default case-fold-search nil)
  940.  
  941.      This sets the default value, which is effective in all buffers
  942.      that do not have local values for the variable.  Setting
  943.      `case-fold-search' with `setq' affects only the current buffer's
  944.      local value, which is not what you probably want to do in an init
  945.      file.
  946.  
  947.    * Make Text mode the default mode for new buffers.
  948.  
  949.           (setq default-major-mode 'text-mode)
  950.  
  951.      Note that `text-mode' is used because it is the command for
  952.      entering Text mode.  The single-quote before it makes the symbol a
  953.      constant; otherwise, `text-mode' would be treated as a variable
  954.      name.
  955.  
  956.    * Turn on Auto Fill mode automatically in Text mode and related
  957.      modes.
  958.  
  959.           (add-hook 'text-mode-hook
  960.             '(lambda () (auto-fill-mode 1)))
  961.  
  962.      This shows how to add a hook function to a normal hook variable
  963.      (*note Hooks::.).  The function we supply is a list starting with
  964.      `lambda', with a single-quote in front of it to make it a list
  965.      constant rather than an expression.
  966.  
  967.      It's beyond the scope of this manual to explain Lisp functions,
  968.      but for this example it is enough to know that the effect is to
  969.      execute `(auto-fill-mode 1)' when Text mode is entered.  You can
  970.      replace it with any other expression that you like, or with
  971.      several expressions in a row.
  972.  
  973.      Emacs comes with a function named `turn-on-auto-fill' whose
  974.      definition is `(lambda () (auto-fill-mode 1))'.  Thus, a simpler
  975.      way to write the above example is as follows:
  976.  
  977.           (add-hook 'text-mode-hook 'turn-on-auto-fill)
  978.  
  979.    * Load the installed Lisp library named `foo' (actually a file
  980.      `foo.elc' or `foo.el' in a standard Emacs directory).
  981.  
  982.           (load "foo")
  983.  
  984.      When the argument to `load' is a relative file name, not starting
  985.      with `/' or `~', `load' searches the directories in `load-path'
  986.      (*note Lisp Libraries::.).
  987.  
  988.    * Load the compiled Lisp file `foo.elc' from your home directory.
  989.  
  990.           (load "~/foo.elc")
  991.  
  992.      Here an absolute file name is used, so no searching is done.
  993.  
  994.    * Rebind the key `C-x l' to run the function `make-symbolic-link'.
  995.  
  996.           (global-set-key "\C-xl" 'make-symbolic-link)
  997.  
  998.      or
  999.  
  1000.           (define-key global-map "\C-xl" 'make-symbolic-link)
  1001.  
  1002.      Note once again the single-quote used to refer to the symbol
  1003.      `make-symbolic-link' instead of its value as a variable.
  1004.  
  1005.    * Do the same thing for C mode only.
  1006.  
  1007.           (define-key c-mode-map "\C-xl" 'make-symbolic-link)
  1008.  
  1009.    * Redefine all keys which now run `next-line' in Fundamental mode so
  1010.      that they run `forward-line' instead.
  1011.  
  1012.           (substitute-key-definition 'next-line 'forward-line
  1013.                                      global-map)
  1014.  
  1015.    * Make `C-x C-v' undefined.
  1016.  
  1017.           (global-unset-key "\C-x\C-v")
  1018.  
  1019.      One reason to undefine a key is so that you can make it a prefix.
  1020.      Simply defining `C-x C-v ANYTHING' will make `C-x C-v' a prefix,
  1021.      but `C-x C-v' must first be freed of its usual non-prefix
  1022.      definition.
  1023.  
  1024.    * Make `$' have the syntax of punctuation in Text mode.  Note the
  1025.      use of a character constant for `$'.
  1026.  
  1027.           (modify-syntax-entry ?\$ "." text-mode-syntax-table)
  1028.  
  1029.    * Enable the use of the command `eval-expression' without
  1030.      confirmation.
  1031.  
  1032.           (put 'eval-expression 'disabled nil)
  1033.  
  1034. 
  1035. File: emacs,  Node: Terminal Init,  Next: Find Init,  Prev: Init Examples,  Up: Init File
  1036.  
  1037. Terminal-specific Initialization
  1038. --------------------------------
  1039.  
  1040.    Each terminal type can have a Lisp library to be loaded into Emacs
  1041. when it is run on that type of terminal.  For a terminal type named
  1042. TERMTYPE, the library is called `term/TERMTYPE' and it is found by
  1043. searching the directories `load-path' as usual and trying the suffixes
  1044. `.elc' and `.el'.  Normally it appears in the subdirectory `term' of
  1045. the directory where most Emacs libraries are kept.
  1046.  
  1047.    The usual purpose of the terminal-specific library is to define the
  1048. escape sequences used by the terminal's function keys using the library
  1049. `keypad.el'.  See the file `term/vt100.el' for an example of how this
  1050. is done.
  1051.  
  1052.    When the terminal type contains a hyphen, only the part of the name
  1053. before the first hyphen is significant in choosing the library name.
  1054. Thus, terminal types `aaa-48' and `aaa-30-rv' both use the library
  1055. `term/aaa'.  The code in the library can use `(getenv "TERM")' to find
  1056. the full terminal type name.
  1057.  
  1058.    The library's name is constructed by concatenating the value of the
  1059. variable `term-file-prefix' and the terminal type.  Your `.emacs' file
  1060. can prevent the loading of the terminal-specific library by setting
  1061. `term-file-prefix' to `nil'.
  1062.  
  1063.    Emacs runs the hook `term-setup-hook' at the end of initialization,
  1064. after both your `.emacs' file and any terminal-specific library have
  1065. been read in.  Add hook functions to this hook if you wish to override
  1066. part of any of the terminal-specific libraries and to define
  1067. initializations for terminals that do not have a library.  *Note
  1068. Hooks::.
  1069.  
  1070. 
  1071. File: emacs,  Node: Find Init,  Prev: Terminal Init,  Up: Init File
  1072.  
  1073. How Emacs Finds Your Init File
  1074. ------------------------------
  1075.  
  1076.    Normally Emacs uses the environment variable `HOME' to find
  1077. `.emacs'; that's what `~' means in a file name.  But if you have done
  1078. `su', Emacs tries to find your own `.emacs', not that of the user you
  1079. are currently pretending to be.  The idea is that you should get your
  1080. own editor customizations even if you are running as the super user.
  1081.  
  1082.    More precisely, Emacs first determines which user's init file to use.
  1083. It gets the user name from the environment variables `USER' and
  1084. `LOGNAME'; if neither of those exists, it uses effective user-ID.  If
  1085. that user name matches the real user-ID, then Emacs uses `HOME';
  1086. otherwise, it looks up the home directory corresponding to that user
  1087. name in the system's data base of users.
  1088.  
  1089. 
  1090. File: emacs,  Node: Quitting,  Next: Lossage,  Prev: Customization,  Up: Top
  1091.  
  1092. Quitting and Aborting
  1093. =====================
  1094.  
  1095. `C-g'
  1096.      Quit.  Cancel running or partially typed command.
  1097.  
  1098. `C-]'
  1099.      Abort innermost recursive editing level and cancel the command
  1100.      which invoked it (`abort-recursive-edit').
  1101.  
  1102. `M-x top-level'
  1103.      Abort all recursive editing levels that are currently executing.
  1104.  
  1105. `C-x u'
  1106.      Cancel an already-executed command, usually (`undo').
  1107.  
  1108.    There are two ways of cancelling commands which are not finished
  1109. executing: "quitting" with `C-g', and "aborting" with `C-]' or `M-x
  1110. top-level'.  Quitting cancels a partially typed command or one which is
  1111. already running.  Aborting exits a recursive editing level and cancels
  1112. the command that invoked the recursive edit.  (*Note Recursive Edit::.)
  1113.  
  1114.    Quitting with `C-g' is used for getting rid of a partially typed
  1115. command, or a numeric argument that you don't want.  It also stops a
  1116. running command in the middle in a relatively safe way, so you can use
  1117. it if you accidentally give a command which takes a long time.  In
  1118. particular, it is safe to quit out of killing; either your text will
  1119. *all* still be in the buffer, or it will *all* be in the kill ring (or
  1120. maybe both).  Quitting an incremental search does special things
  1121. documented under searching; in general, it may take two successive
  1122. `C-g' characters to get out of a search.
  1123.  
  1124.    `C-g' works by setting the variable `quit-flag' to `t' the instant
  1125. `C-g' is typed; Emacs Lisp checks this variable frequently and quits if
  1126. it is non-`nil'.  `C-g' is only actually executed as a command if you
  1127. type it while Emacs is waiting for input.
  1128.  
  1129.    If you quit with `C-g' a second time before the first `C-g' is
  1130. recognized, you activate the "emergency escape" feature and return to
  1131. the shell.  *Note Emergency Escape::.
  1132.  
  1133.    There may be times when you cannot quit.  When Emacs is waiting for
  1134. the operating system to do something, quitting is impossible unless
  1135. special pains are taken for the particular system call within Emacs
  1136. where the waiting occurs.  We have done this for the system calls that
  1137. users are likely to want to quit from, but it's possible you will find
  1138. another.  In one very common case--waiting for file input or output
  1139. using NFS--Emacs itself knows how to quit, but most NFS implementations
  1140. simply do not allow user programs to stop waiting for NFS when the NFS
  1141. server is hung.
  1142.  
  1143.    Aborting with `C-]' (`abort-recursive-edit') is used to get out of a
  1144. recursive editing level and cancel the command which invoked it.
  1145. Quitting with `C-g' does not do this, and could not do this, because it
  1146. is used to cancel a partially typed command *within* the recursive
  1147. editing level.  Both operations are useful.  For example, if you are in
  1148. a recursive edit and type `C-u 8' to enter a numeric argument, you can
  1149. cancel that argument with `C-g' and remain in the recursive edit.
  1150.  
  1151.    The command `M-x top-level' is equivalent to "enough" `C-]' commands
  1152. to get you out of all the levels of recursive edits that you are in.
  1153. `C-]' gets you out one level at a time, but `M-x top-level' goes out
  1154. all levels at once.  Both `C-]' and `M-x top-level' are like all other
  1155. commands, and unlike `C-g', in that they are effective only when Emacs
  1156. is ready for a command.  `C-]' is an ordinary key and has its meaning
  1157. only because of its binding in the keymap.  *Note Recursive Edit::.
  1158.  
  1159.    `C-x u' (`undo') is not strictly speaking a way of cancelling a
  1160. command, but you can think of it as cancelling a command already
  1161. finished executing.  *Note Undo::.
  1162.  
  1163.