home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / elisp / elisp-14 < prev    next >
Encoding:
GNU Info File  |  1993-05-31  |  49.5 KB  |  1,195 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.  
  4.    This is edition 2.0 of the GNU Emacs Lisp Reference Manual, for
  5. Emacs Version 19.
  6.  
  7.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  8. Cambridge, MA 02139 USA
  9.  
  10.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that this permission notice may be stated in a
  24. translation approved by the Foundation.
  25.  
  26. 
  27. File: elisp,  Node: Classifying Events,  Next: Accessing Events,  Prev: Event Examples,  Up: Input Events
  28.  
  29. Classifying Events
  30. ------------------
  31.  
  32.    Every event has an "event type" which classifies the event for key
  33. binding purposes.  For a keyboard event, the event type equals the event
  34. value; thus, the event type for a character is the character, and the
  35. event type for a function key symbol is the symbol itself.  For events
  36. which are lists, the event type is the symbol in the CAR of the list.
  37. Thus, the event type is always a symbol or a character.
  38.  
  39.    Two events of the same type are equivalent where key bindings are
  40. concerned; thus, they always run the same command.  That does not
  41. necessarily mean they do the same things, however, as some commands look
  42. at the whole event to decide what to do.  For example, some commands use
  43. the location of a mouse event to decide what text to act on.
  44.  
  45.    Sometimes broader classifications of events are useful.  For example,
  46. you might want to ask whether an event involved the META key,
  47. regardless of which other key or mouse button was used.
  48.  
  49.    To get such information conveniently, call the functions
  50. `event-modifiers' and `event-basic-type'.
  51.  
  52.  - Function: event-modifiers EVENT
  53.      This function returns a list of the modifiers that EVENT has.  The
  54.      modifiers are symbols; they include `shift', `control', `meta',
  55.      `alt', `hyper' and `super'.  In addition, the property of a mouse
  56.      event symbol always has one of `click', `drag', and `down' among
  57.      the modifiers.  For example:
  58.  
  59.           (event-modifiers ?a)
  60.                => nil
  61.           (event-modifiers ?\C-a)
  62.                => (control)
  63.           (event-modifiers ?\C-%)
  64.                => (control)
  65.           (event-modifiers ?\C-\S-a)
  66.                => (control shift)
  67.           (event-modifiers 'f5)
  68.                => nil
  69.           (event-modifiers 's-f5)
  70.                => (super)
  71.           (event-modifiers 'M-S-f5)
  72.                => (meta shift)
  73.           (event-modifiers 'mouse-1)
  74.                => (click)
  75.           (event-modifiers 'down-mouse-1)
  76.                => (down)
  77.  
  78.      The modifiers list for a click event explicitly contains `click',
  79.      but the event symbol name itself does not contain `click'.
  80.  
  81.  - Function: event-basic-type EVENT
  82.      This function returns the key or mouse button that EVENT
  83.      describes, with all modifiers removed.  For example:
  84.  
  85.           (event-basic-type ?a)
  86.                => 97
  87.           (event-basic-type ?A)
  88.                => 97
  89.           (event-basic-type ?\C-a)
  90.                => 97
  91.           (event-basic-type ?\C-\S-a)
  92.                => 97
  93.           (event-basic-type 'f5)
  94.                => f5
  95.           (event-basic-type 's-f5)
  96.                => f5
  97.           (event-basic-type 'M-S-f5)
  98.                => f5
  99.           (event-basic-type 'down-mouse-1)
  100.                => mouse-1
  101.  
  102.  - Function: mouse-movement-p OBJECT
  103.      This function returns non-`nil' if OBJECT is a mouse movement
  104.      event.
  105.  
  106. 
  107. File: elisp,  Node: Accessing Events,  Next: Strings of Events,  Prev: Classifying Events,  Up: Input Events
  108.  
  109. Accessing Events
  110. ----------------
  111.  
  112.    This section describes convenient functions for accessing the data in
  113. an event which is a list.
  114.  
  115.    The following functions return the starting or ending position of a
  116. mouse-button event.  The position is a list of this form:
  117.  
  118.      (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP)
  119.  
  120.  - Function: event-start EVENT
  121.      This returns the starting position of EVENT.
  122.  
  123.      If EVENT is a click or button-down event, this returns the
  124.      location of the event.  If EVENT is a drag event, this returns the
  125.      drag's starting position.
  126.  
  127.  - Function: event-end EVENT
  128.      This returns the ending position of EVENT.
  129.  
  130.      If EVENT is a drag event, this returns the position where the user
  131.      released the mouse button.  If EVENT is a click or button-down
  132.      event, the value is actually the starting position, which is the
  133.      only position such events have.
  134.  
  135.    These four functions take a position-list as described above, and
  136. return various parts of it.
  137.  
  138.  - Function: posn-window POSITION
  139.      Return the window that POSITION is in.
  140.  
  141.  - Function: posn-point POSITION
  142.      Return the buffer location in POSITION.
  143.  
  144.  - Function: posn-col-row POSITION
  145.      Return the row and column in POSITION, as a list `(COL . ROW)'.
  146.  
  147.  - Function: posn-timestamp POSITION
  148.      Return the timestamp of POSITION.
  149.  
  150.  - Function: scroll-bar-scale RATIO TOTAL
  151.      This function multiples (in effect) RATIO by TOTAL, rounding the
  152.      result to an integer.  RATIO is not a number, but rather  a pair
  153.      `(NUM . DENOM)'.
  154.  
  155.      This is handy for scaling a position on a scroll bar into a buffer
  156.      position.  Here's how to do that:
  157.  
  158.           (scroll-bar-scale (posn-col-row (event-start event))
  159.                             (buffer-size))
  160.  
  161. 
  162. File: elisp,  Node: Strings of Events,  Prev: Accessing Events,  Up: Input Events
  163.  
  164. Putting Keyboard Events in Strings
  165. ----------------------------------
  166.  
  167.    In most of the places where strings are used, we conceptualize the
  168. string as containing text characters--the same kind of characters found
  169. in buffers or files.  Occasionally Lisp programs use strings which
  170. conceptually contain keyboard characters; for example, they may be key
  171. sequences or keyboard macro definitions.  There are special rules for
  172. how to put keyboard characters into a string, because they are not
  173. limited to the range of 0 to 255 as text characters are.
  174.  
  175.    A keyboard character typed using the META key is called a "meta
  176. character".  The numeric code for such an event includes the 2**23 bit;
  177. it does not even come close to fitting in a string.  However, earlier
  178. Emacs versions used a different representation for these characters,
  179. which gave them codes in the range of 128 to 255.  That did fit in a
  180. string, and many Lisp programs contain string constants that use `\M-'
  181. to express meta characters, especially as the argument to `define-key'
  182. and similar functions.
  183.  
  184.    We provide backward compatibility to run those programs with special
  185. rules for how to put a keyboard character event in a string.  Here are
  186. the rules:
  187.  
  188.    * If the keyboard event value is in the range of 0 to 127, it can go
  189.      in the string unchanged.
  190.  
  191.    * The meta variants of those events, with codes in the range of
  192.      2**23 to 2**23+127, can also go in the string, but you must change
  193.      their numeric values.  You must set the 2**7 bit instead of the
  194.      2**23 bit, resulting in a value between 128 and 255.
  195.  
  196.    * Other keyboard character events cannot fit in a string.  This
  197.      includes keyboard events in the range of 128 to 255.
  198.  
  199.    Functions such as `read-key-sequence' that can construct strings
  200. containing events follow these rules.
  201.  
  202.    When you use the read syntax `\M-' in a string, it produces a code
  203. in the range of 128 to 255--the same code that you get if you modify
  204. the corresponding keyboard event to put it in the string.  Thus, meta
  205. events in strings work consistently regardless of how they get into the
  206. strings.
  207.  
  208.    New programs can avoid dealing with these rules by using vectors
  209. instead of strings for key sequences when there is any possibility that
  210. these issues might arise.
  211.  
  212.    The reason we changed the representation of meta characters as
  213. keyboard events is to make room for basic character codes beyond 127,
  214. and support meta variants of such larger character codes.
  215.  
  216. 
  217. File: elisp,  Node: Reading Input,  Next: Waiting,  Prev: Input Events,  Up: Command Loop
  218.  
  219. Reading Input
  220. =============
  221.  
  222.    The editor command loop reads keyboard input using the function
  223. `read-key-sequence', which uses `read-event'.  These and other
  224. functions for keyboard input are also available for use in Lisp
  225. programs.  See also `momentary-string-display' in *Note Temporary
  226. Displays::, and `sit-for' in *Note Waiting::.  *Note Terminal Input::,
  227. for functions and variables for controlling terminal input modes and
  228. debugging terminal input.
  229.  
  230.    For higher-level input facilities, see *Note Minibuffers::.
  231.  
  232. * Menu:
  233.  
  234. * Key Sequence Input::        How to read one key sequence.
  235. * Reading One Event::        How to read just one event.
  236. * Quoted Character Input::    Asking the user to specify a character.
  237. * Peeking and Discarding::    How to reread or throw away input events.
  238.  
  239. 
  240. File: elisp,  Node: Key Sequence Input,  Next: Reading One Event,  Up: Reading Input
  241.  
  242. Key Sequence Input
  243. ------------------
  244.  
  245.    The command loop reads input a key sequence at a time, by calling
  246. `read-key-sequence'.  Lisp programs can also call this function; for
  247. example, `describe-key' uses it to read the key to describe.
  248.  
  249.  - Function: read-key-sequence PROMPT
  250.      This function reads a key sequence and returns it as a string or
  251.      vector.  It keeps reading events until it has accumulated a full
  252.      key sequence; that is, enough to specify a non-prefix command
  253.      using the currently active keymaps.
  254.  
  255.      If the events are all characters and all can fit in a string, then
  256.      `read-key-sequence' returns a string (*note Strings of Events::.).
  257.      Otherwise, it returns a vector, since a vector can hold all kinds
  258.      of events--characters, symbols, and lists.  The elements of the
  259.      string or vector are the events in the key sequence.
  260.  
  261.      Quitting is suppressed inside `read-key-sequence'.  In other words,
  262.      a `C-g' typed while reading with this function is treated like any
  263.      other character, and does not set `quit-flag'.  *Note Quitting::.
  264.  
  265.      The argument PROMPT is either a string to be displayed in the echo
  266.      area as a prompt, or `nil', meaning not to display a prompt.
  267.  
  268.      In the example below, the prompt `?' is displayed in the echo area,
  269.      and the user types `C-x C-f'.
  270.  
  271.           (read-key-sequence "?")
  272.           
  273.           ---------- Echo Area ----------
  274.           ?`C-x C-f'
  275.           ---------- Echo Area ----------
  276.           
  277.                => "^X^F"
  278.  
  279.  - Variable: num-input-keys
  280.      This variable's value is the number of key sequences processed so
  281.      far in this Emacs session.  This includes key sequences read from
  282.      the terminal and key sequences read from keyboard macros being
  283.      executed.
  284.  
  285.    If an input character is an upper case letter and has no key binding,
  286. but the lower case equivalent has one, then `read-key-sequence'
  287. converts the character to lower case.  Note that `lookup-key' does not
  288. perform case conversion in this way.
  289.  
  290.    The function `read-key-sequence' also transforms some mouse events.
  291. It converts unbound drag events into click events, and discards unbound
  292. button-down events entirely.  It also reshuffles focus events so that
  293. they never appear in a key sequence with any other events.
  294.  
  295.    When mouse events occur in special parts of a window, such as a mode
  296. line or a scroll bar, the event itself shows nothing special--only the
  297. symbol that would normally represent that mouse button and modifier
  298. keys.  The information about the screen region is kept elsewhere in the
  299. event--in the coordinates.  But `read-key-sequence' translates this
  300. information into imaginary prefix keys, all of which are symbols:
  301. `mode-line', `vertical-line', `horizontal-scroll-bar' and
  302. `vertical-scroll-bar'.
  303.  
  304.    For example, if you call `read-key-sequence' and then click the
  305. mouse on the window's mode line, this is what happens:
  306.  
  307.      (read-key-sequence "Click on the mode line: ")
  308.           => [mode-line
  309.                (mouse-1
  310.                 (#<window 6 on NEWS> mode-line
  311.                  (40 . 63) 5959987))]
  312.  
  313.    You can define meanings for mouse clicks in special window regions by
  314. defining key sequences using these imaginary prefix keys.
  315.  
  316. 
  317. File: elisp,  Node: Reading One Event,  Next: Quoted Character Input,  Prev: Key Sequence Input,  Up: Reading Input
  318.  
  319. Reading One Event
  320. -----------------
  321.  
  322.    The lowest level functions for command input are those which read a
  323. single event.
  324.  
  325.  - Function: read-event
  326.      This function reads and returns the next event of command input,
  327.      waiting if necessary until an event is available.  Events can come
  328.      directly from the user or from a keyboard macro.
  329.  
  330.      The function `read-event' does not display any message to indicate
  331.      it is waiting for input; use `message' first, if you wish to
  332.      display one.  If you have not displayed a message, `read-event'
  333.      does "prompting": it displays descriptions of the events that led
  334.      to or were read by the current command.  *Note The Echo Area::.
  335.  
  336.      If `cursor-in-echo-area' is non-`nil', then `read-event' moves the
  337.      cursor temporarily to the echo area, to the end of any message
  338.      displayed there.  Otherwise `read-event' does not move the cursor.
  339.  
  340.    Here is what happens if you call `read-event' and then press the
  341. right-arrow function key:
  342.  
  343.      (read-event)
  344.           => right
  345.  
  346.  - Function: read-char
  347.      This function reads and returns a character of command input.  It
  348.      discards any events that are not characters until it gets a
  349.      character.
  350.  
  351.      In the first example, the user types `1' (which is ASCII code 49).
  352.      The second example shows a keyboard macro definition that calls
  353.      `read-char' from the minibuffer.  `read-char' reads the keyboard
  354.      macro's very next character, which is `1'.  The value of this
  355.      function is displayed in the echo area by the command
  356.      `eval-expression'.
  357.  
  358.           (read-char)
  359.                => 49
  360.           
  361.           (symbol-function 'foo)
  362.                => "^[^[(read-char)^M1"
  363.           (execute-kbd-macro foo)
  364.                -| 49
  365.                => nil
  366.  
  367. 
  368. File: elisp,  Node: Quoted Character Input,  Next: Peeking and Discarding,  Prev: Reading One Event,  Up: Reading Input
  369.  
  370. Quoted Character Input
  371. ----------------------
  372.  
  373.    You can use the function `read-quoted-char' when you want the user
  374. to specify a character, and allow the user to specify a control or meta
  375. character conveniently with quoting or as an octal character code.  The
  376. command `quoted-insert' calls this function.
  377.  
  378.  - Function: read-quoted-char &optional PROMPT
  379.      This function is like `read-char', except that if the first
  380.      character read is an octal digit (0-7), it reads up to two more
  381.      octal digits (but stopping if a non-octal digit is found) and
  382.      returns the character represented by those digits as an octal
  383.      number.
  384.  
  385.      Quitting is suppressed when the first character is read, so that
  386.      the user can enter a `C-g'.  *Note Quitting::.
  387.  
  388.      If PROMPT is supplied, it specifies a string for prompting the
  389.      user.  The prompt string is always printed in the echo area and
  390.      followed by a single `-'.
  391.  
  392.      In the following example, the user types in the octal number 177
  393.      (which is 127 in decimal).
  394.  
  395.           (read-quoted-char "What character")
  396.           
  397.           ---------- Echo Area ----------
  398.           What character-`177'
  399.           ---------- Echo Area ----------
  400.           
  401.                => 127
  402.  
  403. 
  404. File: elisp,  Node: Peeking and Discarding,  Prev: Quoted Character Input,  Up: Reading Input
  405.  
  406. Peeking and Discarding
  407. ----------------------
  408.  
  409.  - Variable: unread-command-events
  410.      This variable holds a list of events waiting to be read as command
  411.      input.  The events are used in the order they appear in the list.
  412.  
  413.      The variable is used because in some cases a function reads a
  414.      event and then decides not to use it.  Storing the event in this
  415.      variable causes it to be processed normally by the command loop or
  416.      when the functions to read command input are called.
  417.  
  418.      For example, the function that implements numeric prefix arguments
  419.      reads any number of digits.  When it finds a non-digit event, it
  420.      must unread the event so that it can be read normally by the
  421.      command loop.  Likewise, incremental search uses this feature to
  422.      unread events it does not recognize.
  423.  
  424.  - Variable: unread-command-char
  425.      This variable holds a character to be read as command input.  A
  426.      value of -1 means "empty".
  427.  
  428.      This variable is pretty much obsolete now that you can use
  429.      `unread-command-events' instead; it exists only to support programs
  430.      written for Emacs versions 18 and earlier.
  431.  
  432.  - Function: listify-key-sequence KEY
  433.      This function converts the string or vector KEY to a list of
  434.      events which you can put in `unread-command-events'.  Converting a
  435.      vector is simple, but converting a string is tricky because of the
  436.      special representation used for meta characters in a string (*note
  437.      Strings of Events::.).
  438.  
  439.  - Function: input-pending-p
  440.      This function determines whether any command input is currently
  441.      available to be read.  It returns immediately, with value `t' if
  442.      there is input, `nil' otherwise.  On rare occasions it may return
  443.      `t' when no input is available.
  444.  
  445.  - Variable: last-input-event
  446.  - Variable: last-input-char
  447.      This variable records the last terminal input event read, whether
  448.      as part of a command or explicitly by a Lisp program.
  449.  
  450.      In the example below, a character is read (the character `1',
  451.      ASCII code 49).  It becomes the value of `last-input-char', while
  452.      `C-e' (from the `C-x C-e' command used to evaluate this
  453.      expression) remains the value of `last-command-char'.
  454.  
  455.           (progn (print (read-char))
  456.                  (print last-command-char)
  457.                  last-input-char)
  458.                -| 49
  459.                -| 5
  460.                => 49
  461.  
  462.      The alias `last-input-char' exists for compatibility with Emacs
  463.      version 18.
  464.  
  465.  - Function: discard-input
  466.      This function discards the contents of the terminal input buffer
  467.      and cancels any keyboard macro that might be in the process of
  468.      definition.  It returns `nil'.
  469.  
  470.      In the following example, the user may type a number of characters
  471.      right after starting the evaluation of the form.  After the
  472.      `sleep-for' finishes sleeping, any characters that have been typed
  473.      are discarded.
  474.  
  475.           (progn (sleep-for 2)
  476.             (discard-input))
  477.                => nil
  478.  
  479. 
  480. File: elisp,  Node: Waiting,  Next: Quitting,  Prev: Reading Input,  Up: Command Loop
  481.  
  482. Waiting for Elapsed Time or Input
  483. =================================
  484.  
  485.    The waiting commands are designed to make Emacs wait for a certain
  486. amount of time to pass or until there is input.  For example, you may
  487. wish to pause in the middle of a computation to allow the user time to
  488. view the display.  `sit-for' pauses and updates the screen, and returns
  489. immediately if input comes in, while `sleep-for' pauses without
  490. updating the screen.
  491.  
  492.  - Function: sit-for SECONDS &optional MILLISEC NODISP
  493.      This function performs redisplay (provided there is no pending
  494.      input from the user), then waits SECONDS seconds, or until input is
  495.      available.  The result is `t' if `sit-for' waited the full time
  496.      with no input arriving (see `input-pending-p' in *Note Peeking and
  497.      Discarding::).  Otherwise, the value is `nil'.
  498.  
  499.      The optional argument MILLISEC specifies an additional waiting
  500.      period measured in milliseconds.  This adds to the period
  501.      specified by SECONDS.  Not all operating systems support waiting
  502.      periods other than multiples of a second; on those that do not,
  503.      you get an error if you specify nonzero MILLISEC.
  504.  
  505.      Redisplay is always preempted if input arrives, and does not
  506.      happen at all if input is available before it starts.  Thus, there
  507.      is no way to force screen updating if there is pending input;
  508.      however, if there is no input pending, you can force an update
  509.      with no delay by using `(sit-for 0)'.
  510.  
  511.      If NODISP is non-`nil', then `sit-for' does not redisplay, but it
  512.      still returns as soon as input is available (or when the timeout
  513.      elapses).
  514.  
  515.      The usual purpose of `sit-for' is to give the user time to read
  516.      text that you display.
  517.  
  518.  - Function: sleep-for SECONDS &optional MILLISEC
  519.      This function simply pauses for SECONDS seconds without updating
  520.      the display.  It pays no attention to available input.  It returns
  521.      `nil'.
  522.  
  523.      The optional argument MILLISEC specifies an additional waiting
  524.      period measured in milliseconds.  This adds to the period
  525.      specified by SECONDS.  Not all operating systems support waiting
  526.      periods other than multiples of a second; on those that do not,
  527.      you get an error if you specify nonzero MILLISEC.
  528.  
  529.      Use `sleep-for' when you wish to guarantee a delay.
  530.  
  531.    *Note Time of Day::, for functions to get the current time.
  532.  
  533. 
  534. File: elisp,  Node: Quitting,  Next: Prefix Command Arguments,  Prev: Waiting,  Up: Command Loop
  535.  
  536. Quitting
  537. ========
  538.  
  539.    Typing `C-g' while the command loop has run a Lisp function causes
  540. Emacs to "quit" whatever it is doing.  This means that control returns
  541. to the innermost active command loop.
  542.  
  543.    Typing `C-g' while the command loop is waiting for keyboard input
  544. does not cause a quit; it acts as an ordinary input character.  In the
  545. simplest case, you cannot tell the difference, because `C-g' normally
  546. runs the command `keyboard-quit', whose effect is to quit.  However,
  547. when `C-g' follows a prefix key, the result is an undefined key.  The
  548. effect is to cancel the prefix key as well as any prefix argument.
  549.  
  550.    In the minibuffer, `C-g' has a different definition: it aborts out
  551. of the minibuffer.  This means, in effect, that it exits the minibuffer
  552. and then quits.  (Simply quitting would return to the command loop
  553. *within* the minibuffer.)  The reason why `C-g' does not quit directly
  554. when the command reader is reading input is so that its meaning can be
  555. redefined in the minibuffer in this way.  `C-g' following a prefix key
  556. is not redefined in the minibuffer, and it has its normal effect of
  557. canceling the prefix key and prefix argument.  This too would not be
  558. possible if `C-g' quit directly.
  559.  
  560.    `C-g' causes a quit by setting the variable `quit-flag' to a
  561. non-`nil' value.  Emacs checks this variable at appropriate times and
  562. quits if it is not `nil'.  Setting `quit-flag' non-`nil' in any way
  563. thus causes a quit.
  564.  
  565.    At the level of C code, quits cannot happen just anywhere; only at
  566. the special places which check `quit-flag'.  The reason for this is
  567. that quitting at other places might leave an inconsistency in Emacs's
  568. internal state.  Because quitting is delayed until a safe place,
  569. quitting cannot make Emacs crash.
  570.  
  571.    Certain functions such as `read-key-sequence' or `read-quoted-char'
  572. prevent quitting entirely even though they wait for input.  Instead of
  573. quitting, `C-g' serves as the requested input.  In the case of
  574. `read-key-sequence', this serves to bring about the special behavior of
  575. `C-g' in the command loop.  In the case of `read-quoted-char', this is
  576. so that `C-q' can be used to quote a `C-g'.
  577.  
  578.    You can prevent quitting for a portion of a Lisp function by binding
  579. the variable `inhibit-quit' to a non-`nil' value.  Then, although `C-g'
  580. still sets `quit-flag' to `t' as usual, the usual result of this--a
  581. quit--is prevented.  Eventually, `inhibit-quit' will become `nil'
  582. again, such as when its binding is unwound at the end of a `let' form.
  583. At that time, if `quit-flag' is still non-`nil', the requested quit
  584. happens immediately.  This behavior is ideal for a "critical section",
  585. where you wish to make sure that quitting does not happen within that
  586. part of the program.
  587.  
  588.    In some functions (such as `read-quoted-char'), `C-g' is handled in
  589. a special way which does not involve quitting.  This is done by reading
  590. the input with `inhibit-quit' bound to `t' and setting `quit-flag' to
  591. `nil' before `inhibit-quit' becomes `nil' again.  This excerpt from the
  592. definition of `read-quoted-char' shows how this is done; it also shows
  593. that normal quitting is permitted after the first character of input.
  594.  
  595.      (defun read-quoted-char (&optional prompt)
  596.        "...DOCUMENTATION..."
  597.        (let ((count 0) (code 0) char)
  598.          (while (< count 3)
  599.            (let ((inhibit-quit (zerop count))
  600.                  (help-form nil))
  601.              (and prompt (message "%s-" prompt))
  602.              (setq char (read-char))
  603.              (if inhibit-quit (setq quit-flag nil)))
  604.            ...)
  605.          (logand 255 code)))
  606.  
  607.  - Variable: quit-flag
  608.      If this variable is non-`nil', then Emacs quits immediately,
  609.      unless `inhibit-quit' is non-`nil'.  Typing `C-g' sets `quit-flag'
  610.      non-`nil', regardless of `inhibit-quit'.
  611.  
  612.  - Variable: inhibit-quit
  613.      This variable determines whether Emacs should quit when `quit-flag'
  614.      is set to a value other than `nil'.  If `inhibit-quit' is
  615.      non-`nil', then `quit-flag' has no special effect.
  616.  
  617.  - Command: keyboard-quit
  618.      This function signals the `quit' condition with `(signal 'quit
  619.      nil)'.  This is the same thing that quitting does.  (See `signal'
  620.      in *Note Errors::.)
  621.  
  622.    You can specify a character other than `C-g' to use for quitting.
  623. See the function `set-input-mode' in *Note Terminal Input::.
  624.  
  625. 
  626. File: elisp,  Node: Prefix Command Arguments,  Next: Recursive Editing,  Prev: Quitting,  Up: Command Loop
  627.  
  628. Prefix Command Arguments
  629. ========================
  630.  
  631.    Most Emacs commands can use a "prefix argument", a number specified
  632. before the command itself.  (Don't confuse prefix arguments with prefix
  633. keys.)  The prefix argument is represented by a value that is always
  634. available (though it may be `nil', meaning there is no prefix
  635. argument).  Each command may use the prefix argument or ignore it.
  636.  
  637.    There are two representations of the prefix argument: "raw" and
  638. "numeric".  The editor command loop uses the raw representation
  639. internally, and so do the Lisp variables that store the information, but
  640. commands can request either representation.
  641.  
  642.    Here are the possible values of a raw prefix argument:
  643.  
  644.    * `nil', meaning there is no prefix argument.  Its numeric value is
  645.      1, but numerous commands make a distinction between `nil' and the
  646.      integer 1.
  647.  
  648.    * An integer, which stands for itself.
  649.  
  650.    * A list of one element, which is an integer.  This form of prefix
  651.      argument results from one or a succession of `C-u''s with no
  652.      digits.  The numeric value is the integer in the list, but some
  653.      commands make a distinction between such a list and an integer
  654.      alone.
  655.  
  656.    * The symbol `-'.  This indicates that `M--' or `C-u -' was typed,
  657.      without following digits.  The equivalent numeric value is -1, but
  658.      some commands make a distinction between the integer -1 and the
  659.      symbol `-'.
  660.  
  661.    The various possibilities may be illustrated by calling the following
  662. function with various prefixes:
  663.  
  664.      (defun display-prefix (arg)
  665.        "Display the value of the raw prefix arg."
  666.        (interactive "P")
  667.        (message "%s" arg))
  668.  
  669. Here are the results of calling `print-prefix' with various raw prefix
  670. arguments:
  671.  
  672.              M-x print-prefix  -| nil
  673.      
  674.      C-u     M-x print-prefix  -| (4)
  675.      
  676.      C-u C-u M-x print-prefix  -| (16)
  677.      
  678.      C-u 3   M-x print-prefix  -| 3
  679.      
  680.      M-3     M-x print-prefix  -| 3      ; (Same as `C-u 3'.)
  681.      
  682.      C-u -   M-x print-prefix  -| -
  683.      
  684.      M- -    M-x print-prefix  -| -      ; (Same as `C-u -'.)
  685.      
  686.      C-u -7  M-x print-prefix  -| -7
  687.      
  688.      M- -7   M-x print-prefix  -| -7     ; (Same as `C-u -7'.)
  689.  
  690.    Emacs uses two variables to store the prefix argument: `prefix-arg'
  691. and `current-prefix-arg'.  Commands such as `universal-argument' that
  692. set up prefix arguments for other commands store them in `prefix-arg'.
  693. In contrast, `current-prefix-arg' conveys the prefix argument to the
  694. current command, so setting it has no effect on the prefix arguments
  695. for future commands.
  696.  
  697.    Normally, commands specify which representation to use for the prefix
  698. argument, either numeric or raw, in the `interactive' declaration.
  699. (*Note Interactive Call::.)  Alternatively, functions may look at the
  700. value of the prefix argument directly in the variable
  701. `current-prefix-arg', but this is less clean.
  702.  
  703.    Do not call the functions `universal-argument', `digit-argument', or
  704. `negative-argument' unless you intend to let the user enter the prefix
  705. argument for the *next* command.
  706.  
  707.  - Command: universal-argument
  708.      This command reads input and specifies a prefix argument for the
  709.      following command.  Don't call this command yourself unless you
  710.      know what you are doing.
  711.  
  712.  - Command: digit-argument ARG
  713.      This command adds to the prefix argument for the following
  714.      command.  The argument ARG is the raw prefix argument as it was
  715.      before this command; it is used to compute the updated prefix
  716.      argument.  Don't call this command yourself unless you know what
  717.      you are doing.
  718.  
  719.  - Command: negative-argument ARG
  720.      This command adds to the numeric argument for the next command.
  721.      The argument ARG is the raw prefix argument as it was before this
  722.      command; its value is negated to form the new prefix argument.
  723.      Don't call this command yourself unless you know what you are
  724.      doing.
  725.  
  726.  - Function: prefix-numeric-value ARG
  727.      This function returns the numeric meaning of a valid raw prefix
  728.      argument value, ARG.  The argument may be a symbol, a number, or a
  729.      list.  If it is `nil', the value 1 is returned; if it is any other
  730.      symbol, the value -1 is returned.  If it is a number, that number
  731.      is returned; if it is a list, the CAR of that list (which should
  732.      be a number) is returned.
  733.  
  734.  - Variable: current-prefix-arg
  735.      This variable is the value of the raw prefix argument for the
  736.      *current* command.  Commands may examine it directly, but the usual
  737.      way to access it is with `(interactive "P")'.
  738.  
  739.  - Variable: prefix-arg
  740.      The value of this variable is the raw prefix argument for the
  741.      *next* editing command.  Commands that specify prefix arguments for
  742.      the following command work by setting this variable.
  743.  
  744. 
  745. File: elisp,  Node: Recursive Editing,  Next: Disabling Commands,  Prev: Prefix Command Arguments,  Up: Command Loop
  746.  
  747. Recursive Editing
  748. =================
  749.  
  750.    The Emacs command loop is entered automatically when Emacs starts up.
  751. This top-level invocation of the command loop is never exited until the
  752. Emacs is killed.  Lisp programs can also invoke the command loop.  Since
  753. this makes more than one activation of the command loop, we call it
  754. "recursive editing".  A recursive editing level has the effect of
  755. suspending whatever command invoked it and permitting the user to do
  756. arbitrary editing before resuming that command.
  757.  
  758.    The commands available during recursive editing are the same ones
  759. available in the top-level editing loop and defined in the keymaps.
  760. Only a few special commands exit the recursive editing level; the others
  761. return to the recursive editing level when finished.  (The special
  762. commands for exiting are always available, but do nothing when recursive
  763. editing is not in progress.)
  764.  
  765.    All command loops, including recursive ones, set up all-purpose error
  766. handlers so that an error in a command run from the command loop will
  767. not exit the loop.
  768.  
  769.    Minibuffer input is a special kind of recursive editing.  It has a
  770. few special wrinkles, such as enabling display of the minibuffer and the
  771. minibuffer window, but fewer than you might suppose.  Certain keys
  772. behave differently in the minibuffer, but that is only because of the
  773. minibuffer's local map; if you switch windows, you get the usual Emacs
  774. commands.
  775.  
  776.    To invoke a recursive editing level, call the function
  777. `recursive-edit'.  This function contains the command loop; it also
  778. contains a call to `catch' with tag `exit', which makes it possible to
  779. exit the recursive editing level by throwing to `exit' (*note Catch and
  780. Throw::.).  If you throw a value other than `t', then `recursive-edit'
  781. returns normally to the function that called it.  The command `C-M-c'
  782. (`exit-recursive-edit') does this.  Throwing a `t' value causes
  783. `recursive-edit' to quit, so that control returns to the command loop
  784. one level up.  This is called "aborting", and is done by `C-]'
  785. (`abort-recursive-edit').
  786.  
  787.    Most applications should not use recursive editing, except as part of
  788. using the minibuffer.  Usually it is more convenient for the user if you
  789. change the major mode of the current buffer temporarily to a special
  790. major mode, which has a command to go back to the previous mode.  (This
  791. technique is used by the `w' command in Rmail.)  Or, if you wish to
  792. give the user different text to edit "recursively", create and select a
  793. new buffer in a special mode.  In this mode, define a command to
  794. complete the processing and go back to the previous buffer.  (The `m'
  795. command in Rmail does this.)
  796.  
  797.    Recursive edits are useful in debugging.  You can insert a call to
  798. `debug' into a function definition as a sort of breakpoint, so that you
  799. can look around when the function gets there.  `debug' invokes a
  800. recursive edit but also provides the other features of the debugger.
  801.  
  802.    Recursive editing levels are also used when you type `C-r' in
  803. `query-replace' or use `C-x q' (`kbd-macro-query').
  804.  
  805.  - Function: recursive-edit
  806.      This function invokes the editor command loop.  It is called
  807.      automatically by the initialization of Emacs, to let the user begin
  808.      editing.  When called from a Lisp program, it enters a recursive
  809.      editing level.
  810.  
  811.      In the following example, the function `simple-rec' first advances
  812.      point one word, then enters a recursive edit, printing out a
  813.      message in the echo area.  The user can then do any editing
  814.      desired, and then type `C-M-c' to exit and continue executing
  815.      `simple-rec'.
  816.  
  817.           (defun simple-rec ()
  818.             (forward-word 1)
  819.             (message "Recursive edit in progress.")
  820.             (recursive-edit)
  821.             (forward-word 1))
  822.                => simple-rec
  823.           (simple-rec)
  824.                => nil
  825.  
  826.  - Command: exit-recursive-edit
  827.      This function exits from the innermost recursive edit (including
  828.      minibuffer input).  Its definition is effectively `(throw 'exit
  829.      nil)'.
  830.  
  831.  - Command: abort-recursive-edit
  832.      This function aborts the command that requested the innermost
  833.      recursive edit (including minibuffer input), by signaling `quit'
  834.      after exiting the recursive edit.  Its definition is effectively
  835.      `(throw 'exit t)'.  *Note Quitting::.
  836.  
  837.  - Command: top-level
  838.      This function exits all recursive editing levels; it does not
  839.      return a value, as it jumps completely out of any computation
  840.      directly back to the main command loop.
  841.  
  842.  - Function: recursion-depth
  843.      This function returns the current depth of recursive edits.  When
  844.      no recursive edit is active, it returns 0.
  845.  
  846. 
  847. File: elisp,  Node: Disabling Commands,  Next: Command History,  Prev: Recursive Editing,  Up: Command Loop
  848.  
  849. Disabling Commands
  850. ==================
  851.  
  852.    "Disabling a command" marks the command as requiring user
  853. confirmation before it can be executed.  Disabling is used for commands
  854. which might be confusing to beginning users, to prevent them from using
  855. the commands by accident.
  856.  
  857.    The low-level mechanism for disabling a command is to put a
  858. non-`nil' `disabled' property on the Lisp symbol for the command.
  859. These properties are normally set up by the user's `.emacs' file with
  860. Lisp expressions such as this:
  861.  
  862.      (put 'upcase-region 'disabled t)
  863.  
  864. For a few commands, these properties are present by default and may be
  865. removed by the `.emacs' file.
  866.  
  867.    If the value of the `disabled' property is a string, that string is
  868. included in the message printed when the command is used:
  869.  
  870.      (put 'delete-region 'disabled
  871.           "Text deleted this way cannot be yanked back!\n")
  872.  
  873.    *Note Disabling: (emacs)Disabling, for the details on what happens
  874. when a disabled command is invoked interactively.  Disabling a command
  875. has no effect on calling it as a function from Lisp programs.
  876.  
  877.  - Command: enable-command COMMAND
  878.      Allow COMMAND to be executed without special confirmation from now
  879.      on.  The user's `.emacs' file is optionally altered so that this
  880.      will apply to future sessions.
  881.  
  882.  - Command: disable-command COMMAND
  883.      Require special confirmation to execute COMMAND from now on.  The
  884.      user's `.emacs' file is optionally altered so that this will apply
  885.      to future sessions.
  886.  
  887.  - Variable: disabled-command-hook
  888.      This variable is a normal hook that is run instead of a disabled
  889.      command, when the user runs the disabled command interactively.
  890.      The hook functions can use `this-command-keys' to determine what
  891.      the user typed to run the command, and thus find the command
  892.      itself.
  893.  
  894.      By default, `disabled-command-hook' contains a function that asks
  895.      the user whether to proceed.
  896.  
  897. 
  898. File: elisp,  Node: Command History,  Next: Keyboard Macros,  Prev: Disabling Commands,  Up: Command Loop
  899.  
  900. Command History
  901. ===============
  902.  
  903.    The command loop keeps a history of the complex commands that have
  904. been executed, to make it convenient to repeat these commands.  A
  905. "complex command" is one for which the interactive argument reading
  906. uses the minibuffer.  This includes any `M-x' command, any `M-ESC'
  907. command, and any command whose `interactive' specification reads an
  908. argument from the minibuffer.  Explicit use of the minibuffer during
  909. the execution of the command itself does not cause the command to be
  910. considered complex.
  911.  
  912.  - Variable: command-history
  913.      This variable's value is a list of recent complex commands, each
  914.      represented as a form to evaluate.  It continues to accumulate all
  915.      complex commands for the duration of the editing session, but all
  916.      but the first (most recent) thirty elements are deleted when a
  917.      garbage collection takes place (*note Garbage Collection::.).
  918.  
  919.           command-history
  920.           => ((switch-to-buffer "chistory.texi")
  921.               (describe-key "^X^[")
  922.               (visit-tags-table "~/emacs/src/")
  923.               (find-tag "repeat-complex-command"))
  924.  
  925.    This history list is actually a special case of minibuffer history
  926. (*note Minibuffer History::.), with one special twist: the elements are
  927. expressions rather than strings.
  928.  
  929.    There are a number of commands devoted to the editing and recall of
  930. previous commands.  The commands `repeat-complex-command', and
  931. `list-command-history' are described in the user manual (*note
  932. Repetition: (emacs)Repetition.).  Within the minibuffer, the history
  933. commands used are the same ones available in any minibuffer.
  934.  
  935. 
  936. File: elisp,  Node: Keyboard Macros,  Prev: Command History,  Up: Command Loop
  937.  
  938. Keyboard Macros
  939. ===============
  940.  
  941.    A "keyboard macro" is a canned sequence of input events that can be
  942. considered a command and made the definition of a key.  Don't confuse
  943. keyboard macros with Lisp macros (*note Macros::.).
  944.  
  945.  - Function: execute-kbd-macro MACRO &optional COUNT
  946.      This function executes MACRO as a sequence of events.  If MACRO is
  947.      a string or vector, then the events in it are executed exactly as
  948.      if they had been input by the user.  The sequence is *not*
  949.      expected to be a single key sequence; normally a keyboard macro
  950.      definition consists of several key sequences concatenated.
  951.  
  952.      If MACRO is a symbol, then its function definition is used in
  953.      place of MACRO.  If that is another symbol, this process repeats.
  954.      Eventually the result should be a string or vector.  If the result
  955.      is not a symbol, string, or vector, an error is signaled.
  956.  
  957.      The argument COUNT is a repeat count; MACRO is executed that many
  958.      times.  If COUNT is omitted or `nil', MACRO is executed once.  If
  959.      it is 0, MACRO is executed over and over until it encounters an
  960.      error or a failing search.
  961.  
  962.  - Variable: last-kbd-macro
  963.      This variable is the definition of the most recently defined
  964.      keyboard macro.  Its value is a string or vector, or `nil'.
  965.  
  966.  - Variable: executing-macro
  967.      This variable contains the string or vector that defines the
  968.      keyboard macro that is currently executing.  It is `nil' if no
  969.      macro is currently executing.
  970.  
  971.  - Variable: defining-kbd-macro
  972.      This variable indicates whether a keyboard macro is being defined.
  973.      It is set to `t' by `start-kbd-macro', and `nil' by
  974.      `end-kbd-macro'.  You can use this variable to make a command
  975.      behave differently when run from a keyboard macro (perhaps
  976.      indirectly by calling `interactive-p').  However, do not set this
  977.      variable yourself.
  978.  
  979.    The commands are described in the user's manual (*note Keyboard
  980. Macros: (emacs)Keyboard Macros.).
  981.  
  982. 
  983. File: elisp,  Node: Keymaps,  Next: Modes,  Prev: Command Loop,  Up: Top
  984.  
  985. Keymaps
  986. *******
  987.  
  988.    The bindings between input events and commands are recorded in data
  989. structures called "keymaps".  Each binding in a keymap associates (or
  990. "binds") an individual event type either with another keymap or with a
  991. command.  When an event is bound to a keymap, that keymap is used to
  992. look up the next character typed; this continues until a command is
  993. found.  The whole process is called "key lookup".
  994.  
  995. * Menu:
  996.  
  997. * Keymap Terminology::            Definitions of terms pertaining to keymaps.
  998. * Format of Keymaps::        What a keymap looks like as a Lisp object.
  999. * Creating Keymaps::         Functions to create and copy keymaps.
  1000. * Inheritance and Keymaps::    How one keymap can inherit the bindings
  1001.                    of another keymap.
  1002. * Prefix Keys::                 Defining a key with a keymap as its definition.
  1003. * Menu Keymaps::        A keymap can define a menu.
  1004. * Active Keymaps::            Each buffer has a local keymap
  1005.                                    to override the standard (global) bindings.
  1006.                    A minor mode can also override them.
  1007. * Key Lookup::                  How extracting elements from keymaps works.
  1008. * Functions for Key Lookup::    How to request key lookup.
  1009. * Changing Key Bindings::       Redefining a key in a keymap.
  1010. * Key Binding Commands::        Interactive interfaces for redefining keys.
  1011. * Scanning Keymaps::            Looking through all keymaps, for printing help.
  1012.  
  1013. 
  1014. File: elisp,  Node: Keymap Terminology,  Next: Format of Keymaps,  Up: Keymaps
  1015.  
  1016. Keymap Terminology
  1017. ==================
  1018.  
  1019.    A "keymap" is a table mapping event types to definitions (which can
  1020. be any Lisp objects, though only certain types are meaningful for
  1021. execution by the command loop).  Given an event (or an event type) and a
  1022. keymap, Emacs can get the event's definition.  Events include ordinary
  1023. ASCII characters, function keys, and mouse actions (*note Input
  1024. Events::.).
  1025.  
  1026.    A sequence of input events that form a unit is called a "key
  1027. sequence", or "key" for short.  A sequence of one event is always a key
  1028. sequence, and so are some multi-event sequences.
  1029.  
  1030.    A keymap determines a binding or definition for any key sequence.  If
  1031. the key sequence is a single event, its binding is the definition of the
  1032. event in the keymap.  The binding of a key sequence of more than one
  1033. event is found by an iterative process: the binding of the first event
  1034. is found, and must be a keymap; then the second event's binding is found
  1035. in that keymap, and so on until all the events in the key sequence are
  1036. used up.
  1037.  
  1038.    If the binding of a key sequence is a keymap, we call the key
  1039. sequence a "prefix key".  Otherwise, we call it a "complete key"
  1040. (because no more characters can be added to it).  If the binding is
  1041. `nil', we call the key "undefined".  Examples of prefix keys are `C-c',
  1042. `C-x', and `C-x 4'.  Examples of defined complete keys are `X', RET,
  1043. and `C-x 4 C-f'.  Examples of undefined complete keys are `C-x C-g',
  1044. and `C-c 3'.  *Note Prefix Keys::, for more details.
  1045.  
  1046.    The rule for finding the binding of a key sequence assumes that the
  1047. intermediate bindings (found for the events before the last) are all
  1048. keymaps; if this is not so, the sequence of events does not form a
  1049. unit--it is not really a key sequence.  In other words, removing one or
  1050. more events from the end of any valid key must always yield a prefix
  1051. key.  For example, `C-f C-f' is not a key; `C-f' is not a prefix key,
  1052. so a longer sequence starting with `C-f' cannot be a key.
  1053.  
  1054.    Note that the set of possible multi-event key sequences depends on
  1055. the bindings for prefix keys; therefore, it can be different for
  1056. different keymaps, and can change when bindings are changed.  However,
  1057. a one-event sequence is always a key sequence, because it does not
  1058. depend on any prefix keys for its well-formedness.
  1059.  
  1060.    At any time, several primary keymaps are "active"--that is, in use
  1061. for finding key bindings.  These are the "global map", which is shared
  1062. by all buffers; the "local keymap", which is usually associated with a
  1063. specific major mode; and zero or more "minor mode keymaps" which belong
  1064. to currently enabled minor modes.  (Not all minor modes have keymaps.)
  1065. The local keymap bindings shadow (i.e., take precedence over) the
  1066. corresponding global bindings.  The minor mode keymaps shadow both
  1067. local and global keymaps.  *Note Active Keymaps::, for details.
  1068.  
  1069. 
  1070. File: elisp,  Node: Format of Keymaps,  Next: Creating Keymaps,  Prev: Keymap Terminology,  Up: Keymaps
  1071.  
  1072. Format of Keymaps
  1073. =================
  1074.  
  1075.    A keymap is a list whose CAR is the symbol `keymap'.  The remaining
  1076. elements of the list define the key bindings of the keymap.  Use the
  1077. function `keymapp' (see below) to test whether an object is a keymap.
  1078.  
  1079.    An ordinary element is a cons cell of the form `(TYPE .  BINDING)'.
  1080. This specifies one binding which applies to events of type TYPE.  Each
  1081. ordinary binding applies to events of a particular "event type", which
  1082. is always a character or a symbol.  *Note Classifying Events::.
  1083.  
  1084.    A cons cell whose CAR is `t' is a "default key binding"; any event
  1085. not bound by other elements of the keymap is given BINDING as its
  1086. binding.  Default bindings allow a keymap to bind all possible event
  1087. types without having to enumerate all of them.  A keymap that has a
  1088. default binding completely masks any lower-precedence keymap.
  1089.  
  1090.    If an element of a keymap is a vector, the vector counts as bindings
  1091. for all the ASCII characters; vector element N is the binding for the
  1092. character with code N.  This is a more compact way to record lots of
  1093. bindings.  A keymap with such a vector is called a "full keymap".
  1094. Other keymaps are called "sparse keymaps".
  1095.  
  1096.    When a keymap contains a vector, it always defines a binding for
  1097. every ASCII character even if the vector element is `nil'.  Such a
  1098. binding of `nil' overrides any default binding in the keymap.  However,
  1099. default bindings are still meaningful for events that are not ASCII
  1100. characters.  A binding of `nil' does *not* override lower-precedence
  1101. keymaps; thus, if the local map gives a binding of `nil', Emacs uses
  1102. the binding from the global map.
  1103.  
  1104.    Aside from bindings, a keymap can also have a string as an element.
  1105. This is called the "overall prompt string" and makes it possible to use
  1106. the keymap as a menu.  *Note Menu Keymaps::.
  1107.  
  1108.    Keymaps do not directly record bindings for the meta characters,
  1109. whose codes are from 128 to 255.  Instead, meta characters are regarded
  1110. for purposes of key lookup as sequences of two characters, the first of
  1111. which is ESC (or whatever is currently the value of
  1112. `meta-prefix-char').  Thus, the key `M-a' is really represented as `ESC
  1113. a', and its global binding is found at the slot for `a' in `esc-map'.
  1114.  
  1115.    Here as an example is the local keymap for Lisp mode, a sparse
  1116. keymap.  It defines bindings for DEL and TAB, plus `C-c C-l', `M-C-q',
  1117. and `M-C-x'.
  1118.  
  1119.      lisp-mode-map
  1120.      =>
  1121.      (keymap
  1122.       ;; TAB
  1123.       (9 . lisp-indent-line)
  1124.       ;; DEL
  1125.       (127 . backward-delete-char-untabify)
  1126.       (3 keymap
  1127.          ;; `C-c C-l'
  1128.          (12 . run-lisp))
  1129.       (27 keymap
  1130.           ;; `M-C-q', treated as `ESC C-q'
  1131.           (17 . indent-sexp)
  1132.           ;; `M-C-x', treated as `ESC C-x'
  1133.           (24 . lisp-send-defun)))
  1134.  
  1135.  - Function: keymapp OBJECT
  1136.      This function returns `t' if OBJECT is a keymap, `nil' otherwise.
  1137.      Practically speaking, this function tests for a list whose CAR is
  1138.      `keymap'.
  1139.  
  1140.           (keymapp '(keymap))
  1141.               => t
  1142.           (keymapp (current-global-map))
  1143.               => t
  1144.  
  1145. 
  1146. File: elisp,  Node: Creating Keymaps,  Next: Inheritance and Keymaps,  Prev: Format of Keymaps,  Up: Keymaps
  1147.  
  1148. Creating Keymaps
  1149. ================
  1150.  
  1151.    Here we describe the functions for creating keymaps.
  1152.  
  1153.  - Function: make-keymap &optional PROMPT
  1154.      This function creates and returns a new full keymap (i.e., one
  1155.      which contains a vector of length 128 for defining all the ASCII
  1156.      characters).  The new keymap initially binds all ASCII characters
  1157.      to `nil', and does not bind any other kind of event.
  1158.  
  1159.           (make-keymap)
  1160.               => (keymap [nil nil nil ... nil nil])
  1161.  
  1162.      If you specify PROMPT, that becomes the overall prompt string for
  1163.      the keymap.  The prompt string is useful for menu keymaps (*note
  1164.      Menu Keymaps::.).
  1165.  
  1166.  - Function: make-sparse-keymap &optional PROMPT
  1167.      This function creates and returns a new sparse keymap with no
  1168.      entries.  The new keymap does not bind any events.  The argument
  1169.      PROMPT specifies a prompt string, as in `make-keymap'.
  1170.  
  1171.           (make-sparse-keymap)
  1172.               => (keymap)
  1173.  
  1174.  - Function: copy-keymap KEYMAP
  1175.      This function returns a copy of KEYMAP.  Any keymaps which appear
  1176.      directly as bindings in KEYMAP are also copied recursively, and so
  1177.      on to any number of levels.  However, recursive copying does not
  1178.      take place when the definition of a character is a symbol whose
  1179.      function definition is a keymap; the same symbol appears in the
  1180.      new copy.
  1181.  
  1182.           (setq map (copy-keymap (current-local-map)))
  1183.           => (keymap
  1184.                ;; (This implements meta characters.)
  1185.                (27 keymap
  1186.                    (83 . center-paragraph)
  1187.                    (115 . center-line))
  1188.                (9 . tab-to-tab-stop))
  1189.           
  1190.           (eq map (current-local-map))
  1191.               => nil
  1192.           (equal map (current-local-map))
  1193.               => t
  1194.  
  1195.