Sync up with r21-4-14-chise-0_21-22.
[chise/xemacs-chise.git-] / info / lispref.info-18
1 This is ../info/lispref.info, produced by makeinfo version 4.0b from
2 lispref/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: Converting Events,  Prev: Working With Events,  Up: Events
54
55 Converting Events
56 -----------------
57
58    XEmacs provides some auxiliary functions for converting between
59 events and other ways of representing keys.  These are useful when
60 working with ASCII strings and with keymaps.
61
62  - Function: character-to-event key-description &optional event console
63           use-console-meta-flag
64      This function converts a keystroke description to an event
65      structure.  KEY-DESCRIPTION is the specification of a key stroke,
66      and EVENT is the event object to fill in.  This function contains
67      knowledge about what the codes "mean"--for example, the number 9 is
68      converted to the character <Tab>, not the distinct character
69      <Control-I>.
70
71      Note that KEY-DESCRIPTION can be an integer, a character, a symbol
72      such as `clear' or a list such as `(control backspace)'.
73
74      If optional arg EVENT is non-`nil', it is modified; otherwise, a
75      new event object is created.  In both cases, the event is returned.
76
77      Optional third arg CONSOLE is the console to store in the event,
78      and defaults to the selected console.
79
80      If KEY-DESCRIPTION is an integer or character, the high bit may be
81      interpreted as the meta key. (This is done for backward
82      compatibility in lots of places.)  If USE-CONSOLE-META-FLAG is
83      `nil', this will always be the case.  If USE-CONSOLE-META-FLAG is
84      non-`nil', the `meta' flag for CONSOLE affects whether the high
85      bit is interpreted as a meta key. (See `set-input-mode'.)  If you
86      don't want this silly meta interpretation done, you should pass in
87      a list containing the character.
88
89      Beware that `character-to-event' and `event-to-character' are not
90      strictly inverse functions, since events contain much more
91      information than the ASCII character set can encode.
92
93  - Function: event-to-character event &optional allow-extra-modifiers
94           allow-meta allow-non-ascii
95      This function returns the closest ASCII approximation to EVENT.
96      If the event isn't a keypress, this returns `nil'.
97
98      If ALLOW-EXTRA-MODIFIERS is non-`nil', then this is lenient in its
99      translation; it will ignore modifier keys other than <control> and
100      <meta>, and will ignore the <shift> modifier on those characters
101      which have no shifted ASCII equivalent (<Control-Shift-A> for
102      example, will be mapped to the same ASCII code as <Control-A>).
103
104      If ALLOW-META is non-`nil', then the <Meta> modifier will be
105      represented by turning on the high bit of the byte returned;
106      otherwise, `nil' will be returned for events containing the <Meta>
107      modifier.
108
109      If ALLOW-NON-ASCII is non-`nil', then characters which are present
110      in the prevailing character set (*note variable
111      `character-set-property': Keymaps.) will be returned as their code
112      in that character set, instead of the return value being
113      restricted to ASCII.
114
115      Note that specifying both ALLOW-META and ALLOW-NON-ASCII is
116      ambiguous, as both use the high bit; <M-x> and <oslash> will be
117      indistinguishable.
118
119  - Function: events-to-keys events &optional no-mice
120      Given a vector of event objects, this function returns a vector of
121      key descriptors, or a string (if they all fit in the ASCII range).
122      Optional arg NO-MICE means that button events are not allowed.
123
124 \1f
125 File: lispref.info,  Node: Reading Input,  Next: Waiting,  Prev: Events,  Up: Command Loop
126
127 Reading Input
128 =============
129
130    The editor command loop reads keyboard input using the function
131 `next-event' and constructs key sequences out of the events using
132 `dispatch-event'.  Lisp programs can also use the function
133 `read-key-sequence', which reads input a key sequence at a time.  See
134 also `momentary-string-display' in *Note Temporary Displays::, and
135 `sit-for' in *Note Waiting::.  *Note Terminal Input::, for functions
136 and variables for controlling terminal input modes and debugging
137 terminal input.
138
139    For higher-level input facilities, see *Note Minibuffers::.
140
141 * Menu:
142
143 * Key Sequence Input::          How to read one key sequence.
144 * Reading One Event::           How to read just one event.
145 * Dispatching an Event::        What to do with an event once it has been read.
146 * Quoted Character Input::      Asking the user to specify a character.
147 * Peeking and Discarding::      How to reread or throw away input events.
148
149 \1f
150 File: lispref.info,  Node: Key Sequence Input,  Next: Reading One Event,  Up: Reading Input
151
152 Key Sequence Input
153 ------------------
154
155    Lisp programs can read input a key sequence at a time by calling
156 `read-key-sequence'; for example, `describe-key' uses it to read the
157 key to describe.
158
159  - Function: read-key-sequence prompt &optional continue-echo
160           dont-downcase-last
161      This function reads a sequence of keystrokes or mouse clicks and
162      returns it as a vector of event objects read.  It keeps reading
163      events until it has accumulated a full key sequence; that is,
164      enough to specify a non-prefix command using the currently active
165      keymaps.
166
167      The vector and the event objects it contains are freshly created
168      (and so will not be side-effected by subsequent calls to this
169      function).
170
171      The function `read-key-sequence' suppresses quitting: `C-g' typed
172      while reading with this function works like any other character,
173      and does not set `quit-flag'.  *Note Quitting::.
174
175      The argument PROMPT is either a string to be displayed in the echo
176      area as a prompt, or `nil', meaning not to display a prompt.
177
178      Second optional arg CONTINUE-ECHO non-`nil' means this key echoes
179      as a continuation of the previous key.
180
181      Third optional arg DONT-DOWNCASE-LAST non-`nil' means do not
182      convert the last event to lower case.  (Normally any upper case
183      event is converted to lower case if the original event is
184      undefined and the lower case equivalent is defined.) This argument
185      is provided mostly for FSF compatibility; the equivalent effect
186      can be achieved more generally by binding
187      `retry-undefined-key-binding-unshifted' to `nil' around the call
188      to `read-key-sequence'.
189
190      If the user selects a menu item while we are prompting for a key
191      sequence, the returned value will be a vector of a single
192      menu-selection event (a misc-user event).  An error will be
193      signalled if you pass this value to `lookup-key' or a related
194      function.
195
196      In the example below, the prompt `?' is displayed in the echo area,
197      and the user types `C-x C-f'.
198
199           (read-key-sequence "?")
200           
201           ---------- Echo Area ----------
202           ?C-x C-f
203           ---------- Echo Area ----------
204           
205                => [#<keypress-event control-X> #<keypress-event control-F>]
206
207    If an input character is an upper-case letter and has no key binding,
208 but its lower-case equivalent has one, then `read-key-sequence'
209 converts the character to lower case.  Note that `lookup-key' does not
210 perform case conversion in this way.
211
212 \1f
213 File: lispref.info,  Node: Reading One Event,  Next: Dispatching an Event,  Prev: Key Sequence Input,  Up: Reading Input
214
215 Reading One Event
216 -----------------
217
218    The lowest level functions for command input are those which read a
219 single event.  These functions often make a distinction between
220 "command events", which are user actions (keystrokes and mouse
221 actions), and other events, which serve as communication between XEmacs
222 and the window system.
223
224  - Function: next-event &optional event prompt
225      This function reads and returns the next available event from the
226      window system or terminal driver, waiting if necessary until an
227      event is available.  Pass this object to `dispatch-event' to
228      handle it. If an event object is supplied, it is filled in and
229      returned; otherwise a new event object will be created.
230
231      Events can come directly from the user, from a keyboard macro, or
232      from `unread-command-events'.
233
234      In most cases, the function `next-command-event' is more
235      appropriate.
236
237  - Function: next-command-event &optional event prompt
238      This function returns the next available "user" event from the
239      window system or terminal driver.  Pass this object to
240      `dispatch-event' to handle it.  If an event object is supplied, it
241      is filled in and returned, otherwise a new event object will be
242      created.
243
244      The event returned will be a keyboard, mouse press, or mouse
245      release event.  If there are non-command events available (mouse
246      motion, sub-process output, etc) then these will be executed (with
247      `dispatch-event') and discarded.  This function is provided as a
248      convenience; it is equivalent to the Lisp code
249
250                   (while (progn
251                            (next-event event)
252                            (not (or (key-press-event-p event)
253                                     (button-press-event-p event)
254                                     (button-release-event-p event)
255                                     (menu-event-p event))))
256                      (dispatch-event event))
257
258      Here is what happens if you call `next-command-event' and then
259      press the right-arrow function key:
260
261           (next-command-event)
262                => #<keypress-event right>
263
264  - Function: read-char
265      This function reads and returns a character of command input.  If a
266      mouse click is detected, an error is signalled.  The character
267      typed is returned as an ASCII value.  This function is retained for
268      compatibility with Emacs 18, and is most likely the wrong thing
269      for you to be using: consider using `next-command-event' instead.
270
271  - Function: enqueue-eval-event function object
272      This function adds an eval event to the back of the queue.  The
273      eval event will be the next event read after all pending events.
274
275 \1f
276 File: lispref.info,  Node: Dispatching an Event,  Next: Quoted Character Input,  Prev: Reading One Event,  Up: Reading Input
277
278 Dispatching an Event
279 --------------------
280
281  - Function: dispatch-event event
282      Given an event object returned by `next-event', this function
283      executes it.  This is the basic function that makes XEmacs respond
284      to user input; it also deals with notifications from the window
285      system (such as Expose events).
286
287 \1f
288 File: lispref.info,  Node: Quoted Character Input,  Next: Peeking and Discarding,  Prev: Dispatching an Event,  Up: Reading Input
289
290 Quoted Character Input
291 ----------------------
292
293    You can use the function `read-quoted-char' to ask the user to
294 specify a character, and allow the user to specify a control or meta
295 character conveniently, either literally or as an octal character code.
296 The command `quoted-insert' uses this function.
297
298  - Function: read-quoted-char &optional prompt
299      This function is like `read-char', except that if the first
300      character read is an octal digit (0-7), it reads up to two more
301      octal digits (but stopping if a non-octal digit is found) and
302      returns the character represented by those digits in octal.
303
304      Quitting is suppressed when the first character is read, so that
305      the user can enter a `C-g'.  *Note Quitting::.
306
307      If PROMPT is supplied, it specifies a string for prompting the
308      user.  The prompt string is always displayed in the echo area,
309      followed by a single `-'.
310
311      In the following example, the user types in the octal number 177
312      (which is 127 in decimal).
313
314           (read-quoted-char "What character")
315           
316           ---------- Echo Area ----------
317           What character-177
318           ---------- Echo Area ----------
319           
320                => 127
321
322 \1f
323 File: lispref.info,  Node: Peeking and Discarding,  Prev: Quoted Character Input,  Up: Reading Input
324
325 Miscellaneous Event Input Features
326 ----------------------------------
327
328    This section describes how to "peek ahead" at events without using
329 them up, how to check for pending input, and how to discard pending
330 input.
331
332    See also the variables `last-command-event' and `last-command-char'
333 (*Note Command Loop Info::).
334
335  - Variable: unread-command-events
336      This variable holds a list of events waiting to be read as command
337      input.  The events are used in the order they appear in the list,
338      and removed one by one as they are used.
339
340      The variable is needed because in some cases a function reads a
341      event and then decides not to use it.  Storing the event in this
342      variable causes it to be processed normally, by the command loop
343      or by the functions to read command input.
344
345      For example, the function that implements numeric prefix arguments
346      reads any number of digits.  When it finds a non-digit event, it
347      must unread the event so that it can be read normally by the
348      command loop.  Likewise, incremental search uses this feature to
349      unread events with no special meaning in a search, because these
350      events should exit the search and then execute normally.
351
352
353  - Variable: unread-command-event
354      This variable holds a single event to be read as command input.
355
356      This variable is mostly obsolete now that you can use
357      `unread-command-events' instead; it exists only to support programs
358      written for versions of XEmacs prior to 19.12.
359
360  - Function: input-pending-p
361      This function determines whether any command input is currently
362      available to be read.  It returns immediately, with value `t' if
363      there is available input, `nil' otherwise.  On rare occasions it
364      may return `t' when no input is available.
365
366  - Variable: last-input-event
367      This variable is set to the last keyboard or mouse button event
368      received.
369
370      This variable is off limits: you may not set its value or modify
371      the event that is its value, as it is destructively modified by
372      `read-key-sequence'.  If you want to keep a pointer to this value,
373      you must use `copy-event'.
374
375      Note that this variable is an alias for `last-input-char' in FSF
376      Emacs.
377
378      In the example below, a character is read (the character `1').  It
379      becomes the value of `last-input-event', while `C-e' (from the
380      `C-x C-e' command used to evaluate this expression) remains the
381      value of `last-command-event'.
382
383           (progn (print (next-command-event))
384                  (print last-command-event)
385                  last-input-event)
386                -| #<keypress-event 1>
387                -| #<keypress-event control-E>
388                => #<keypress-event 1>
389
390  - Variable: last-input-char
391      If the value of `last-input-event' is a keyboard event, then this
392      is the nearest ASCII equivalent to it.  Remember that there is
393      _not_ a 1:1 mapping between keyboard events and ASCII characters:
394      the set of keyboard events is much larger, so writing code that
395      examines this variable to determine what key has been typed is bad
396      practice, unless you are certain that it will be one of a small
397      set of characters.
398
399      This function exists for compatibility with Emacs version 18.
400
401  - Function: discard-input
402      This function discards the contents of the terminal input buffer
403      and cancels any keyboard macro that might be in the process of
404      definition.  It returns `nil'.
405
406      In the following example, the user may type a number of characters
407      right after starting the evaluation of the form.  After the
408      `sleep-for' finishes sleeping, `discard-input' discards any
409      characters typed during the sleep.
410
411           (progn (sleep-for 2)
412                  (discard-input))
413                => nil
414
415 \1f
416 File: lispref.info,  Node: Waiting,  Next: Quitting,  Prev: Reading Input,  Up: Command Loop
417
418 Waiting for Elapsed Time or Input
419 =================================
420
421    The wait functions are designed to wait for a certain amount of time
422 to pass or until there is input.  For example, you may wish to pause in
423 the middle of a computation to allow the user time to view the display.
424 `sit-for' pauses and updates the screen, and returns immediately if
425 input comes in, while `sleep-for' pauses without updating the screen.
426
427    Note that in FSF Emacs, the commands `sit-for' and `sleep-for' take
428 two arguments to specify the time (one integer and one float value),
429 instead of a single argument that can be either an integer or a float.
430
431  - Function: sit-for seconds &optional nodisplay
432      This function performs redisplay (provided there is no pending
433      input from the user), then waits SECONDS seconds, or until input is
434      available.  The result is `t' if `sit-for' waited the full time
435      with no input arriving (see `input-pending-p' in *Note Peeking and
436      Discarding::).  Otherwise, the value is `nil'.
437
438      The argument SECONDS need not be an integer.  If it is a floating
439      point number, `sit-for' waits for a fractional number of seconds.
440
441      Redisplay is normally preempted if input arrives, and does not
442      happen at all if input is available before it starts. (You can
443      force screen updating in such a case by using `force-redisplay'.
444      *Note Refresh Screen::.) If there is no input pending, you can
445      force an update with no delay by using `(sit-for 0)'.
446
447      If NODISPLAY is non-`nil', then `sit-for' does not redisplay, but
448      it still returns as soon as input is available (or when the
449      timeout elapses).
450
451      The usual purpose of `sit-for' is to give the user time to read
452      text that you display.
453
454  - Function: sleep-for seconds
455      This function simply pauses for SECONDS seconds without updating
456      the display.  This function pays no attention to available input.
457      It returns `nil'.
458
459      The argument SECONDS need not be an integer.  If it is a floating
460      point number, `sleep-for' waits for a fractional number of seconds.
461
462      Use `sleep-for' when you wish to guarantee a delay.
463
464    *Note Time of Day::, for functions to get the current time.
465
466 \1f
467 File: lispref.info,  Node: Quitting,  Next: Prefix Command Arguments,  Prev: Waiting,  Up: Command Loop
468
469 Quitting
470 ========
471
472    Typing `C-g' while a Lisp function is running causes XEmacs to
473 "quit" whatever it is doing.  This means that control returns to the
474 innermost active command loop.
475
476    Typing `C-g' while the command loop is waiting for keyboard input
477 does not cause a quit; it acts as an ordinary input character.  In the
478 simplest case, you cannot tell the difference, because `C-g' normally
479 runs the command `keyboard-quit', whose effect is to quit.  However,
480 when `C-g' follows a prefix key, the result is an undefined key.  The
481 effect is to cancel the prefix key as well as any prefix argument.
482
483    In the minibuffer, `C-g' has a different definition: it aborts out
484 of the minibuffer.  This means, in effect, that it exits the minibuffer
485 and then quits.  (Simply quitting would return to the command loop
486 _within_ the minibuffer.)  The reason why `C-g' does not quit directly
487 when the command reader is reading input is so that its meaning can be
488 redefined in the minibuffer in this way.  `C-g' following a prefix key
489 is not redefined in the minibuffer, and it has its normal effect of
490 canceling the prefix key and prefix argument.  This too would not be
491 possible if `C-g' always quit directly.
492
493    When `C-g' does directly quit, it does so by setting the variable
494 `quit-flag' to `t'.  XEmacs checks this variable at appropriate times
495 and quits if it is not `nil'.  Setting `quit-flag' non-`nil' in any way
496 thus causes a quit.
497
498    At the level of C code, quitting cannot happen just anywhere; only
499 at the special places that check `quit-flag'.  The reason for this is
500 that quitting at other places might leave an inconsistency in XEmacs's
501 internal state.  Because quitting is delayed until a safe place,
502 quitting cannot make XEmacs crash.
503
504    Certain functions such as `read-key-sequence' or `read-quoted-char'
505 prevent quitting entirely even though they wait for input.  Instead of
506 quitting, `C-g' serves as the requested input.  In the case of
507 `read-key-sequence', this serves to bring about the special behavior of
508 `C-g' in the command loop.  In the case of `read-quoted-char', this is
509 so that `C-q' can be used to quote a `C-g'.
510
511    You can prevent quitting for a portion of a Lisp function by binding
512 the variable `inhibit-quit' to a non-`nil' value.  Then, although `C-g'
513 still sets `quit-flag' to `t' as usual, the usual result of this--a
514 quit--is prevented.  Eventually, `inhibit-quit' will become `nil'
515 again, such as when its binding is unwound at the end of a `let' form.
516 At that time, if `quit-flag' is still non-`nil', the requested quit
517 happens immediately.  This behavior is ideal when you wish to make sure
518 that quitting does not happen within a "critical section" of the
519 program.
520
521    In some functions (such as `read-quoted-char'), `C-g' is handled in
522 a special way that does not involve quitting.  This is done by reading
523 the input with `inhibit-quit' bound to `t', and setting `quit-flag' to
524 `nil' before `inhibit-quit' becomes `nil' again.  This excerpt from the
525 definition of `read-quoted-char' shows how this is done; it also shows
526 that normal quitting is permitted after the first character of input.
527
528      (defun read-quoted-char (&optional prompt)
529        "...DOCUMENTATION..."
530        (let ((count 0) (code 0) char)
531          (while (< count 3)
532            (let ((inhibit-quit (zerop count))
533                  (help-form nil))
534              (and prompt (message "%s-" prompt))
535              (setq char (read-char))
536              (if inhibit-quit (setq quit-flag nil)))
537            ...)
538          (logand 255 code)))
539
540  - Variable: quit-flag
541      If this variable is non-`nil', then XEmacs quits immediately,
542      unless `inhibit-quit' is non-`nil'.  Typing `C-g' ordinarily sets
543      `quit-flag' non-`nil', regardless of `inhibit-quit'.
544
545  - Variable: inhibit-quit
546      This variable determines whether XEmacs should quit when
547      `quit-flag' is set to a value other than `nil'.  If `inhibit-quit'
548      is non-`nil', then `quit-flag' has no special effect.
549
550  - Command: keyboard-quit
551      This function signals the `quit' condition with `(signal 'quit
552      nil)'.  This is the same thing that quitting does.  (See `signal'
553      in *Note Errors::.)
554
555    You can specify a character other than `C-g' to use for quitting.
556 See the function `set-input-mode' in *Note Terminal Input::.
557
558 \1f
559 File: lispref.info,  Node: Prefix Command Arguments,  Next: Recursive Editing,  Prev: Quitting,  Up: Command Loop
560
561 Prefix Command Arguments
562 ========================
563
564    Most XEmacs commands can use a "prefix argument", a number specified
565 before the command itself.  (Don't confuse prefix arguments with prefix
566 keys.)  The prefix argument is at all times represented by a value,
567 which may be `nil', meaning there is currently no prefix argument.
568 Each command may use the prefix argument or ignore it.
569
570    There are two representations of the prefix argument: "raw" and
571 "numeric".  The editor command loop uses the raw representation
572 internally, and so do the Lisp variables that store the information, but
573 commands can request either representation.
574
575    Here are the possible values of a raw prefix argument:
576
577    * `nil', meaning there is no prefix argument.  Its numeric value is
578      1, but numerous commands make a distinction between `nil' and the
579      integer 1.
580
581    * An integer, which stands for itself.
582
583    * A list of one element, which is an integer.  This form of prefix
584      argument results from one or a succession of `C-u''s with no
585      digits.  The numeric value is the integer in the list, but some
586      commands make a distinction between such a list and an integer
587      alone.
588
589    * The symbol `-'.  This indicates that `M--' or `C-u -' was typed,
590      without following digits.  The equivalent numeric value is -1, but
591      some commands make a distinction between the integer -1 and the
592      symbol `-'.
593
594    We illustrate these possibilities by calling the following function
595 with various prefixes:
596
597      (defun display-prefix (arg)
598        "Display the value of the raw prefix arg."
599        (interactive "P")
600        (message "%s" arg))
601
602 Here are the results of calling `display-prefix' with various raw
603 prefix arguments:
604
605              M-x display-prefix  -| nil
606      
607      C-u     M-x display-prefix  -| (4)
608      
609      C-u C-u M-x display-prefix  -| (16)
610      
611      C-u 3   M-x display-prefix  -| 3
612      
613      M-3     M-x display-prefix  -| 3      ; (Same as `C-u 3'.)
614      
615      C-3     M-x display-prefix  -| 3      ; (Same as `C-u 3'.)
616      
617      C-u -   M-x display-prefix  -| -
618      
619      M--     M-x display-prefix  -| -      ; (Same as `C-u -'.)
620      
621      C--     M-x display-prefix  -| -      ; (Same as `C-u -'.)
622      
623      C-u - 7 M-x display-prefix  -| -7
624      
625      M-- 7   M-x display-prefix  -| -7     ; (Same as `C-u -7'.)
626      
627      C-- 7   M-x display-prefix  -| -7     ; (Same as `C-u -7'.)
628
629    XEmacs uses two variables to store the prefix argument: `prefix-arg'
630 and `current-prefix-arg'.  Commands such as `universal-argument' that
631 set up prefix arguments for other commands store them in `prefix-arg'.
632 In contrast, `current-prefix-arg' conveys the prefix argument to the
633 current command, so setting it has no effect on the prefix arguments
634 for future commands.
635
636    Normally, commands specify which representation to use for the prefix
637 argument, either numeric or raw, in the `interactive' declaration.
638 (*Note Using Interactive::.)  Alternatively, functions may look at the
639 value of the prefix argument directly in the variable
640 `current-prefix-arg', but this is less clean.
641
642  - Function: prefix-numeric-value raw
643      This function returns the numeric meaning of a valid raw prefix
644      argument value, RAW.  The argument may be a symbol, a number, or a
645      list.  If it is `nil', the value 1 is returned; if it is `-', the
646      value -1 is returned; if it is a number, that number is returned;
647      if it is a list, the CAR of that list (which should be a number) is
648      returned.
649
650  - Variable: current-prefix-arg
651      This variable holds the raw prefix argument for the _current_
652      command.  Commands may examine it directly, but the usual way to
653      access it is with `(interactive "P")'.
654
655  - Variable: prefix-arg
656      The value of this variable is the raw prefix argument for the
657      _next_ editing command.  Commands that specify prefix arguments for
658      the following command work by setting this variable.
659
660    Do not call the functions `universal-argument', `digit-argument', or
661 `negative-argument' unless you intend to let the user enter the prefix
662 argument for the _next_ command.
663
664  - Command: universal-argument
665      This command reads input and specifies a prefix argument for the
666      following command.  Don't call this command yourself unless you
667      know what you are doing.
668
669  - Command: digit-argument arg
670      This command adds to the prefix argument for the following
671      command.  The argument ARG is the raw prefix argument as it was
672      before this command; it is used to compute the updated prefix
673      argument.  Don't call this command yourself unless you know what
674      you are doing.
675
676  - Command: negative-argument arg
677      This command adds to the numeric argument for the next command.
678      The argument ARG is the raw prefix argument as it was before this
679      command; its value is negated to form the new prefix argument.
680      Don't call this command yourself unless you know what you are
681      doing.
682
683 \1f
684 File: lispref.info,  Node: Recursive Editing,  Next: Disabling Commands,  Prev: Prefix Command Arguments,  Up: Command Loop
685
686 Recursive Editing
687 =================
688
689    The XEmacs command loop is entered automatically when XEmacs starts
690 up.  This top-level invocation of the command loop never exits; it keeps
691 running as long as XEmacs does.  Lisp programs can also invoke the
692 command loop.  Since this makes more than one activation of the command
693 loop, we call it "recursive editing".  A recursive editing level has
694 the effect of suspending whatever command invoked it and permitting the
695 user to do arbitrary editing before resuming that command.
696
697    The commands available during recursive editing are the same ones
698 available in the top-level editing loop and defined in the keymaps.
699 Only a few special commands exit the recursive editing level; the others
700 return to the recursive editing level when they finish.  (The special
701 commands for exiting are always available, but they do nothing when
702 recursive editing is not in progress.)
703
704    All command loops, including recursive ones, set up all-purpose error
705 handlers so that an error in a command run from the command loop will
706 not exit the loop.
707
708    Minibuffer input is a special kind of recursive editing.  It has a
709 few special wrinkles, such as enabling display of the minibuffer and the
710 minibuffer window, but fewer than you might suppose.  Certain keys
711 behave differently in the minibuffer, but that is only because of the
712 minibuffer's local map; if you switch windows, you get the usual XEmacs
713 commands.
714
715    To invoke a recursive editing level, call the function
716 `recursive-edit'.  This function contains the command loop; it also
717 contains a call to `catch' with tag `exit', which makes it possible to
718 exit the recursive editing level by throwing to `exit' (*note Catch and
719 Throw::).  If you throw a value other than `t', then `recursive-edit'
720 returns normally to the function that called it.  The command `C-M-c'
721 (`exit-recursive-edit') does this.  Throwing a `t' value causes
722 `recursive-edit' to quit, so that control returns to the command loop
723 one level up.  This is called "aborting", and is done by `C-]'
724 (`abort-recursive-edit').
725
726    Most applications should not use recursive editing, except as part of
727 using the minibuffer.  Usually it is more convenient for the user if you
728 change the major mode of the current buffer temporarily to a special
729 major mode, which should have a command to go back to the previous mode.
730 (The `e' command in Rmail uses this technique.)  Or, if you wish to
731 give the user different text to edit "recursively", create and select a
732 new buffer in a special mode.  In this mode, define a command to
733 complete the processing and go back to the previous buffer.  (The `m'
734 command in Rmail does this.)
735
736    Recursive edits are useful in debugging.  You can insert a call to
737 `debug' into a function definition as a sort of breakpoint, so that you
738 can look around when the function gets there.  `debug' invokes a
739 recursive edit but also provides the other features of the debugger.
740
741    Recursive editing levels are also used when you type `C-r' in
742 `query-replace' or use `C-x q' (`kbd-macro-query').
743
744  - Command: recursive-edit
745      This function invokes the editor command loop.  It is called
746      automatically by the initialization of XEmacs, to let the user
747      begin editing.  When called from a Lisp program, it enters a
748      recursive editing level.
749
750      In the following example, the function `simple-rec' first advances
751      point one word, then enters a recursive edit, printing out a
752      message in the echo area.  The user can then do any editing
753      desired, and then type `C-M-c' to exit and continue executing
754      `simple-rec'.
755
756           (defun simple-rec ()
757             (forward-word 1)
758             (message "Recursive edit in progress")
759             (recursive-edit)
760             (forward-word 1))
761                => simple-rec
762           (simple-rec)
763                => nil
764
765  - Command: exit-recursive-edit
766      This function exits from the innermost recursive edit (including
767      minibuffer input).  Its definition is effectively `(throw 'exit
768      nil)'.
769
770  - Command: abort-recursive-edit
771      This function aborts the command that requested the innermost
772      recursive edit (including minibuffer input), by signaling `quit'
773      after exiting the recursive edit.  Its definition is effectively
774      `(throw 'exit t)'.  *Note Quitting::.
775
776  - Command: top-level
777      This function exits all recursive editing levels; it does not
778      return a value, as it jumps completely out of any computation
779      directly back to the main command loop.
780
781  - Function: recursion-depth
782      This function returns the current depth of recursive edits.  When
783      no recursive edit is active, it returns 0.
784
785 \1f
786 File: lispref.info,  Node: Disabling Commands,  Next: Command History,  Prev: Recursive Editing,  Up: Command Loop
787
788 Disabling Commands
789 ==================
790
791    "Disabling a command" marks the command as requiring user
792 confirmation before it can be executed.  Disabling is used for commands
793 which might be confusing to beginning users, to prevent them from using
794 the commands by accident.
795
796    The low-level mechanism for disabling a command is to put a
797 non-`nil' `disabled' property on the Lisp symbol for the command.
798 These properties are normally set up by the user's `.emacs' file with
799 Lisp expressions such as this:
800
801      (put 'upcase-region 'disabled t)
802
803 For a few commands, these properties are present by default and may be
804 removed by the `.emacs' file.
805
806    If the value of the `disabled' property is a string, the message
807 saying the command is disabled includes that string.  For example:
808
809      (put 'delete-region 'disabled
810           "Text deleted this way cannot be yanked back!\n")
811
812    *Note Disabling: (xemacs)Disabling, for the details on what happens
813 when a disabled command is invoked interactively.  Disabling a command
814 has no effect on calling it as a function from Lisp programs.
815
816  - Command: enable-command command
817      Allow COMMAND to be executed without special confirmation from now
818      on, and (if the user confirms) alter the user's `.emacs' file so
819      that this will apply to future sessions.
820
821  - Command: disable-command command
822      Require special confirmation to execute COMMAND from now on, and
823      (if the user confirms) alter the user's `.emacs' file so that this
824      will apply to future sessions.
825
826  - Variable: disabled-command-hook
827      This normal hook is run instead of a disabled command, when the
828      user invokes the disabled command interactively.  The hook
829      functions can use `this-command-keys' to determine what the user
830      typed to run the command, and thus find the command itself.  *Note
831      Hooks::.
832
833      By default, `disabled-command-hook' contains a function that asks
834      the user whether to proceed.
835
836 \1f
837 File: lispref.info,  Node: Command History,  Next: Keyboard Macros,  Prev: Disabling Commands,  Up: Command Loop
838
839 Command History
840 ===============
841
842    The command loop keeps a history of the complex commands that have
843 been executed, to make it convenient to repeat these commands.  A
844 "complex command" is one for which the interactive argument reading
845 uses the minibuffer.  This includes any `M-x' command, any `M-:'
846 command, and any command whose `interactive' specification reads an
847 argument from the minibuffer.  Explicit use of the minibuffer during
848 the execution of the command itself does not cause the command to be
849 considered complex.
850
851  - Variable: command-history
852      This variable's value is a list of recent complex commands, each
853      represented as a form to evaluate.  It continues to accumulate all
854      complex commands for the duration of the editing session, but all
855      but the first (most recent) thirty elements are deleted when a
856      garbage collection takes place (*note Garbage Collection::).
857
858           command-history
859           => ((switch-to-buffer "chistory.texi")
860               (describe-key "^X^[")
861               (visit-tags-table "~/emacs/src/")
862               (find-tag "repeat-complex-command"))
863
864    This history list is actually a special case of minibuffer history
865 (*note Minibuffer History::), with one special twist: the elements are
866 expressions rather than strings.
867
868    There are a number of commands devoted to the editing and recall of
869 previous commands.  The commands `repeat-complex-command', and
870 `list-command-history' are described in the user manual (*note
871 Repetition: (xemacs)Repetition.).  Within the minibuffer, the history
872 commands used are the same ones available in any minibuffer.
873
874 \1f
875 File: lispref.info,  Node: Keyboard Macros,  Prev: Command History,  Up: Command Loop
876
877 Keyboard Macros
878 ===============
879
880    A "keyboard macro" is a canned sequence of input events that can be
881 considered a command and made the definition of a key.  The Lisp
882 representation of a keyboard macro is a string or vector containing the
883 events.  Don't confuse keyboard macros with Lisp macros (*note
884 Macros::).
885
886  - Function: execute-kbd-macro macro &optional count
887      This function executes MACRO as a sequence of events.  If MACRO is
888      a string or vector, then the events in it are executed exactly as
889      if they had been input by the user.  The sequence is _not_
890      expected to be a single key sequence; normally a keyboard macro
891      definition consists of several key sequences concatenated.
892
893      If MACRO is a symbol, then its function definition is used in
894      place of MACRO.  If that is another symbol, this process repeats.
895      Eventually the result should be a string or vector.  If the result
896      is not a symbol, string, or vector, an error is signaled.
897
898      The argument COUNT is a repeat count; MACRO is executed that many
899      times.  If COUNT is omitted or `nil', MACRO is executed once.  If
900      it is 0, MACRO is executed over and over until it encounters an
901      error or a failing search.
902
903  - Variable: executing-macro
904      This variable contains the string or vector that defines the
905      keyboard macro that is currently executing.  It is `nil' if no
906      macro is currently executing.  A command can test this variable to
907      behave differently when run from an executing macro.  Do not set
908      this variable yourself.
909
910  - Variable: defining-kbd-macro
911      This variable indicates whether a keyboard macro is being defined.
912      A command can test this variable to behave differently while a
913      macro is being defined.  The commands `start-kbd-macro' and
914      `end-kbd-macro' set this variable--do not set it yourself.
915
916  - Variable: last-kbd-macro
917      This variable is the definition of the most recently defined
918      keyboard macro.  Its value is a string or vector, or `nil'.
919
920    The commands are described in the user's manual (*note Keyboard
921 Macros: (xemacs)Keyboard Macros.).
922
923 \1f
924 File: lispref.info,  Node: Keymaps,  Next: Menus,  Prev: Command Loop,  Up: Top
925
926 Keymaps
927 *******
928
929    The bindings between input events and commands are recorded in data
930 structures called "keymaps".  Each binding in a keymap associates (or
931 "binds") an individual event type either with another keymap or with a
932 command.  When an event is bound to a keymap, that keymap is used to
933 look up the next input event; this continues until a command is found.
934 The whole process is called "key lookup".
935
936 * Menu:
937
938 * Keymap Terminology::       Definitions of terms pertaining to keymaps.
939 * Format of Keymaps::        What a keymap looks like as a Lisp object.
940 * Creating Keymaps::         Functions to create and copy keymaps.
941 * Inheritance and Keymaps::  How one keymap can inherit the bindings
942                                 of another keymap.
943 * Key Sequences::            How to specify key sequences.
944 * Prefix Keys::              Defining a key with a keymap as its definition.
945 * Active Keymaps::           Each buffer has a local keymap
946                                 to override the standard (global) bindings.
947                                 A minor mode can also override them.
948 * Key Lookup::               How extracting elements from keymaps works.
949 * Functions for Key Lookup:: How to request key lookup.
950 * Changing Key Bindings::    Redefining a key in a keymap.
951 * Key Binding Commands::     Interactive interfaces for redefining keys.
952 * Scanning Keymaps::         Looking through all keymaps, for printing help.
953 * Other Keymap Functions::   Miscellaneous keymap functions.
954
955 \1f
956 File: lispref.info,  Node: Keymap Terminology,  Next: Format of Keymaps,  Up: Keymaps
957
958 Keymap Terminology
959 ==================
960
961    A "keymap" is a table mapping event types to definitions (which can
962 be any Lisp objects, though only certain types are meaningful for
963 execution by the command loop).  Given an event (or an event type) and a
964 keymap, XEmacs can get the event's definition.  Events mapped in keymaps
965 include keypresses, button presses, and button releases (*note
966 Events::).
967
968    A sequence of input events that form a unit is called a "key
969 sequence", or "key" for short.  A sequence of one event is always a key
970 sequence, and so are some multi-event sequences.
971
972    A keymap determines a binding or definition for any key sequence.  If
973 the key sequence is a single event, its binding is the definition of the
974 event in the keymap.  The binding of a key sequence of more than one
975 event is found by an iterative process: the binding of the first event
976 is found, and must be a keymap; then the second event's binding is found
977 in that keymap, and so on until all the events in the key sequence are
978 used up.
979
980    If the binding of a key sequence is a keymap, we call the key
981 sequence a "prefix key".  Otherwise, we call it a "complete key"
982 (because no more events can be added to it).  If the binding is `nil',
983 we call the key "undefined".  Examples of prefix keys are `C-c', `C-x',
984 and `C-x 4'.  Examples of defined complete keys are `X', <RET>, and
985 `C-x 4 C-f'.  Examples of undefined complete keys are `C-x C-g', and
986 `C-c 3'.  *Note Prefix Keys::, for more details.
987
988    The rule for finding the binding of a key sequence assumes that the
989 intermediate bindings (found for the events before the last) are all
990 keymaps; if this is not so, the sequence of events does not form a
991 unit--it is not really a key sequence.  In other words, removing one or
992 more events from the end of any valid key must always yield a prefix
993 key.  For example, `C-f C-n' is not a key; `C-f' is not a prefix key,
994 so a longer sequence starting with `C-f' cannot be a key.
995
996    Note that the set of possible multi-event key sequences depends on
997 the bindings for prefix keys; therefore, it can be different for
998 different keymaps, and can change when bindings are changed.  However,
999 a one-event sequence is always a key sequence, because it does not
1000 depend on any prefix keys for its well-formedness.
1001
1002    At any time, several primary keymaps are "active"--that is, in use
1003 for finding key bindings.  These are the "global map", which is shared
1004 by all buffers; the "local keymap", which is usually associated with a
1005 specific major mode; and zero or more "minor mode keymaps", which
1006 belong to currently enabled minor modes.  (Not all minor modes have
1007 keymaps.)  The local keymap bindings shadow (i.e., take precedence
1008 over) the corresponding global bindings.  The minor mode keymaps shadow
1009 both local and global keymaps.  *Note Active Keymaps::, for details.
1010
1011 \1f
1012 File: lispref.info,  Node: Format of Keymaps,  Next: Creating Keymaps,  Prev: Keymap Terminology,  Up: Keymaps
1013
1014 Format of Keymaps
1015 =================
1016
1017    A keymap is a primitive type that associates events with their
1018 bindings.  Note that this is different from Emacs 18 and FSF Emacs,
1019 where keymaps are lists.
1020
1021  - Function: keymapp object
1022      This function returns `t' if OBJECT is a keymap, `nil' otherwise.
1023
1024 \1f
1025 File: lispref.info,  Node: Creating Keymaps,  Next: Inheritance and Keymaps,  Prev: Format of Keymaps,  Up: Keymaps
1026
1027 Creating Keymaps
1028 ================
1029
1030    Here we describe the functions for creating keymaps.
1031
1032  - Function: make-keymap &optional name
1033      This function constructs and returns a new keymap object.  All
1034      entries in it are `nil', meaning "command undefined".
1035
1036      Optional argument NAME specifies a name to assign to the keymap,
1037      as in `set-keymap-name'.  This name is only a debugging
1038      convenience; it is not used except when printing the keymap.
1039
1040  - Function: make-sparse-keymap &optional name
1041      This function constructs and returns a new keymap object.  All
1042      entries in it are `nil', meaning "command undefined".  The only
1043      difference between this function and `make-keymap' is that this
1044      function returns a "smaller" keymap (one that is expected to
1045      contain fewer entries).  As keymaps dynamically resize, this
1046      distinction is not great.
1047
1048      Optional argument NAME specifies a name to assign to the keymap,
1049      as in `set-keymap-name'.  This name is only a debugging
1050      convenience; it is not used except when printing the keymap.
1051
1052  - Function: set-keymap-name keymap new-name
1053      This function assigns a "name" to a keymap.  The name is only a
1054      debugging convenience; it is not used except when printing the
1055      keymap.
1056
1057  - Function: keymap-name keymap
1058      This function returns the "name" of a keymap, as assigned using
1059      `set-keymap-name'.
1060
1061  - Function: copy-keymap keymap
1062      This function returns a copy of KEYMAP.  Any keymaps that appear
1063      directly as bindings in KEYMAP are also copied recursively, and so
1064      on to any number of levels.  However, recursive copying does not
1065      take place when the definition of a character is a symbol whose
1066      function definition is a keymap; the same symbol appears in the
1067      new copy.
1068
1069           (setq map (copy-keymap (current-local-map)))
1070           => #<keymap 3 entries 0x21f80>
1071           
1072           (eq map (current-local-map))
1073               => nil
1074
1075 \1f
1076 File: lispref.info,  Node: Inheritance and Keymaps,  Next: Key Sequences,  Prev: Creating Keymaps,  Up: Keymaps
1077
1078 Inheritance and Keymaps
1079 =======================
1080
1081    A keymap can inherit the bindings of other keymaps.  The other
1082 keymaps are called the keymap's "parents", and are set with
1083 `set-keymap-parents'.  When searching for a binding for a key sequence
1084 in a particular keymap, that keymap itself will first be searched;
1085 then, if no binding was found in the map and it has parents, the first
1086 parent keymap will be searched; then that keymap's parent will be
1087 searched, and so on, until either a binding for the key sequence is
1088 found, or a keymap without a parent is encountered.  At this point, the
1089 search will continue with the next parent of the most recently
1090 encountered keymap that has another parent, etc.  Essentially, a
1091 depth-first search of all the ancestors of the keymap is conducted.
1092
1093    `(current-global-map)' is the default parent of all keymaps.
1094
1095  - Function: set-keymap-parents keymap parents
1096      This function sets the parent keymaps of KEYMAP to the list
1097      PARENTS.
1098
1099      If you change the bindings in one of the keymaps in PARENTS using
1100      `define-key' or other key-binding functions, these changes are
1101      visible in KEYMAP unless shadowed by bindings in that map or in
1102      earlier-searched ancestors.  The converse is not true: if you use
1103      `define-key' to change KEYMAP, that affects the bindings in that
1104      map, but has no effect on any of the keymaps in PARENTS.
1105
1106  - Function: keymap-parents keymap
1107      This function returns the list of parent keymaps of KEYMAP, or
1108      `nil' if KEYMAP has no parents.
1109
1110    As an alternative to specifying a parent, you can also specify a
1111 "default binding" that is used whenever a key is not otherwise bound in
1112 the keymap.  This is useful for terminal emulators, for example, which
1113 may want to trap all keystrokes and pass them on in some modified
1114 format.  Note that if you specify a default binding for a keymap,
1115 neither the keymap's parents nor the current global map are searched for
1116 key bindings.
1117
1118  - Function: set-keymap-default-binding keymap command
1119      This function sets the default binding of KEYMAP to COMMAND, or
1120      `nil' if no default is desired.
1121
1122  - Function: keymap-default-binding keymap
1123      This function returns the default binding of KEYMAP, or `nil' if
1124      it has none.
1125