This commit was generated by cvs2svn to compensate for changes in r5670,
[chise/xemacs-chise.git.1] / info / lispref.info-18
1 This is Info file ../../info/lispref.info, produced by Makeinfo version
2 1.68 from the input file lispref.texi.
3
4 INFO-DIR-SECTION XEmacs Editor
5 START-INFO-DIR-ENTRY
6 * Lispref: (lispref).           XEmacs Lisp Reference Manual.
7 END-INFO-DIR-ENTRY
8
9    Edition History:
10
11    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
12 Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
13 Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
14 XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
15 GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
16 Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
17 Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
18 Reference Manual (for 19.15 and 20.1, 20.2, 20.3) v3.2, April, May,
19 November 1997 XEmacs Lisp Reference Manual (for 21.0) v3.3, April 1998
20
21    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
22 Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
23 Copyright (C) 1995, 1996 Ben Wing.
24
25    Permission is granted to make and distribute verbatim copies of this
26 manual provided the copyright notice and this permission notice are
27 preserved on all copies.
28
29    Permission is granted to copy and distribute modified versions of
30 this manual under the conditions for verbatim copying, provided that the
31 entire resulting derived work is distributed under the terms of a
32 permission notice identical to this one.
33
34    Permission is granted to copy and distribute translations of this
35 manual into another language, under the above conditions for modified
36 versions, except that this permission notice may be stated in a
37 translation approved by the Foundation.
38
39    Permission is granted to copy and distribute modified versions of
40 this manual under the conditions for verbatim copying, provided also
41 that the section entitled "GNU General Public License" is included
42 exactly as in the original, and provided that the entire resulting
43 derived work is distributed under the terms of a permission notice
44 identical to this one.
45
46    Permission is granted to copy and distribute translations of this
47 manual into another language, under the above conditions for modified
48 versions, except that the section entitled "GNU General Public License"
49 may be included in a translation approved by the Free Software
50 Foundation instead of in the original English.
51
52 \1f
53 File: lispref.info,  Node: Quitting,  Next: Prefix Command Arguments,  Prev: Waiting,  Up: Command Loop
54
55 Quitting
56 ========
57
58    Typing `C-g' while a Lisp function is running causes XEmacs to
59 "quit" whatever it is doing.  This means that control returns to the
60 innermost active command loop.
61
62    Typing `C-g' while the command loop is waiting for keyboard input
63 does not cause a quit; it acts as an ordinary input character.  In the
64 simplest case, you cannot tell the difference, because `C-g' normally
65 runs the command `keyboard-quit', whose effect is to quit.  However,
66 when `C-g' follows a prefix key, the result is an undefined key.  The
67 effect is to cancel the prefix key as well as any prefix argument.
68
69    In the minibuffer, `C-g' has a different definition: it aborts out
70 of the minibuffer.  This means, in effect, that it exits the minibuffer
71 and then quits.  (Simply quitting would return to the command loop
72 *within* the minibuffer.)  The reason why `C-g' does not quit directly
73 when the command reader is reading input is so that its meaning can be
74 redefined in the minibuffer in this way.  `C-g' following a prefix key
75 is not redefined in the minibuffer, and it has its normal effect of
76 canceling the prefix key and prefix argument.  This too would not be
77 possible if `C-g' always quit directly.
78
79    When `C-g' does directly quit, it does so by setting the variable
80 `quit-flag' to `t'.  XEmacs checks this variable at appropriate times
81 and quits if it is not `nil'.  Setting `quit-flag' non-`nil' in any way
82 thus causes a quit.
83
84    At the level of C code, quitting cannot happen just anywhere; only
85 at the special places that check `quit-flag'.  The reason for this is
86 that quitting at other places might leave an inconsistency in XEmacs's
87 internal state.  Because quitting is delayed until a safe place,
88 quitting cannot make XEmacs crash.
89
90    Certain functions such as `read-key-sequence' or `read-quoted-char'
91 prevent quitting entirely even though they wait for input.  Instead of
92 quitting, `C-g' serves as the requested input.  In the case of
93 `read-key-sequence', this serves to bring about the special behavior of
94 `C-g' in the command loop.  In the case of `read-quoted-char', this is
95 so that `C-q' can be used to quote a `C-g'.
96
97    You can prevent quitting for a portion of a Lisp function by binding
98 the variable `inhibit-quit' to a non-`nil' value.  Then, although `C-g'
99 still sets `quit-flag' to `t' as usual, the usual result of this--a
100 quit--is prevented.  Eventually, `inhibit-quit' will become `nil'
101 again, such as when its binding is unwound at the end of a `let' form.
102 At that time, if `quit-flag' is still non-`nil', the requested quit
103 happens immediately.  This behavior is ideal when you wish to make sure
104 that quitting does not happen within a "critical section" of the
105 program.
106
107    In some functions (such as `read-quoted-char'), `C-g' is handled in
108 a special way that does not involve quitting.  This is done by reading
109 the input with `inhibit-quit' bound to `t', and setting `quit-flag' to
110 `nil' before `inhibit-quit' becomes `nil' again.  This excerpt from the
111 definition of `read-quoted-char' shows how this is done; it also shows
112 that normal quitting is permitted after the first character of input.
113
114      (defun read-quoted-char (&optional prompt)
115        "...DOCUMENTATION..."
116        (let ((count 0) (code 0) char)
117          (while (< count 3)
118            (let ((inhibit-quit (zerop count))
119                  (help-form nil))
120              (and prompt (message "%s-" prompt))
121              (setq char (read-char))
122              (if inhibit-quit (setq quit-flag nil)))
123            ...)
124          (logand 255 code)))
125
126  - Variable: quit-flag
127      If this variable is non-`nil', then XEmacs quits immediately,
128      unless `inhibit-quit' is non-`nil'.  Typing `C-g' ordinarily sets
129      `quit-flag' non-`nil', regardless of `inhibit-quit'.
130
131  - Variable: inhibit-quit
132      This variable determines whether XEmacs should quit when
133      `quit-flag' is set to a value other than `nil'.  If `inhibit-quit'
134      is non-`nil', then `quit-flag' has no special effect.
135
136  - Command: keyboard-quit
137      This function signals the `quit' condition with `(signal 'quit
138      nil)'.  This is the same thing that quitting does.  (See `signal'
139      in *Note Errors::.)
140
141    You can specify a character other than `C-g' to use for quitting.
142 See the function `set-input-mode' in *Note Terminal Input::.
143
144 \1f
145 File: lispref.info,  Node: Prefix Command Arguments,  Next: Recursive Editing,  Prev: Quitting,  Up: Command Loop
146
147 Prefix Command Arguments
148 ========================
149
150    Most XEmacs commands can use a "prefix argument", a number specified
151 before the command itself.  (Don't confuse prefix arguments with prefix
152 keys.)  The prefix argument is at all times represented by a value,
153 which may be `nil', meaning there is currently no prefix argument.
154 Each command may use the prefix argument or ignore it.
155
156    There are two representations of the prefix argument: "raw" and
157 "numeric".  The editor command loop uses the raw representation
158 internally, and so do the Lisp variables that store the information, but
159 commands can request either representation.
160
161    Here are the possible values of a raw prefix argument:
162
163    * `nil', meaning there is no prefix argument.  Its numeric value is
164      1, but numerous commands make a distinction between `nil' and the
165      integer 1.
166
167    * An integer, which stands for itself.
168
169    * A list of one element, which is an integer.  This form of prefix
170      argument results from one or a succession of `C-u''s with no
171      digits.  The numeric value is the integer in the list, but some
172      commands make a distinction between such a list and an integer
173      alone.
174
175    * The symbol `-'.  This indicates that `M--' or `C-u -' was typed,
176      without following digits.  The equivalent numeric value is -1, but
177      some commands make a distinction between the integer -1 and the
178      symbol `-'.
179
180    We illustrate these possibilities by calling the following function
181 with various prefixes:
182
183      (defun display-prefix (arg)
184        "Display the value of the raw prefix arg."
185        (interactive "P")
186        (message "%s" arg))
187
188 Here are the results of calling `display-prefix' with various raw
189 prefix arguments:
190
191              M-x display-prefix  -| nil
192      
193      C-u     M-x display-prefix  -| (4)
194      
195      C-u C-u M-x display-prefix  -| (16)
196      
197      C-u 3   M-x display-prefix  -| 3
198      
199      M-3     M-x display-prefix  -| 3      ; (Same as `C-u 3'.)
200      
201      C-3     M-x display-prefix  -| 3      ; (Same as `C-u 3'.)
202      
203      C-u -   M-x display-prefix  -| -
204      
205      M--     M-x display-prefix  -| -      ; (Same as `C-u -'.)
206      
207      C--     M-x display-prefix  -| -      ; (Same as `C-u -'.)
208      
209      C-u - 7 M-x display-prefix  -| -7
210      
211      M-- 7   M-x display-prefix  -| -7     ; (Same as `C-u -7'.)
212      
213      C-- 7   M-x display-prefix  -| -7     ; (Same as `C-u -7'.)
214
215    XEmacs uses two variables to store the prefix argument: `prefix-arg'
216 and `current-prefix-arg'.  Commands such as `universal-argument' that
217 set up prefix arguments for other commands store them in `prefix-arg'.
218 In contrast, `current-prefix-arg' conveys the prefix argument to the
219 current command, so setting it has no effect on the prefix arguments
220 for future commands.
221
222    Normally, commands specify which representation to use for the prefix
223 argument, either numeric or raw, in the `interactive' declaration.
224 (*Note Using Interactive::.)  Alternatively, functions may look at the
225 value of the prefix argument directly in the variable
226 `current-prefix-arg', but this is less clean.
227
228  - Function: prefix-numeric-value ARG
229      This function returns the numeric meaning of a valid raw prefix
230      argument value, ARG.  The argument may be a symbol, a number, or a
231      list.  If it is `nil', the value 1 is returned; if it is `-', the
232      value -1 is returned; if it is a number, that number is returned;
233      if it is a list, the CAR of that list (which should be a number) is
234      returned.
235
236  - Variable: current-prefix-arg
237      This variable holds the raw prefix argument for the *current*
238      command.  Commands may examine it directly, but the usual way to
239      access it is with `(interactive "P")'.
240
241  - Variable: prefix-arg
242      The value of this variable is the raw prefix argument for the
243      *next* editing command.  Commands that specify prefix arguments for
244      the following command work by setting this variable.
245
246    Do not call the functions `universal-argument', `digit-argument', or
247 `negative-argument' unless you intend to let the user enter the prefix
248 argument for the *next* command.
249
250  - Command: universal-argument
251      This command reads input and specifies a prefix argument for the
252      following command.  Don't call this command yourself unless you
253      know what you are doing.
254
255  - Command: digit-argument ARG
256      This command adds to the prefix argument for the following
257      command.  The argument ARG is the raw prefix argument as it was
258      before this command; it is used to compute the updated prefix
259      argument.  Don't call this command yourself unless you know what
260      you are doing.
261
262  - Command: negative-argument ARG
263      This command adds to the numeric argument for the next command.
264      The argument ARG is the raw prefix argument as it was before this
265      command; its value is negated to form the new prefix argument.
266      Don't call this command yourself unless you know what you are
267      doing.
268
269 \1f
270 File: lispref.info,  Node: Recursive Editing,  Next: Disabling Commands,  Prev: Prefix Command Arguments,  Up: Command Loop
271
272 Recursive Editing
273 =================
274
275    The XEmacs command loop is entered automatically when XEmacs starts
276 up.  This top-level invocation of the command loop never exits; it keeps
277 running as long as XEmacs does.  Lisp programs can also invoke the
278 command loop.  Since this makes more than one activation of the command
279 loop, we call it "recursive editing".  A recursive editing level has
280 the effect of suspending whatever command invoked it and permitting the
281 user to do arbitrary editing before resuming that command.
282
283    The commands available during recursive editing are the same ones
284 available in the top-level editing loop and defined in the keymaps.
285 Only a few special commands exit the recursive editing level; the others
286 return to the recursive editing level when they finish.  (The special
287 commands for exiting are always available, but they do nothing when
288 recursive editing is not in progress.)
289
290    All command loops, including recursive ones, set up all-purpose error
291 handlers so that an error in a command run from the command loop will
292 not exit the loop.
293
294    Minibuffer input is a special kind of recursive editing.  It has a
295 few special wrinkles, such as enabling display of the minibuffer and the
296 minibuffer window, but fewer than you might suppose.  Certain keys
297 behave differently in the minibuffer, but that is only because of the
298 minibuffer's local map; if you switch windows, you get the usual XEmacs
299 commands.
300
301    To invoke a recursive editing level, call the function
302 `recursive-edit'.  This function contains the command loop; it also
303 contains a call to `catch' with tag `exit', which makes it possible to
304 exit the recursive editing level by throwing to `exit' (*note Catch and
305 Throw::.).  If you throw a value other than `t', then `recursive-edit'
306 returns normally to the function that called it.  The command `C-M-c'
307 (`exit-recursive-edit') does this.  Throwing a `t' value causes
308 `recursive-edit' to quit, so that control returns to the command loop
309 one level up.  This is called "aborting", and is done by `C-]'
310 (`abort-recursive-edit').
311
312    Most applications should not use recursive editing, except as part of
313 using the minibuffer.  Usually it is more convenient for the user if you
314 change the major mode of the current buffer temporarily to a special
315 major mode, which should have a command to go back to the previous mode.
316 (The `e' command in Rmail uses this technique.)  Or, if you wish to
317 give the user different text to edit "recursively", create and select a
318 new buffer in a special mode.  In this mode, define a command to
319 complete the processing and go back to the previous buffer.  (The `m'
320 command in Rmail does this.)
321
322    Recursive edits are useful in debugging.  You can insert a call to
323 `debug' into a function definition as a sort of breakpoint, so that you
324 can look around when the function gets there.  `debug' invokes a
325 recursive edit but also provides the other features of the debugger.
326
327    Recursive editing levels are also used when you type `C-r' in
328 `query-replace' or use `C-x q' (`kbd-macro-query').
329
330  - Function: recursive-edit
331      This function invokes the editor command loop.  It is called
332      automatically by the initialization of XEmacs, to let the user
333      begin editing.  When called from a Lisp program, it enters a
334      recursive editing level.
335
336      In the following example, the function `simple-rec' first advances
337      point one word, then enters a recursive edit, printing out a
338      message in the echo area.  The user can then do any editing
339      desired, and then type `C-M-c' to exit and continue executing
340      `simple-rec'.
341
342           (defun simple-rec ()
343             (forward-word 1)
344             (message "Recursive edit in progress")
345             (recursive-edit)
346             (forward-word 1))
347                => simple-rec
348           (simple-rec)
349                => nil
350
351  - Command: exit-recursive-edit
352      This function exits from the innermost recursive edit (including
353      minibuffer input).  Its definition is effectively `(throw 'exit
354      nil)'.
355
356  - Command: abort-recursive-edit
357      This function aborts the command that requested the innermost
358      recursive edit (including minibuffer input), by signaling `quit'
359      after exiting the recursive edit.  Its definition is effectively
360      `(throw 'exit t)'.  *Note Quitting::.
361
362  - Command: top-level
363      This function exits all recursive editing levels; it does not
364      return a value, as it jumps completely out of any computation
365      directly back to the main command loop.
366
367  - Function: recursion-depth
368      This function returns the current depth of recursive edits.  When
369      no recursive edit is active, it returns 0.
370
371 \1f
372 File: lispref.info,  Node: Disabling Commands,  Next: Command History,  Prev: Recursive Editing,  Up: Command Loop
373
374 Disabling Commands
375 ==================
376
377    "Disabling a command" marks the command as requiring user
378 confirmation before it can be executed.  Disabling is used for commands
379 which might be confusing to beginning users, to prevent them from using
380 the commands by accident.
381
382    The low-level mechanism for disabling a command is to put a
383 non-`nil' `disabled' property on the Lisp symbol for the command.
384 These properties are normally set up by the user's `.emacs' file with
385 Lisp expressions such as this:
386
387      (put 'upcase-region 'disabled t)
388
389 For a few commands, these properties are present by default and may be
390 removed by the `.emacs' file.
391
392    If the value of the `disabled' property is a string, the message
393 saying the command is disabled includes that string.  For example:
394
395      (put 'delete-region 'disabled
396           "Text deleted this way cannot be yanked back!\n")
397
398    *Note Disabling: (xemacs)Disabling, for the details on what happens
399 when a disabled command is invoked interactively.  Disabling a command
400 has no effect on calling it as a function from Lisp programs.
401
402  - Command: enable-command COMMAND
403      Allow COMMAND to be executed without special confirmation from now
404      on, and (if the user confirms) alter the user's `.emacs' file so
405      that this will apply to future sessions.
406
407  - Command: disable-command COMMAND
408      Require special confirmation to execute COMMAND from now on, and
409      (if the user confirms) alter the user's `.emacs' file so that this
410      will apply to future sessions.
411
412  - Variable: disabled-command-hook
413      This normal hook is run instead of a disabled command, when the
414      user invokes the disabled command interactively.  The hook
415      functions can use `this-command-keys' to determine what the user
416      typed to run the command, and thus find the command itself.  *Note
417      Hooks::.
418
419      By default, `disabled-command-hook' contains a function that asks
420      the user whether to proceed.
421
422 \1f
423 File: lispref.info,  Node: Command History,  Next: Keyboard Macros,  Prev: Disabling Commands,  Up: Command Loop
424
425 Command History
426 ===============
427
428    The command loop keeps a history of the complex commands that have
429 been executed, to make it convenient to repeat these commands.  A
430 "complex command" is one for which the interactive argument reading
431 uses the minibuffer.  This includes any `M-x' command, any `M-:'
432 command, and any command whose `interactive' specification reads an
433 argument from the minibuffer.  Explicit use of the minibuffer during
434 the execution of the command itself does not cause the command to be
435 considered complex.
436
437  - Variable: command-history
438      This variable's value is a list of recent complex commands, each
439      represented as a form to evaluate.  It continues to accumulate all
440      complex commands for the duration of the editing session, but all
441      but the first (most recent) thirty elements are deleted when a
442      garbage collection takes place (*note Garbage Collection::.).
443
444           command-history
445           => ((switch-to-buffer "chistory.texi")
446               (describe-key "^X^[")
447               (visit-tags-table "~/emacs/src/")
448               (find-tag "repeat-complex-command"))
449
450    This history list is actually a special case of minibuffer history
451 (*note Minibuffer History::.), with one special twist: the elements are
452 expressions rather than strings.
453
454    There are a number of commands devoted to the editing and recall of
455 previous commands.  The commands `repeat-complex-command', and
456 `list-command-history' are described in the user manual (*note
457 Repetition: (xemacs)Repetition.).  Within the minibuffer, the history
458 commands used are the same ones available in any minibuffer.
459
460 \1f
461 File: lispref.info,  Node: Keyboard Macros,  Prev: Command History,  Up: Command Loop
462
463 Keyboard Macros
464 ===============
465
466    A "keyboard macro" is a canned sequence of input events that can be
467 considered a command and made the definition of a key.  The Lisp
468 representation of a keyboard macro is a string or vector containing the
469 events.  Don't confuse keyboard macros with Lisp macros (*note
470 Macros::.).
471
472  - Function: execute-kbd-macro MACRO &optional COUNT
473      This function executes MACRO as a sequence of events.  If MACRO is
474      a string or vector, then the events in it are executed exactly as
475      if they had been input by the user.  The sequence is *not*
476      expected to be a single key sequence; normally a keyboard macro
477      definition consists of several key sequences concatenated.
478
479      If MACRO is a symbol, then its function definition is used in
480      place of MACRO.  If that is another symbol, this process repeats.
481      Eventually the result should be a string or vector.  If the result
482      is not a symbol, string, or vector, an error is signaled.
483
484      The argument COUNT is a repeat count; MACRO is executed that many
485      times.  If COUNT is omitted or `nil', MACRO is executed once.  If
486      it is 0, MACRO is executed over and over until it encounters an
487      error or a failing search.
488
489  - Variable: executing-macro
490      This variable contains the string or vector that defines the
491      keyboard macro that is currently executing.  It is `nil' if no
492      macro is currently executing.  A command can test this variable to
493      behave differently when run from an executing macro.  Do not set
494      this variable yourself.
495
496  - Variable: defining-kbd-macro
497      This variable indicates whether a keyboard macro is being defined.
498      A command can test this variable to behave differently while a
499      macro is being defined.  The commands `start-kbd-macro' and
500      `end-kbd-macro' set this variable--do not set it yourself.
501
502  - Variable: last-kbd-macro
503      This variable is the definition of the most recently defined
504      keyboard macro.  Its value is a string or vector, or `nil'.
505
506    The commands are described in the user's manual (*note Keyboard
507 Macros: (xemacs)Keyboard Macros.).
508
509 \1f
510 File: lispref.info,  Node: Keymaps,  Next: Menus,  Prev: Command Loop,  Up: Top
511
512 Keymaps
513 *******
514
515    The bindings between input events and commands are recorded in data
516 structures called "keymaps".  Each binding in a keymap associates (or
517 "binds") an individual event type either with another keymap or with a
518 command.  When an event is bound to a keymap, that keymap is used to
519 look up the next input event; this continues until a command is found.
520 The whole process is called "key lookup".
521
522 * Menu:
523
524 * Keymap Terminology::       Definitions of terms pertaining to keymaps.
525 * Format of Keymaps::        What a keymap looks like as a Lisp object.
526 * Creating Keymaps::         Functions to create and copy keymaps.
527 * Inheritance and Keymaps::  How one keymap can inherit the bindings
528                                 of another keymap.
529 * Key Sequences::            How to specify key sequences.
530 * Prefix Keys::              Defining a key with a keymap as its definition.
531 * Active Keymaps::           Each buffer has a local keymap
532                                 to override the standard (global) bindings.
533                                 A minor mode can also override them.
534 * Key Lookup::               How extracting elements from keymaps works.
535 * Functions for Key Lookup:: How to request key lookup.
536 * Changing Key Bindings::    Redefining a key in a keymap.
537 * Key Binding Commands::     Interactive interfaces for redefining keys.
538 * Scanning Keymaps::         Looking through all keymaps, for printing help.
539 * Other Keymap Functions::   Miscellaneous keymap functions.
540
541 \1f
542 File: lispref.info,  Node: Keymap Terminology,  Next: Format of Keymaps,  Up: Keymaps
543
544 Keymap Terminology
545 ==================
546
547    A "keymap" is a table mapping event types to definitions (which can
548 be any Lisp objects, though only certain types are meaningful for
549 execution by the command loop).  Given an event (or an event type) and a
550 keymap, XEmacs can get the event's definition.  Events mapped in keymaps
551 include keypresses, button presses, and button releases (*note
552 Events::.).
553
554    A sequence of input events that form a unit is called a "key
555 sequence", or "key" for short.  A sequence of one event is always a key
556 sequence, and so are some multi-event sequences.
557
558    A keymap determines a binding or definition for any key sequence.  If
559 the key sequence is a single event, its binding is the definition of the
560 event in the keymap.  The binding of a key sequence of more than one
561 event is found by an iterative process: the binding of the first event
562 is found, and must be a keymap; then the second event's binding is found
563 in that keymap, and so on until all the events in the key sequence are
564 used up.
565
566    If the binding of a key sequence is a keymap, we call the key
567 sequence a "prefix key".  Otherwise, we call it a "complete key"
568 (because no more events can be added to it).  If the binding is `nil',
569 we call the key "undefined".  Examples of prefix keys are `C-c', `C-x',
570 and `C-x 4'.  Examples of defined complete keys are `X', <RET>, and
571 `C-x 4 C-f'.  Examples of undefined complete keys are `C-x C-g', and
572 `C-c 3'.  *Note Prefix Keys::, for more details.
573
574    The rule for finding the binding of a key sequence assumes that the
575 intermediate bindings (found for the events before the last) are all
576 keymaps; if this is not so, the sequence of events does not form a
577 unit--it is not really a key sequence.  In other words, removing one or
578 more events from the end of any valid key must always yield a prefix
579 key.  For example, `C-f C-n' is not a key; `C-f' is not a prefix key,
580 so a longer sequence starting with `C-f' cannot be a key.
581
582    Note that the set of possible multi-event key sequences depends on
583 the bindings for prefix keys; therefore, it can be different for
584 different keymaps, and can change when bindings are changed.  However,
585 a one-event sequence is always a key sequence, because it does not
586 depend on any prefix keys for its well-formedness.
587
588    At any time, several primary keymaps are "active"--that is, in use
589 for finding key bindings.  These are the "global map", which is shared
590 by all buffers; the "local keymap", which is usually associated with a
591 specific major mode; and zero or more "minor mode keymaps", which
592 belong to currently enabled minor modes.  (Not all minor modes have
593 keymaps.)  The local keymap bindings shadow (i.e., take precedence
594 over) the corresponding global bindings.  The minor mode keymaps shadow
595 both local and global keymaps.  *Note Active Keymaps::, for details.
596
597 \1f
598 File: lispref.info,  Node: Format of Keymaps,  Next: Creating Keymaps,  Prev: Keymap Terminology,  Up: Keymaps
599
600 Format of Keymaps
601 =================
602
603    A keymap is a primitive type that associates events with their
604 bindings.  Note that this is different from Emacs 18 and FSF Emacs,
605 where keymaps are lists.
606
607  - Function: keymapp OBJECT
608      This function returns `t' if OBJECT is a keymap, `nil' otherwise.
609
610 \1f
611 File: lispref.info,  Node: Creating Keymaps,  Next: Inheritance and Keymaps,  Prev: Format of Keymaps,  Up: Keymaps
612
613 Creating Keymaps
614 ================
615
616    Here we describe the functions for creating keymaps.
617
618  - Function: make-keymap &optional NAME
619      This function constructs and returns a new keymap object.  All
620      entries in it are `nil', meaning "command undefined".
621
622      Optional argument NAME specifies a name to assign to the keymap,
623      as in `set-keymap-name'.  This name is only a debugging
624      convenience; it is not used except when printing the keymap.
625
626  - Function: make-sparse-keymap &optional NAME
627      This function constructs and returns a new keymap object.  All
628      entries in it are `nil', meaning "command undefined".  The only
629      difference between this function and `make-keymap' is that this
630      function returns a "smaller" keymap (one that is expected to
631      contain fewer entries).  As keymaps dynamically resize, the
632      distinction is not great.
633
634      Optional argument NAME specifies a name to assign to the keymap,
635      as in `set-keymap-name'.  This name is only a debugging
636      convenience; it is not used except when printing the keymap.
637
638  - Function: set-keymap-name KEYMAP NEW-NAME
639      This function assigns a "name" to a keymap.  The name is only a
640      debugging convenience; it is not used except when printing the
641      keymap.
642
643  - Function: keymap-name KEYMAP
644      This function returns the "name" of a keymap, as assigned using
645      `set-keymap-name'.
646
647  - Function: copy-keymap KEYMAP
648      This function returns a copy of KEYMAP.  Any keymaps that appear
649      directly as bindings in KEYMAP are also copied recursively, and so
650      on to any number of levels.  However, recursive copying does not
651      take place when the definition of a character is a symbol whose
652      function definition is a keymap; the same symbol appears in the
653      new copy.
654
655           (setq map (copy-keymap (current-local-map)))
656           => #<keymap 3 entries 0x21f80>
657           
658           (eq map (current-local-map))
659               => nil
660
661 \1f
662 File: lispref.info,  Node: Inheritance and Keymaps,  Next: Key Sequences,  Prev: Creating Keymaps,  Up: Keymaps
663
664 Inheritance and Keymaps
665 =======================
666
667    A keymap can inherit the bindings of other keymaps.  The other
668 keymaps are called the keymap's "parents", and are set with
669 `set-keymap-parents'.  When searching for a binding for a key sequence
670 in a particular keymap, that keymap itself will first be searched;
671 then, if no binding was found in the map and it has parents, the first
672 parent keymap will be searched; then that keymap's parent will be
673 searched, and so on, until either a binding for the key sequence is
674 found, or a keymap without a parent is encountered.  At this point, the
675 search will continue with the next parent of the most recently
676 encountered keymap that has another parent, etc.  Essentially, a
677 depth-first search of all the ancestors of the keymap is conducted.
678
679    `(current-global-map)' is the default parent of all keymaps.
680
681  - Function: set-keymap-parents KEYMAP PARENTS
682      This function sets the parent keymaps of KEYMAP to the list
683      PARENTS.
684
685      If you change the bindings in one of the keymaps in PARENTS using
686      `define-key' or other key-binding functions, these changes are
687      visible in KEYMAP unless shadowed by bindings in that map or in
688      earlier-searched ancestors.  The converse is not true: if you use
689      `define-key' to change KEYMAP, that affects the bindings in that
690      map, but has no effect on any of the keymaps in PARENTS.
691
692  - Function: keymap-parents KEYMAP
693      This function returns the list of parent keymaps of KEYMAP, or
694      `nil' if KEYMAP has no parents.
695
696    As an alternative to specifying a parent, you can also specify a
697 "default binding" that is used whenever a key is not otherwise bound in
698 the keymap.  This is useful for terminal emulators, for example, which
699 may want to trap all keystrokes and pass them on in some modified
700 format.  Note that if you specify a default binding for a keymap,
701 neither the keymap's parents nor the current global map are searched for
702 key bindings.
703
704  - Function: set-keymap-default-binding KEYMAP COMMAND
705      This function sets the default binding of KEYMAP to COMMAND, or
706      `nil' if no default is desired.
707
708  - Function: keymap-default-binding KEYMAP
709      This function returns the default binding of KEYMAP, or `nil' if
710      it has none.
711
712 \1f
713 File: lispref.info,  Node: Key Sequences,  Next: Prefix Keys,  Prev: Inheritance and Keymaps,  Up: Keymaps
714
715 Key Sequences
716 =============
717
718    Contrary to popular belief, the world is not ASCII.  When running
719 under a window manager, XEmacs can tell the difference between, for
720 example, the keystrokes `control-h', `control-shift-h', and
721 `backspace'.  You can, in fact, bind different commands to each of
722 these.
723
724    A "key sequence" is a set of keystrokes.  A "keystroke" is a keysym
725 and some set of modifiers (such as <CONTROL> and <META>).  A "keysym"
726 is what is printed on the keys on your keyboard.
727
728    A keysym may be represented by a symbol, or (if and only if it is
729 equivalent to an ASCII character in the range 32 - 255) by a character
730 or its equivalent ASCII code.  The `A' key may be represented by the
731 symbol `A', the character `?A', or by the number 65.  The `break' key
732 may be represented only by the symbol `break'.
733
734    A keystroke may be represented by a list: the last element of the
735 list is the key (a symbol, character, or number, as above) and the
736 preceding elements are the symbolic names of modifier keys (<CONTROL>,
737 <META>, <SUPER>, <HYPER>, <ALT>, and <SHIFT>).  Thus, the sequence
738 `control-b' is represented by the forms `(control b)', `(control ?b)',
739 and `(control 98)'.  A keystroke may also be represented by an event
740 object, as returned by the `next-command-event' and `read-key-sequence'
741 functions.
742
743    Note that in this context, the keystroke `control-b' is *not*
744 represented by the number 2 (the ASCII code for `^B') or the character
745 `?\^B'.  See below.
746
747    The <SHIFT> modifier is somewhat of a special case.  You should not
748 (and cannot) use `(meta shift a)' to mean `(meta A)', since for
749 characters that have ASCII equivalents, the state of the shift key is
750 implicit in the keysym (`a' vs. `A').  You also cannot say `(shift =)'
751 to mean `+', as that sort of thing varies from keyboard to keyboard.
752 The <SHIFT> modifier is for use only with characters that do not have a
753 second keysym on the same key, such as `backspace' and `tab'.
754
755    A key sequence is a vector of keystrokes.  As a degenerate case,
756 elements of this vector may also be keysyms if they have no modifiers.
757 That is, the `A' keystroke is represented by all of these forms:
758
759         A       ?A      65      (A)     (?A)    (65)
760         [A]     [?A]    [65]    [(A)]   [(?A)]  [(65)]
761
762    the `control-a' keystroke is represented by these forms:
763
764         (control A)     (control ?A)    (control 65)
765         [(control A)]   [(control ?A)]  [(control 65)]
766
767    the key sequence `control-c control-a' is represented by these forms:
768
769         [(control c) (control a)]       [(control ?c) (control ?a)]
770         [(control 99) (control 65)]     etc.
771
772    Mouse button clicks work just like keypresses: `(control button1)'
773 means pressing the left mouse button while holding down the control
774 key.  `[(control c) (shift button3)]' means `control-c', hold <SHIFT>,
775 click right.
776
777    Commands may be bound to the mouse-button up-stroke rather than the
778 down-stroke as well.  `button1' means the down-stroke, and `button1up'
779 means the up-stroke.  Different commands may be bound to the up and
780 down strokes, though that is probably not what you want, so be careful.
781
782    For backward compatibility, a key sequence may also be represented by
783 a string.  In this case, it represents the key sequence(s) that would
784 produce that sequence of ASCII characters in a purely ASCII world.  For
785 example, a string containing the ASCII backspace character, `"\^H"',
786 would represent two key sequences: `(control h)' and `backspace'.
787 Binding a command to this will actually bind both of those key
788 sequences.  Likewise for the following pairs:
789
790                 control h       backspace
791                 control i       tab
792                 control m       return
793                 control j       linefeed
794                 control [       escape
795                 control @       control space
796
797    After binding a command to two key sequences with a form like
798
799         (define-key global-map "\^X\^I" 'command-1)
800
801 it is possible to redefine only one of those sequences like so:
802
803         (define-key global-map [(control x) (control i)] 'command-2)
804         (define-key global-map [(control x) tab] 'command-3)
805
806    Of course, all of this applies only when running under a window
807 system.  If you're talking to XEmacs through a TTY connection, you
808 don't get any of these features.
809
810  - Function: event-matches-key-specifier-p EVENT KEY-SPECIFIER
811      This function returns non-`nil' if EVENT matches KEY-SPECIFIER,
812      which can be any valid form representing a key sequence.  This can
813      be useful, e.g., to determine if the user pressed `help-char' or
814      `quit-char'.
815
816 \1f
817 File: lispref.info,  Node: Prefix Keys,  Next: Active Keymaps,  Prev: Key Sequences,  Up: Keymaps
818
819 Prefix Keys
820 ===========
821
822    A "prefix key" has an associated keymap that defines what to do with
823 key sequences that start with the prefix key.  For example, `C-x' is a
824 prefix key, and it uses a keymap that is also stored in the variable
825 `ctl-x-map'.  Here is a list of the standard prefix keys of XEmacs and
826 their keymaps:
827
828    * `help-map' is used for events that follow `C-h'.
829
830    * `mode-specific-map' is for events that follow `C-c'.  This map is
831      not actually mode specific; its name was chosen to be informative
832      for the user in `C-h b' (`display-bindings'), where it describes
833      the main use of the `C-c' prefix key.
834
835    * `ctl-x-map' is the map used for events that follow `C-x'.  This
836      map is also the function definition of `Control-X-prefix'.
837
838    * `ctl-x-4-map' is used for events that follow `C-x 4'.
839
840    * `ctl-x-5-map' is used for events that follow `C-x 5'.
841
842    * The prefix keys `C-x n', `C-x r' and `C-x a' use keymaps that have
843      no special name.
844
845    * `esc-map' is an evil hack that is present for compatibility
846      purposes with Emacs 18.  Defining a key in `esc-map' is equivalent
847      to defining the same key in `global-map' but with the <META>
848      prefix added.  You should *not* use this in your code. (This map is
849      also the function definition of `ESC-prefix'.)
850
851    The binding of a prefix key is the keymap to use for looking up the
852 events that follow the prefix key.  (It may instead be a symbol whose
853 function definition is a keymap.  The effect is the same, but the symbol
854 serves as a name for the prefix key.)  Thus, the binding of `C-x' is
855 the symbol `Control-X-prefix', whose function definition is the keymap
856 for `C-x' commands.  (The same keymap is also the value of `ctl-x-map'.)
857
858    Prefix key definitions can appear in any active keymap.  The
859 definitions of `C-c', `C-x', `C-h' and <ESC> as prefix keys appear in
860 the global map, so these prefix keys are always available.  Major and
861 minor modes can redefine a key as a prefix by putting a prefix key
862 definition for it in the local map or the minor mode's map.  *Note
863 Active Keymaps::.
864
865    If a key is defined as a prefix in more than one active map, then its
866 various definitions are in effect merged: the commands defined in the
867 minor mode keymaps come first, followed by those in the local map's
868 prefix definition, and then by those from the global map.
869
870    In the following example, we make `C-p' a prefix key in the local
871 keymap, in such a way that `C-p' is identical to `C-x'.  Then the
872 binding for `C-p C-f' is the function `find-file', just like `C-x C-f'.
873 The key sequence `C-p 6' is not found in any active keymap.
874
875      (use-local-map (make-sparse-keymap))
876          => nil
877      (local-set-key "\C-p" ctl-x-map)
878          => nil
879      (key-binding "\C-p\C-f")
880          => find-file
881      
882      (key-binding "\C-p6")
883          => nil
884
885  - Function: define-prefix-command SYMBOL &optional MAPVAR
886      This function defines SYMBOL as a prefix command: it creates a
887      keymap and stores it as SYMBOL's function definition.  Storing the
888      symbol as the binding of a key makes the key a prefix key that has
889      a name.  If optional argument MAPVAR is not specified, it also
890      sets SYMBOL as a variable, to have the keymap as its value. (If
891      MAPVAR is given and is not `t', its value is stored as the value
892      of SYMBOL.) The function returns SYMBOL.
893
894      In Emacs version 18, only the function definition of SYMBOL was
895      set, not the value as a variable.
896
897 \1f
898 File: lispref.info,  Node: Active Keymaps,  Next: Key Lookup,  Prev: Prefix Keys,  Up: Keymaps
899
900 Active Keymaps
901 ==============
902
903    XEmacs normally contains many keymaps; at any given time, just a few
904 of them are "active" in that they participate in the interpretation of
905 user input.  These are the global keymap, the current buffer's local
906 keymap, and the keymaps of any enabled minor modes.
907
908    The "global keymap" holds the bindings of keys that are defined
909 regardless of the current buffer, such as `C-f'.  The variable
910 `global-map' holds this keymap, which is always active.
911
912    Each buffer may have another keymap, its "local keymap", which may
913 contain new or overriding definitions for keys.  The current buffer's
914 local keymap is always active except when `overriding-local-map' or
915 `overriding-terminal-local-map' overrides it.  Extents and text
916 properties can specify an alternative local map for certain parts of the
917 buffer; see *Note Extents and Events::.
918
919    Each minor mode may have a keymap; if it does, the keymap is active
920 when the minor mode is enabled.
921
922    The variable `overriding-local-map' and
923 `overriding-terminal-local-map', if non-`nil', specify other local
924 keymaps that override the buffer's local map and all the minor mode
925 keymaps.
926
927    All the active keymaps are used together to determine what command to
928 execute when a key is entered.  XEmacs searches these maps one by one,
929 in order of decreasing precedence, until it finds a binding in one of
930 the maps.
931
932    More specifically:
933
934    For key-presses, the order of keymaps searched is:
935
936    * the `keymap' property of any extent(s) or text properties at point;
937
938    * any applicable minor-mode maps;
939
940    * the current local map of the current buffer;
941
942    * the current global map.
943
944    For mouse-clicks, the order of keymaps searched is:
945
946    * the current local map of the `mouse-grabbed-buffer' if any;
947
948    * the `keymap' property of any extent(s) at the position of the click
949      (this includes modeline extents);
950
951    * the `modeline-map' of the buffer corresponding to the modeline
952      under the mouse (if the click happened over a modeline);
953
954    * the value of `toolbar-map' in the current buffer (if the click
955      happened over a toolbar);
956
957    * the current local map of the buffer under the mouse (does not
958      apply to toolbar clicks);
959
960    * any applicable minor-mode maps;
961
962    * the current global map.
963
964    Note that if `overriding-local-map' or
965 `overriding-terminal-local-map' is non-`nil', *only* those two maps and
966 the current global map are searched.
967
968    The procedure for searching a single keymap is called "key lookup";
969 see *Note Key Lookup::.
970
971    Since every buffer that uses the same major mode normally uses the
972 same local keymap, you can think of the keymap as local to the mode.  A
973 change to the local keymap of a buffer (using `local-set-key', for
974 example) is seen also in the other buffers that share that keymap.
975
976    The local keymaps that are used for Lisp mode, C mode, and several
977 other major modes exist even if they have not yet been used.  These
978 local maps are the values of the variables `lisp-mode-map',
979 `c-mode-map', and so on.  For most other modes, which are less
980 frequently used, the local keymap is constructed only when the mode is
981 used for the first time in a session.
982
983    The minibuffer has local keymaps, too; they contain various
984 completion and exit commands.  *Note Intro to Minibuffers::.
985
986    *Note Standard Keymaps::, for a list of standard keymaps.
987
988  - Function: current-keymaps &optional EVENT-OR-KEYS
989      This function returns a list of the current keymaps that will be
990      searched for bindings.  This lists keymaps such as the current
991      local map and the minor-mode maps, but does not list the parents
992      of those keymaps.  EVENT-OR-KEYS controls which keymaps will be
993      listed.  If EVENT-OR-KEYS is a mouse event (or a vector whose last
994      element is a mouse event), the keymaps for that mouse event will
995      be listed.  Otherwise, the keymaps for key presses will be listed.
996
997  - Variable: global-map
998      This variable contains the default global keymap that maps XEmacs
999      keyboard input to commands.  The global keymap is normally this
1000      keymap.  The default global keymap is a full keymap that binds
1001      `self-insert-command' to all of the printing characters.
1002
1003      It is normal practice to change the bindings in the global map,
1004      but you should not assign this variable any value other than the
1005      keymap it starts out with.
1006
1007  - Function: current-global-map
1008      This function returns the current global keymap.  This is the same
1009      as the value of `global-map' unless you change one or the other.
1010
1011           (current-global-map)
1012           => #<keymap global-map 639 entries 0x221>
1013
1014  - Function: current-local-map
1015      This function returns the current buffer's local keymap, or `nil'
1016      if it has none.  In the following example, the keymap for the
1017      `*scratch*' buffer (using Lisp Interaction mode) has a number of
1018      entries, including one prefix key, `C-x'.
1019
1020           (current-local-map)
1021           => #<keymap lisp-interaction-mode-map 5 entries 0x558>
1022           (describe-bindings-internal (current-local-map))
1023           =>  ; Inserted into the buffer:
1024           backspace     backward-delete-char-untabify
1025           linefeed      eval-print-last-sexp
1026           delete                delete-char
1027           C-j           eval-print-last-sexp
1028           C-x           << Prefix Command >>
1029           M-tab         lisp-complete-symbol
1030           M-;           lisp-indent-for-comment
1031           M-C-i         lisp-complete-symbol
1032           M-C-q         indent-sexp
1033           M-C-x         eval-defun
1034           Alt-backspace backward-kill-sexp
1035           Alt-delete    kill-sexp
1036           
1037           C-x x         edebug-defun
1038
1039  - Function: current-minor-mode-maps
1040      This function returns a list of the keymaps of currently enabled
1041      minor modes.
1042
1043  - Function: use-global-map KEYMAP
1044      This function makes KEYMAP the new current global keymap.  It
1045      returns `nil'.
1046
1047      It is very unusual to change the global keymap.
1048
1049  - Function: use-local-map KEYMAP &optional BUFFER
1050      This function makes KEYMAP the new local keymap of BUFFER.  BUFFER
1051      defaults to the current buffer.  If KEYMAP is `nil', then the
1052      buffer has no local keymap.  `use-local-map' returns `nil'.  Most
1053      major mode commands use this function.
1054
1055  - Variable: minor-mode-map-alist
1056      This variable is an alist describing keymaps that may or may not be
1057      active according to the values of certain variables.  Its elements
1058      look like this:
1059
1060           (VARIABLE . KEYMAP)
1061
1062      The keymap KEYMAP is active whenever VARIABLE has a non-`nil'
1063      value.  Typically VARIABLE is the variable that enables or
1064      disables a minor mode.  *Note Keymaps and Minor Modes::.
1065
1066      Note that elements of `minor-mode-map-alist' do not have the same
1067      structure as elements of `minor-mode-alist'.  The map must be the
1068      CDR of the element; a list with the map as the second element will
1069      not do.
1070
1071      What's more, the keymap itself must appear in the CDR.  It does not
1072      work to store a variable in the CDR and make the map the value of
1073      that variable.
1074
1075      When more than one minor mode keymap is active, their order of
1076      priority is the order of `minor-mode-map-alist'.  But you should
1077      design minor modes so that they don't interfere with each other.
1078      If you do this properly, the order will not matter.
1079
1080      See also `minor-mode-key-binding', above.  See *Note Keymaps and
1081      Minor Modes::, for more information about minor modes.
1082
1083  - Variable: modeline-map
1084      This variable holds the keymap consulted for mouse-clicks on the
1085      modeline of a window.  This variable may be buffer-local; its
1086      value will be looked up in the buffer of the window whose modeline
1087      was clicked upon.
1088
1089  - Variable: toolbar-map
1090      This variable holds the keymap consulted for mouse-clicks over a
1091      toolbar.
1092
1093  - Variable: mouse-grabbed-buffer
1094      If non-`nil', a buffer which should be consulted first for all
1095      mouse activity.  When a mouse-click is processed, it will first be
1096      looked up in the local-map of this buffer, and then through the
1097      normal mechanism if there is no binding for that click.  This
1098      buffer's value of `mode-motion-hook' will be consulted instead of
1099      the `mode-motion-hook' of the buffer of the window under the mouse.
1100      You should *bind* this, not set it.
1101
1102  - Variable: overriding-local-map
1103      If non-`nil', this variable holds a keymap to use instead of the
1104      buffer's local keymap and instead of all the minor mode keymaps.
1105      This keymap, if any, overrides all other maps that would have been
1106      active, except for the current global map.
1107
1108  - Variable: overriding-terminal-local-map
1109      If non-`nil', this variable holds a keymap to use instead of the
1110      buffer's local keymap and instead of all the minor mode keymaps,
1111      but for the selected console only. (In other words, this variable
1112      is always console-local; putting a keymap here only applies to
1113      keystrokes coming from the selected console.  *Note Consoles and
1114      Devices::.) This keymap, if any, overrides all other maps that
1115      would have been active, except for the current global map.
1116