home *** CD-ROM | disk | FTP | other *** search
/ Dr. CD ROM (Annual Premium Edition) / premium.zip / premium / IBMOS2_1 / E17INFO.ZIP / emacs / 19.17 / info / emacs-16 (.txt) < prev    next >
GNU Info File  |  1993-07-18  |  50KB  |  867 lines

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