Resorted; add some missing Morohashi's Daikanwa characters; add
[chise/xemacs-chise.git-] / info / lispref.info-19
1 This is ../info/lispref.info, produced by makeinfo version 4.0 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: Key Lookup,  Next: Functions for Key Lookup,  Prev: Active Keymaps,  Up: Keymaps
54
55 Key Lookup
56 ==========
57
58    "Key lookup" is the process of finding the binding of a key sequence
59 from a given keymap.  Actual execution of the binding is not part of
60 key lookup.
61
62    Key lookup uses just the event type of each event in the key
63 sequence; the rest of the event is ignored.  In fact, a key sequence
64 used for key lookup may designate mouse events with just their types
65 (symbols) instead of with entire mouse events (lists).  *Note Events::.
66 Such a pseudo-key-sequence is insufficient for `command-execute', but
67 it is sufficient for looking up or rebinding a key.
68
69    When the key sequence consists of multiple events, key lookup
70 processes the events sequentially: the binding of the first event is
71 found, and must be a keymap; then the second event's binding is found in
72 that keymap, and so on until all the events in the key sequence are used
73 up.  (The binding thus found for the last event may or may not be a
74 keymap.)  Thus, the process of key lookup is defined in terms of a
75 simpler process for looking up a single event in a keymap.  How that is
76 done depends on the type of object associated with the event in that
77 keymap.
78
79    Let's use the term "keymap entry" to describe the value found by
80 looking up an event type in a keymap.  (This doesn't include the item
81 string and other extra elements in menu key bindings because
82 `lookup-key' and other key lookup functions don't include them in the
83 returned value.)  While any Lisp object may be stored in a keymap as a
84 keymap entry, not all make sense for key lookup.  Here is a list of the
85 meaningful kinds of keymap entries:
86
87 `nil'
88      `nil' means that the events used so far in the lookup form an
89      undefined key.  When a keymap fails to mention an event type at
90      all, and has no default binding, that is equivalent to a binding
91      of `nil' for that event type.
92
93 KEYMAP
94      The events used so far in the lookup form a prefix key.  The next
95      event of the key sequence is looked up in KEYMAP.
96
97 COMMAND
98      The events used so far in the lookup form a complete key, and
99      COMMAND is its binding.  *Note What Is a Function::.
100
101 ARRAY
102      The array (either a string or a vector) is a keyboard macro.  The
103      events used so far in the lookup form a complete key, and the
104      array is its binding.  See *Note Keyboard Macros::, for more
105      information. (Note that you cannot use a shortened form of a key
106      sequence here, such as `(control y)'; you must use the full form
107      `[(control y)]'.  *Note Key Sequences::.)
108
109 LIST
110      The meaning of a list depends on the types of the elements of the
111      list.
112
113         * If the CAR of LIST is `lambda', then the list is a lambda
114           expression.  This is presumed to be a command, and is treated
115           as such (see above).
116
117         * If the CAR of LIST is a keymap and the CDR is an event type,
118           then this is an "indirect entry":
119
120                (OTHERMAP . OTHERTYPE)
121
122           When key lookup encounters an indirect entry, it looks up
123           instead the binding of OTHERTYPE in OTHERMAP and uses that.
124
125           This feature permits you to define one key as an alias for
126           another key.  For example, an entry whose CAR is the keymap
127           called `esc-map' and whose CDR is 32 (the code for <SPC>)
128           means, "Use the global binding of `Meta-<SPC>', whatever that
129           may be."
130
131 SYMBOL
132      The function definition of SYMBOL is used in place of SYMBOL.  If
133      that too is a symbol, then this process is repeated, any number of
134      times.  Ultimately this should lead to an object that is a keymap,
135      a command or a keyboard macro.  A list is allowed if it is a
136      keymap or a command, but indirect entries are not understood when
137      found via symbols.
138
139      Note that keymaps and keyboard macros (strings and vectors) are not
140      valid functions, so a symbol with a keymap, string, or vector as
141      its function definition is invalid as a function.  It is, however,
142      valid as a key binding.  If the definition is a keyboard macro,
143      then the symbol is also valid as an argument to `command-execute'
144      (*note Interactive Call::).
145
146      The symbol `undefined' is worth special mention: it means to treat
147      the key as undefined.  Strictly speaking, the key is defined, and
148      its binding is the command `undefined'; but that command does the
149      same thing that is done automatically for an undefined key: it
150      rings the bell (by calling `ding') but does not signal an error.
151
152      `undefined' is used in local keymaps to override a global key
153      binding and make the key "undefined" locally.  A local binding of
154      `nil' would fail to do this because it would not override the
155      global binding.
156
157 ANYTHING ELSE
158      If any other type of object is found, the events used so far in the
159      lookup form a complete key, and the object is its binding, but the
160      binding is not executable as a command.
161
162    In short, a keymap entry may be a keymap, a command, a keyboard
163 macro, a symbol that leads to one of them, or an indirection or `nil'.
164
165 \1f
166 File: lispref.info,  Node: Functions for Key Lookup,  Next: Changing Key Bindings,  Prev: Key Lookup,  Up: Keymaps
167
168 Functions for Key Lookup
169 ========================
170
171    Here are the functions and variables pertaining to key lookup.
172
173  - Function: lookup-key keymap key &optional accept-defaults
174      This function returns the definition of KEY in KEYMAP.  If the
175      string or vector KEY is not a valid key sequence according to the
176      prefix keys specified in KEYMAP (which means it is "too long" and
177      has extra events at the end), then the value is a number, the
178      number of events at the front of KEY that compose a complete key.
179
180      If ACCEPT-DEFAULTS is non-`nil', then `lookup-key' considers
181      default bindings as well as bindings for the specific events in
182      KEY.  Otherwise, `lookup-key' reports only bindings for the
183      specific sequence KEY, ignoring default bindings except when you
184      explicitly ask about them.
185
186      All the other functions described in this chapter that look up
187      keys use `lookup-key'.
188
189           (lookup-key (current-global-map) "\C-x\C-f")
190               => find-file
191           (lookup-key (current-global-map) "\C-x\C-f12345")
192               => 2
193
194      If KEY begins with the character whose value is contained in
195      `meta-prefix-char', that character is implicitly removed and the
196      <META> modifier added to the key.  Thus, the first example below is
197      handled by conversion into the second example.
198
199           (lookup-key (current-global-map) "\ef")
200               => forward-word
201           (lookup-key (current-global-map) "\M-f")
202               => forward-word
203
204      Unlike `read-key-sequence', this function does not modify the
205      specified events in ways that discard information (*note Key
206      Sequence Input::).  In particular, it does not convert letters to
207      lower case.
208
209  - Command: undefined
210      Used in keymaps to undefine keys.  If a key sequence is defined to
211      this, invoking this key sequence causes a "key undefined" error,
212      just as if the key sequence had no binding.
213
214  - Function: key-binding key &optional accept-defaults
215      This function returns the binding for KEY in the current keymaps,
216      trying all the active keymaps.  The result is `nil' if KEY is
217      undefined in the keymaps.
218
219      The argument ACCEPT-DEFAULTS controls checking for default
220      bindings, as in `lookup-key' (above).
221
222           (key-binding "\C-x\C-f")
223               => find-file
224           (key-binding '(control home))
225               => beginning-of-buffer
226           (key-binding [escape escape escape])
227               => keyboard-escape-quit
228
229  - Function: local-key-binding key &optional accept-defaults
230      This function returns the binding for KEY in the current local
231      keymap, or `nil' if it is undefined there.
232
233      The argument ACCEPT-DEFAULTS controls checking for default
234      bindings, as in `lookup-key' (above).
235
236  - Function: global-key-binding key &optional accept-defaults
237      This function returns the binding for command KEY in the current
238      global keymap, or `nil' if it is undefined there.
239
240      The argument ACCEPT-DEFAULTS controls checking for default
241      bindings, as in `lookup-key' (above).
242
243  - Function: minor-mode-key-binding key &optional accept-defaults
244      This function returns a list of all the active minor mode bindings
245      of KEY.  More precisely, it returns an alist of pairs `(MODENAME .
246      BINDING)', where MODENAME is the variable that enables the minor
247      mode, and BINDING is KEY's binding in that mode.  If KEY has no
248      minor-mode bindings, the value is `nil'.
249
250      If the first binding is not a prefix command, all subsequent
251      bindings from other minor modes are omitted, since they would be
252      completely shadowed.  Similarly, the list omits non-prefix
253      bindings that follow prefix bindings.
254
255      The argument ACCEPT-DEFAULTS controls checking for default
256      bindings, as in `lookup-key' (above).
257
258  - Variable: meta-prefix-char
259      This variable is the meta-prefix character code.  It is used when
260      translating a two-character sequence to a meta character so it can
261      be looked up in a keymap.  For useful results, the value should be
262      a prefix event (*note Prefix Keys::).  The default value is `?\^['
263      (integer 27), which is the ASCII character usually produced by the
264      <ESC> key.
265
266      As long as the value of `meta-prefix-char' remains `?\^[', key
267      lookup translates `<ESC> b' into `M-b', which is normally defined
268      as the `backward-word' command.  However, if you set
269      `meta-prefix-char' to `?\^X' (i.e. the keystroke `C-x') or its
270      equivalent ASCII code `24', then XEmacs will translate `C-x b'
271      (whose standard binding is the `switch-to-buffer' command) into
272      `M-b'.
273
274           meta-prefix-char                    ; The default value.
275                => ?\^[   ; Under XEmacs 20.
276                => 27     ; Under XEmacs 19.
277           (key-binding "\eb")
278                => backward-word
279           ?\C-x                               ; The print representation
280                                                      ;   of a character.
281                => ?\^X   ; Under XEmacs 20.
282                => 24     ; Under XEmacs 19.
283           (setq meta-prefix-char 24)
284                => 24
285           (key-binding "\C-xb")
286                => backward-word            ; Now, typing `C-x b' is
287                                               ;   like typing `M-b'.
288           
289           (setq meta-prefix-char ?\e)          ; Avoid confusion!
290                                                ; Restore the default value!
291                => ?\^[   ; Under XEmacs 20.
292                => 27     ; Under XEmacs 19.
293
294 \1f
295 File: lispref.info,  Node: Changing Key Bindings,  Next: Key Binding Commands,  Prev: Functions for Key Lookup,  Up: Keymaps
296
297 Changing Key Bindings
298 =====================
299
300    The way to rebind a key is to change its entry in a keymap.  If you
301 change a binding in the global keymap, the change is effective in all
302 buffers (though it has no direct effect in buffers that shadow the
303 global binding with a local one).  If you change the current buffer's
304 local map, that usually affects all buffers using the same major mode.
305 The `global-set-key' and `local-set-key' functions are convenient
306 interfaces for these operations (*note Key Binding Commands::).  You
307 can also use `define-key', a more general function; then you must
308 specify explicitly the map to change.
309
310    The way to specify the key sequence that you want to rebind is
311 described above (*note Key Sequences::).
312
313    For the functions below, an error is signaled if KEYMAP is not a
314 keymap or if KEY is not a string or vector representing a key sequence.
315 You can use event types (symbols) as shorthand for events that are
316 lists.
317
318  - Function: define-key keymap key binding
319      This function sets the binding for KEY in KEYMAP.  (If KEY is more
320      than one event long, the change is actually made in another keymap
321      reached from KEYMAP.)  The argument BINDING can be any Lisp
322      object, but only certain types are meaningful.  (For a list of
323      meaningful types, see *Note Key Lookup::.)  The value returned by
324      `define-key' is BINDING.
325
326      Every prefix of KEY must be a prefix key (i.e., bound to a keymap)
327      or undefined; otherwise an error is signaled.
328
329      If some prefix of KEY is undefined, then `define-key' defines it
330      as a prefix key so that the rest of KEY may be defined as
331      specified.
332
333    Here is an example that creates a sparse keymap and makes a number of
334 bindings in it:
335
336      (setq map (make-sparse-keymap))
337          => #<keymap 0 entries 0xbee>
338      (define-key map "\C-f" 'forward-char)
339          => forward-char
340      map
341          => #<keymap 1 entry 0xbee>
342      (describe-bindings-internal map)
343      =>   ; (Inserted in buffer)
344      C-f             forward-char
345      
346      ;; Build sparse submap for `C-x' and bind `f' in that.
347      (define-key map "\C-xf" 'forward-word)
348          => forward-word
349      map
350          => #<keymap 2 entries 0xbee>
351      (describe-bindings-internal map)
352      =>   ; (Inserted in buffer)
353      C-f             forward-char
354      C-x             << Prefix Command >>
355      
356      C-x f           forward-word
357      
358      ;; Bind `C-p' to the `ctl-x-map'.
359      (define-key map "\C-p" ctl-x-map)
360      ;; `ctl-x-map'
361      => #<keymap Control-X-prefix 77 entries 0x3bf>
362      
363      ;; Bind `C-f' to `foo' in the `ctl-x-map'.
364      (define-key map "\C-p\C-f" 'foo)
365      => foo
366      map
367          => #<keymap 3 entries 0xbee>
368      (describe-bindings-internal map)
369      =>   ; (Inserted in buffer)
370      C-f             forward-char
371      C-p             << Prefix command Control-X-prefix >>
372      C-x             << Prefix Command >>
373      
374      C-p tab         indent-rigidly
375      C-p $           set-selective-display
376      C-p '           expand-abbrev
377      C-p (           start-kbd-macro
378      C-p )           end-kbd-macro
379         ...
380      C-p C-x         exchange-point-and-mark
381      C-p C-z         suspend-or-iconify-emacs
382      C-p M-escape    repeat-complex-command
383      C-p M-C-[       repeat-complex-command
384      
385      C-x f           forward-word
386      
387      C-p 4 .         find-tag-other-window
388         ...
389      C-p 4 C-o       display-buffer
390      
391      C-p 5 0         delete-frame
392         ...
393      C-p 5 C-f       find-file-other-frame
394      
395         ...
396      
397      C-p a i g       inverse-add-global-abbrev
398      C-p a i l       inverse-add-mode-abbrev
399
400 Note that storing a new binding for `C-p C-f' actually works by
401 changing an entry in `ctl-x-map', and this has the effect of changing
402 the bindings of both `C-p C-f' and `C-x C-f' in the default global map.
403
404  - Function: substitute-key-definition olddef newdef keymap &optional
405           oldmap
406      This function replaces OLDDEF with NEWDEF for any keys in KEYMAP
407      that were bound to OLDDEF.  In other words, OLDDEF is replaced
408      with NEWDEF wherever it appears.  The function returns `nil'.
409
410      For example, this redefines `C-x C-f', if you do it in an XEmacs
411      with standard bindings:
412
413           (substitute-key-definition
414            'find-file 'find-file-read-only (current-global-map))
415
416      If OLDMAP is non-`nil', then its bindings determine which keys to
417      rebind.  The rebindings still happen in NEWMAP, not in OLDMAP.
418      Thus, you can change one map under the control of the bindings in
419      another.  For example,
420
421           (substitute-key-definition
422             'delete-backward-char 'my-funny-delete
423             my-map global-map)
424
425      puts the special deletion command in `my-map' for whichever keys
426      are globally bound to the standard deletion command.
427
428
429  - Function: suppress-keymap keymap &optional nodigits
430      This function changes the contents of the full keymap KEYMAP by
431      making all the printing characters undefined.  More precisely, it
432      binds them to the command `undefined'.  This makes ordinary
433      insertion of text impossible.  `suppress-keymap' returns `nil'.
434
435      If NODIGITS is `nil', then `suppress-keymap' defines digits to run
436      `digit-argument', and `-' to run `negative-argument'.  Otherwise
437      it makes them undefined like the rest of the printing characters.
438
439      The `suppress-keymap' function does not make it impossible to
440      modify a buffer, as it does not suppress commands such as `yank'
441      and `quoted-insert'.  To prevent any modification of a buffer, make
442      it read-only (*note Read Only Buffers::).
443
444      Since this function modifies KEYMAP, you would normally use it on
445      a newly created keymap.  Operating on an existing keymap that is
446      used for some other purpose is likely to cause trouble; for
447      example, suppressing `global-map' would make it impossible to use
448      most of XEmacs.
449
450      Most often, `suppress-keymap' is used to initialize local keymaps
451      of modes such as Rmail and Dired where insertion of text is not
452      desirable and the buffer is read-only.  Here is an example taken
453      from the file `emacs/lisp/dired.el', showing how the local keymap
454      for Dired mode is set up:
455
456             ...
457             (setq dired-mode-map (make-keymap))
458             (suppress-keymap dired-mode-map)
459             (define-key dired-mode-map "r" 'dired-rename-file)
460             (define-key dired-mode-map "\C-d" 'dired-flag-file-deleted)
461             (define-key dired-mode-map "d" 'dired-flag-file-deleted)
462             (define-key dired-mode-map "v" 'dired-view-file)
463             (define-key dired-mode-map "e" 'dired-find-file)
464             (define-key dired-mode-map "f" 'dired-find-file)
465             ...
466
467 \1f
468 File: lispref.info,  Node: Key Binding Commands,  Next: Scanning Keymaps,  Prev: Changing Key Bindings,  Up: Keymaps
469
470 Commands for Binding Keys
471 =========================
472
473    This section describes some convenient interactive interfaces for
474 changing key bindings.  They work by calling `define-key'.
475
476    People often use `global-set-key' in their `.emacs' file for simple
477 customization.  For example,
478
479      (global-set-key "\C-x\C-\\" 'next-line)
480
481 or
482
483      (global-set-key [(control ?x) (control ?\\)] 'next-line)
484
485 or
486
487      (global-set-key [?\C-x ?\C-\\] 'next-line)
488
489 redefines `C-x C-\' to move down a line.
490
491      (global-set-key [(meta button1)] 'mouse-set-point)
492
493 redefines the first (leftmost) mouse button, typed with the Meta key, to
494 set point where you click.
495
496  - Command: global-set-key key definition
497      This function sets the binding of KEY in the current global map to
498      DEFINITION.
499
500           (global-set-key KEY DEFINITION)
501           ==
502           (define-key (current-global-map) KEY DEFINITION)
503
504  - Command: global-unset-key key
505      This function removes the binding of KEY from the current global
506      map.
507
508      One use of this function is in preparation for defining a longer
509      key that uses KEY as a prefix--which would not be allowed if KEY
510      has a non-prefix binding.  For example:
511
512           (global-unset-key "\C-l")
513               => nil
514           (global-set-key "\C-l\C-l" 'redraw-display)
515               => nil
516
517      This function is implemented simply using `define-key':
518
519           (global-unset-key KEY)
520           ==
521           (define-key (current-global-map) KEY nil)
522
523  - Command: local-set-key key definition
524      This function sets the binding of KEY in the current local keymap
525      to DEFINITION.
526
527           (local-set-key KEY DEFINITION)
528           ==
529           (define-key (current-local-map) KEY DEFINITION)
530
531  - Command: local-unset-key key
532      This function removes the binding of KEY from the current local
533      map.
534
535           (local-unset-key KEY)
536           ==
537           (define-key (current-local-map) KEY nil)
538
539 \1f
540 File: lispref.info,  Node: Scanning Keymaps,  Next: Other Keymap Functions,  Prev: Key Binding Commands,  Up: Keymaps
541
542 Scanning Keymaps
543 ================
544
545    This section describes functions used to scan all the current
546 keymaps, or all keys within a keymap, for the sake of printing help
547 information.
548
549  - Function: accessible-keymaps keymap &optional prefix
550      This function returns a list of all the keymaps that can be
551      accessed (via prefix keys) from KEYMAP.  The value is an
552      association list with elements of the form `(KEY . MAP)', where
553      KEY is a prefix key whose definition in KEYMAP is MAP.
554
555      The elements of the alist are ordered so that the KEY increases in
556      length.  The first element is always `([] . KEYMAP)', because the
557      specified keymap is accessible from itself with a prefix of no
558      events.
559
560      If PREFIX is given, it should be a prefix key sequence; then
561      `accessible-keymaps' includes only the submaps whose prefixes start
562      with PREFIX.  These elements look just as they do in the value of
563      `(accessible-keymaps)'; the only difference is that some elements
564      are omitted.
565
566      In the example below, the returned alist indicates that the key
567      `C-x', which is displayed as `[(control x)]', is a prefix key
568      whose definition is the keymap `#<keymap ((control x) #<keymap
569      emacs-lisp-mode-map 8 entries 0x546>) 1 entry 0x8a2>'. (The strange
570      notation for the keymap's name indicates that this is an internal
571      submap of `emacs-lisp-mode-map'.  This is because
572      `lisp-interaction-mode-map' has set up `emacs-lisp-mode-map' as
573      its parent, and `lisp-interaction-mode-map' defines no key
574      sequences beginning with `C-x'.)
575
576           (current-local-map)
577           => #<keymap lisp-interaction-mode-map 5 entries 0x558>
578           (accessible-keymaps (current-local-map))
579           =>(([] . #<keymap lisp-interaction-mode-map 5 entries 0x558>)
580               ([(control x)] .
581                #<keymap ((control x) #<keymap emacs-lisp-mode-map 8 entries 0x546>)
582                         1 entry 0x8a2>))
583
584      The following example shows the results of calling
585      `accessible-keymaps' on a large, complex keymap.  Notice how some
586      keymaps were given explicit names using `set-keymap-name'; those
587      submaps without explicit names are given descriptive names
588      indicating their relationship to their enclosing keymap.
589
590           (accessible-keymaps (current-global-map))
591           => (([] . #<keymap global-map 639 entries 0x221>)
592              ([(control c)] . #<keymap mode-specific-command-prefix 1 entry 0x3cb>)
593              ([(control h)] . #<keymap help-map 33 entries 0x4ec>)
594              ([(control x)] . #<keymap Control-X-prefix 77 entries 0x3bf>)
595              ([(meta escape)] .
596                 #<keymap ((meta escape) #<keymap global-map 639 entries 0x221>)
597                          3 entries 0x3e0>)
598              ([(meta control \[)] .
599                 #<keymap ((meta escape) #<keymap global-map 639 entries 0x221>)
600                          3 entries 0x3e0>)
601              ([f1] . #<keymap help-map 33 entries 0x4ec>)
602              ([(control x) \4] . #<keymap ctl-x-4-prefix 9 entries 0x3c5>)
603              ([(control x) \5] . #<keymap ctl-x-5-prefix 8 entries 0x3c8>)
604              ([(control x) \6] . #<keymap 13 entries 0x4d2>)
605              ([(control x) a] .
606                 #<keymap (a #<keymap Control-X-prefix 77 entries 0x3bf>)
607                          8 entries 0x3ef>)
608              ([(control x) n] . #<keymap narrowing-prefix 3 entries 0x3dd>)
609              ([(control x) r] . #<keymap rectangle-prefix 18 entries 0x3e9>)
610              ([(control x) v] . #<keymap vc-prefix-map 13 entries 0x60e>)
611              ([(control x) a i] .
612                #<keymap (i #<keymap (a #<keymap Control-X-prefix 77 entries 0x3bf>)
613                                     8 entries 0x3ef>)
614                         2 entries 0x3f5>))
615
616  - Function: map-keymap function keymap &optional sort-first
617      This function applies FUNCTION to each element of `KEYMAP'.
618      FUNCTION will be called with two arguments: a key-description
619      list, and the binding.  The order in which the elements of the
620      keymap are passed to the function is unspecified.  If the function
621      inserts new elements into the keymap, it may or may not be called
622      with them later.  No element of the keymap will ever be passed to
623      the function more than once.
624
625      The function will not be called on elements of this keymap's
626      parents (*note Inheritance and Keymaps::) or upon keymaps which
627      are contained within this keymap (multi-character definitions).
628      It will be called on <META> characters since they are not really
629      two-character sequences.
630
631      If the optional third argument SORT-FIRST is non-`nil', then the
632      elements of the keymap will be passed to the mapper function in a
633      canonical order.  Otherwise, they will be passed in hash (that is,
634      random) order, which is faster.
635
636  - Function: keymap-fullness keymap
637      This function returns the number of bindings in the keymap.
638
639  - Function: where-is-internal definition &optional keymaps firstonly
640           noindirect event-or-keys
641      This function returns a list of key sequences (of any length) that
642      are bound to DEFINITION in a set of keymaps.
643
644      The argument DEFINITION can be any object; it is compared with all
645      keymap entries using `eq'.
646
647      KEYMAPS can be either a keymap (meaning search in that keymap and
648      the current global keymap) or a list of keymaps (meaning search in
649      exactly those keymaps and no others).  If KEYMAPS is nil, search
650      in the currently applicable maps for EVENT-OR-KEYS.
651
652      If KEYMAP is a keymap, then the maps searched are KEYMAP and the
653      global keymap.  If KEYMAP is a list of keymaps, then the maps
654      searched are exactly those keymaps, and no others.  If KEYMAP is
655      `nil', then the maps used are the current active keymaps for
656      EVENT-OR-KEYS (this is equivalent to specifying `(current-keymaps
657      EVENT-OR-KEYS)' as the argument to KEYMAPS).
658
659      If FIRSTONLY is non-`nil', then the value is a single vector
660      representing the first key sequence found, rather than a list of
661      all possible key sequences.
662
663      If NOINDIRECT is non-`nil', `where-is-internal' doesn't follow
664      indirect keymap bindings.  This makes it possible to search for an
665      indirect definition itself.
666
667      This function is used by `where-is' (*note Help: (emacs)Help.).
668
669           (where-is-internal 'describe-function)
670               => ([(control h) d] [(control h) f] [f1 d] [f1 f])
671
672  - Function: describe-bindings-internal map &optional all shadow prefix
673           mouse-only-p
674      This function inserts (into the current buffer) a list of all
675      defined keys and their definitions in MAP.  Optional second
676      argument ALL says whether to include even "uninteresting"
677      definitions, i.e.  symbols with a non-`nil' `suppress-keymap'
678      property.  Third argument SHADOW is a list of keymaps whose
679      bindings shadow those of map; if a binding is present in any
680      shadowing map, it is not printed.  Fourth argument PREFIX, if
681      non-`nil', should be a key sequence; only bindings which start
682      with that key sequence will be printed.  Fifth argument
683      MOUSE-ONLY-P says to only print bindings for mouse clicks.
684
685    `describe-bindings-internal' is used to implement the help command
686 `describe-bindings'.
687
688  - Command: describe-bindings prefix mouse-only-p
689      This function creates a listing of all defined keys and their
690      definitions.  It writes the listing in a buffer named `*Help*' and
691      displays it in a window.
692
693      If PREFIX is non-`nil', it should be a prefix key; then the
694      listing includes only keys that start with PREFIX.
695
696      When several characters with consecutive ASCII codes have the same
697      definition, they are shown together, as `FIRSTCHAR..LASTCHAR'.  In
698      this instance, you need to know the ASCII codes to understand
699      which characters this means.  For example, in the default global
700      map, the characters `<SPC> .. ~' are described by a single line.
701      <SPC> is ASCII 32, `~' is ASCII 126, and the characters between
702      them include all the normal printing characters, (e.g., letters,
703      digits, punctuation, etc.); all these characters are bound to
704      `self-insert-command'.
705
706      If the second argument (prefix arg, interactively) is non-`nil'
707      then only the mouse bindings are displayed.
708
709 \1f
710 File: lispref.info,  Node: Other Keymap Functions,  Prev: Scanning Keymaps,  Up: Keymaps
711
712 Other Keymap Functions
713 ======================
714
715  - Function: set-keymap-prompt keymap new-prompt
716      This function sets the "prompt" of KEYMAP to string NEW-PROMPT, or
717      `nil' if no prompt is desired.  The prompt is shown in the
718      echo-area when reading a key-sequence to be looked-up in this
719      keymap.
720
721  - Function: keymap-prompt keymap &optional use-inherited
722      This function returns the "prompt" of the given keymap.  If
723      USE-INHERITED is non-`nil', any parent keymaps will also be
724      searched for a prompt.
725
726 \1f
727 File: lispref.info,  Node: Menus,  Next: Dialog Boxes,  Prev: Keymaps,  Up: Top
728
729 Menus
730 *****
731
732 * Menu:
733
734 * Menu Format::         Format of a menu description.
735 * Menubar Format::      How to specify a menubar.
736 * Menubar::             Functions for controlling the menubar.
737 * Modifying Menus::     Modifying a menu description.
738 * Pop-Up Menus::        Functions for specifying pop-up menus.
739 * Menu Filters::        Filter functions for the default menubar.
740 * Menu Accelerators::   Using and controlling menu accelerator keys
741 * Buffers Menu::        The menu that displays the list of buffers.
742
743 \1f
744 File: lispref.info,  Node: Menu Format,  Next: Menubar Format,  Up: Menus
745
746 Format of Menus
747 ===============
748
749    A menu is described using a "menu description", which is a list of
750 menu items, keyword-value pairs, strings, and submenus.  The menu
751 description specifies which items are present in the menu, what function
752 each item invokes, and whether the item is selectable or not.  Pop-up
753 menus are directly described with a menu description, while menubars are
754 described slightly differently (see below).
755
756    The first element of a menu must be a string, which is the name of
757 the menu.  This is the string that will be displayed in the parent menu
758 or menubar, if any.  This string is not displayed in the menu itself,
759 except in the case of the top level pop-up menu, where there is no
760 parent.  In this case, the string will be displayed at the top of the
761 menu if `popup-menu-titles' is non-`nil'.
762
763    Immediately following the first element there may optionally be up
764 to four keyword-value pairs, as follows:
765
766 `:included FORM'
767      This can be used to control the visibility of a menu.  The form is
768      evaluated and the menu will be omitted if the result is `nil'.
769
770 `:config SYMBOL'
771      This is an efficient shorthand for `:included (memq SYMBOL
772      menubar-configuration)'.  See the variable `menubar-configuration'.
773
774 `:filter FUNCTION'
775      A menu filter is used to sensitize or incrementally create a
776      submenu only when it is selected by the user and not every time
777      the menubar is activated.  The filter function is passed the list
778      of menu items in the submenu and must return a list of menu items
779      to be used for the menu.  It is called only when the menu is about
780      to be displayed, so other menus may already be displayed.  Vile
781      and terrible things will happen if a menu filter function changes
782      the current buffer, window, or frame.  It also should not raise,
783      lower, or iconify any frames.  Basically, the filter function
784      should have no side-effects.
785
786 `:accelerator KEY'
787      A menu accelerator is a keystroke which can be pressed while the
788      menu is visible which will immediately activate the item.  KEY
789      must be a char or the symbol name of a key.  *Note Menu
790      Accelerators::.
791
792    The rest of the menu consists of elements as follows:
793
794    * A "menu item", which is a vector in the following form:
795
796           `[ NAME CALLBACK :KEYWORD VALUE :KEYWORD VALUE ... ]'
797
798      NAME is a string, the name of the menu item; it is the string to
799      display on the menu.  It is filtered through the resource
800      database, so it is possible for resources to override what string
801      is actually displayed.
802
803      CALLBACK is a form that will be invoked when the menu item is
804      selected.  If the callback of a menu item is a symbol, then it
805      must name a command.  It will be invoked with
806      `call-interactively'.  If it is a list, then it is evaluated with
807      `eval'.
808
809      The valid keywords and their meanings are described below.
810
811      Note that for compatibility purposes, the form
812
813           `[ NAME CALLBACK ACTIVE-P ]'
814
815      is also accepted and is equivalent to
816
817           `[ NAME CALLBACK :active ACTIVE-P ]'
818
819      and the form
820
821           `[ NAME CALLBACK ACTIVE-P SUFFIX]'
822
823      is accepted and is equivalent to
824
825           `[ NAME CALLBACK :active ACTIVE-P :suffix SUFFIX]'
826
827      However, these older forms are deprecated and should generally not
828      be used.
829
830    * If an element of a menu is a string, then that string will be
831      presented in the menu as unselectable text.
832
833    * If an element of a menu is a string consisting solely of hyphens,
834      then that item will be presented as a solid horizontal line.
835
836    * If an element of a menu is a string beginning with `--:', then a
837      particular sort of horizontal line will be displayed, as follows:
838
839     `"--:singleLine"'
840           A solid horizontal line.  This is equivalent to a string
841           consisting solely of hyphens.
842
843     `"--:doubleLine"'
844           A solid double horizontal line.
845
846     `"--:singleDashedLine"'
847           A dashed horizontal line.
848
849     `"--:doubleDashedLine"'
850           A dashed double horizontal line.
851
852     `"--:noLine"'
853           No line (but a small space is left).
854
855     `"--:shadowEtchedIn"'
856           A solid horizontal line with a 3-d recessed appearance.
857
858     `"--:shadowEtchedOut"'
859           A solid horizontal line with a 3-d pushed-out appearance.
860
861     `"--:shadowDoubleEtchedIn"'
862           A solid double horizontal line with a 3-d recessed appearance.
863
864     `"--:shadowDoubleEtchedOut"'
865           A solid double horizontal line with a 3-d pushed-out
866           appearance.
867
868     `"--:shadowEtchedInDash"'
869           A dashed horizontal line with a 3-d recessed appearance.
870
871     `"--:shadowEtchedOutDash"'
872           A dashed horizontal line with a 3-d pushed-out appearance.
873
874     `"--:shadowDoubleEtchedInDash"'
875           A dashed double horizontal line with a 3-d recessed
876           appearance.
877
878     `"--:shadowDoubleEtchedOutDash"'
879           A dashed double horizontal line with a 3-d pushed-out
880           appearance.
881
882    * If an element of a menu is a list, it is treated as a submenu.
883      The name of that submenu (the first element in the list) will be
884      used as the name of the item representing this menu on the parent.
885
886    The possible keywords are as follows:
887
888 :active FORM
889      FORM will be evaluated when the menu that this item is a part of
890      is about to be displayed, and the item will be selectable only if
891      the result is non-`nil'.  If the item is unselectable, it will
892      usually be displayed grayed-out to indicate this.
893
894 :suffix FORM
895      FORM will be evaluated when the menu that this item is a part of
896      is about to be displayed, and the resulting string is appended to
897      the displayed name.  This provides a convenient way of adding the
898      name of a command's "argument" to the menu, like `Kill Buffer
899      NAME'.
900
901 :keys STRING
902      Normally, the keyboard equivalents of commands in menus are
903      displayed when the "callback" is a symbol.  This can be used to
904      specify keys for more complex menu items.  It is passed through
905      `substitute-command-keys' first.
906
907 :style STYLE
908      Specifies what kind of object this menu item is.  STYLE be one of
909      the symbols
910
911     `nil'
912           A normal menu item.
913
914     `toggle'
915           A toggle button.
916
917     `radio'
918           A radio button.
919
920     `button'
921           A menubar button.
922
923      The only difference between toggle and radio buttons is how they
924      are displayed.  But for consistency, a toggle button should be
925      used when there is one option whose value can be turned on or off,
926      and radio buttons should be used when there is a set of mutually
927      exclusive options.  When using a group of radio buttons, you
928      should arrange for no more than one to be marked as selected at a
929      time.
930
931 :selected FORM
932      Meaningful only when STYLE is `toggle', `radio' or `button'.  This
933      specifies whether the button will be in the selected or unselected
934      state.  FORM is evaluated, as for `:active'.
935
936 :included FORM
937      This can be used to control the visibility of a menu item.  The
938      form is evaluated and the menu item is only displayed if the
939      result is non-`nil'.  Note that this is different from `:active':
940      If `:active' evaluates to `nil', the item will be displayed grayed
941      out, while if `:included' evaluates to `nil', the item will be
942      omitted entirely.
943
944 :config SYMBOL
945      This is an efficient shorthand for `:included (memq SYMBOL
946      menubar-configuration)'.  See the variable `menubar-configuration'.
947
948 :accelerator KEY
949      A menu accelerator is a keystroke which can be pressed while the
950      menu is visible which will immediately activate the item.  KEY
951      must be a char or the symbol name of a key.  *Note Menu
952      Accelerators::.
953
954  - Variable: menubar-configuration
955      This variable holds a list of symbols, against which the value of
956      the `:config' tag for each menubar item will be compared.  If a
957      menubar item has a `:config' tag, then it is omitted from the
958      menubar if that tag is not a member of the `menubar-configuration'
959      list.
960
961    For example:
962
963       ("File"
964        :filter file-menu-filter      ; file-menu-filter is a function that takes
965                                      ; one argument (a list of menu items) and
966                                      ; returns a list of menu items
967        [ "Save As..."    write-file]
968        [ "Revert Buffer" revert-buffer :active (buffer-modified-p) ]
969        [ "Read Only"     toggle-read-only :style toggle :selected buffer-read-only ]
970        )
971
972 \1f
973 File: lispref.info,  Node: Menubar Format,  Next: Menubar,  Prev: Menu Format,  Up: Menus
974
975 Format of the Menubar
976 =====================
977
978    A menubar is a list of menus, menu items, and strings.  The format is
979 similar to that of a menu, except:
980
981    * The first item need not be a string, and is not treated specially.
982
983    * A string consisting solely of hyphens is not treated specially.
984
985    * If an element of a menubar is `nil', then it is used to represent
986      the division between the set of menubar items which are flush-left
987      and those which are flush-right.  (Note: this isn't completely
988      implemented yet.)
989
990 \1f
991 File: lispref.info,  Node: Menubar,  Next: Modifying Menus,  Prev: Menubar Format,  Up: Menus
992
993 Menubar
994 =======
995
996  - Variable: current-menubar
997      This variable holds the description of the current menubar.  This
998      may be buffer-local.  When the menubar is changed, the function
999      `set-menubar-dirty-flag' has to be called in order for the menubar
1000      to be updated on the screen.
1001
1002  - Constant: default-menubar
1003      This variable holds the menubar description of the menubar that is
1004      visible at startup.  This is the value that `current-menubar' has
1005      at startup.
1006
1007  - Function: set-menubar-dirty-flag
1008      This function tells XEmacs that the menubar widget has to be
1009      updated.  Changes to the menubar will generally not be visible
1010      until this function is called.
1011
1012    The following convenience functions are provided for setting the
1013 menubar.  They are equivalent to doing the appropriate action to change
1014 `current-menubar', and then calling `set-menubar-dirty-flag'.  Note
1015 that these functions copy their argument using `copy-sequence'.
1016
1017  - Function: set-menubar menubar
1018      This function sets the default menubar to be MENUBAR (*note Menu
1019      Format::).  This is the menubar that will be visible in buffers
1020      that have not defined their own, buffer-local menubar.
1021
1022  - Function: set-buffer-menubar menubar
1023      This function sets the buffer-local menubar to be MENUBAR.  This
1024      does not change the menubar in any buffers other than the current
1025      one.
1026
1027    Miscellaneous:
1028
1029  - Variable: menubar-show-keybindings
1030      If true, the menubar will display keyboard equivalents.  If false,
1031      only the command names will be displayed.
1032
1033  - Variable: activate-menubar-hook
1034      Function or functions called before a menubar menu is pulled down.
1035      These functions are called with no arguments, and should
1036      interrogate and modify the value of `current-menubar' as desired.
1037
1038      The functions on this hook are invoked after the mouse goes down,
1039      but before the menu is mapped, and may be used to activate,
1040      deactivate, add, or delete items from the menus.  However, using a
1041      filter (with the `:filter' keyword in a menu description) is
1042      generally a more efficient way of accomplishing the same thing,
1043      because the filter is invoked only when the actual menu goes down.
1044      With a complex menu, there can be a quite noticeable and
1045      sometimes aggravating delay if all menu modification is
1046      implemented using the `activate-menubar-hook'.  See above.
1047
1048      These functions may return the symbol `t' to assert that they have
1049      made no changes to the menubar.  If any other value is returned,
1050      the menubar is recomputed.  If `t' is returned but the menubar has
1051      been changed, then the changes may not show up right away.
1052      Returning `nil' when the menubar has not changed is not so bad;
1053      more computation will be done, but redisplay of the menubar will
1054      still be performed optimally.
1055
1056  - Variable: menu-no-selection-hook
1057      Function or functions to call when a menu or dialog box is
1058      dismissed without a selection having been made.
1059
1060 \1f
1061 File: lispref.info,  Node: Modifying Menus,  Next: Pop-Up Menus,  Prev: Menubar,  Up: Menus
1062
1063 Modifying Menus
1064 ===============
1065
1066    The following functions are provided to modify the menubar of one of
1067 its submenus.  Note that these functions modify the menu in-place,
1068 rather than copying it and making a new menu.
1069
1070    Some of these functions take a "menu path", which is a list of
1071 strings identifying the menu to be modified.  For example, `("File")'
1072 names the top-level "File" menu.  `("File" "Foo")' names a hypothetical
1073 submenu of "File".
1074
1075    Others take a "menu item path", which is similar to a menu path but
1076 also specifies a particular item to be modified.  For example, `("File"
1077 "Save")' means the menu item called "Save" under the top-level "File"
1078 menu.  `("Menu" "Foo" "Item")' means the menu item called "Item" under
1079 the "Foo" submenu of "Menu".
1080
1081  - Function: add-submenu menu-path submenu &optional before
1082      This function adds a menu to the menubar or one of its submenus.
1083      If the named menu exists already, it is changed.
1084
1085      MENU-PATH identifies the menu under which the new menu should be
1086      inserted.  If MENU-PATH is `nil', then the menu will be added to
1087      the menubar itself.
1088
1089      SUBMENU is the new menu to add (*note Menu Format::).
1090
1091      BEFORE, if provided, is the name of a menu before which this menu
1092      should be added, if this menu is not on its parent already.  If
1093      the menu is already present, it will not be moved.
1094
1095  - Function: add-menu-button menu-path menu-leaf &optional before
1096      This function adds a menu item to some menu, creating the menu
1097      first if necessary.  If the named item exists already, it is
1098      changed.
1099
1100      MENU-PATH identifies the menu under which the new menu item should
1101      be inserted.
1102
1103      MENU-LEAF is a menubar leaf node (*note Menu Format::).
1104
1105      BEFORE, if provided, is the name of a menu before which this item
1106      should be added, if this item is not on the menu already.  If the
1107      item is already present, it will not be moved.
1108
1109  - Function: delete-menu-item menu-item-path
1110      This function removes the menu item specified by MENU-ITEM-PATH
1111      from the menu hierarchy.
1112
1113  - Function: enable-menu-item menu-item-path
1114      This function makes the menu item specified by MENU-ITEM-PATH be
1115      selectable.
1116
1117  - Function: disable-menu-item menu-item-path
1118      This function makes the menu item specified by MENU-ITEM-PATH be
1119      unselectable.
1120
1121  - Function: relabel-menu-item menu-item-path new-name
1122      This function changes the string of the menu item specified by
1123      MENU-ITEM-PATH.  NEW-NAME is the string that the menu item will be
1124      printed as from now on.
1125
1126    The following function can be used to search for a particular item in
1127 a menubar specification, given a path to the item.
1128
1129  - Function: find-menu-item menubar menu-item-path &optional parent
1130      This function searches MENUBAR for the item given by
1131      MENU-ITEM-PATH starting from PARENT (`nil' means start at the top
1132      of MENUBAR).  This function returns `(ITEM . PARENT)', where
1133      PARENT is the immediate parent of the item found (a menu
1134      description), and ITEM is either a vector, list, or string,
1135      depending on the nature of the menu item.
1136
1137      This function signals an error if the item is not found.
1138
1139    The following deprecated functions are also documented, so that
1140 existing code can be understood.  You should not use these functions in
1141 new code.
1142
1143  - Function: add-menu menu-path menu-name menu-items &optional before
1144      This function adds a menu to the menubar or one of its submenus.
1145      If the named menu exists already, it is changed.  This is
1146      obsolete; use `add-submenu' instead.
1147
1148      MENU-PATH identifies the menu under which the new menu should be
1149      inserted.  If MENU-PATH is `nil', then the menu will be added to
1150      the menubar itself.
1151
1152      MENU-NAME is the string naming the menu to be added; MENU-ITEMS is
1153      a list of menu items, strings, and submenus.  These two arguments
1154      are the same as the first and following elements of a menu
1155      description (*note Menu Format::).
1156
1157      BEFORE, if provided, is the name of a menu before which this menu
1158      should be added, if this menu is not on its parent already.  If the
1159      menu is already present, it will not be moved.
1160
1161  - Function: add-menu-item menu-path item-name function enabled-p
1162           &optional before
1163      This function adds a menu item to some menu, creating the menu
1164      first if necessary.  If the named item exists already, it is
1165      changed.  This is obsolete; use `add-menu-button' instead.
1166
1167      MENU-PATH identifies the menu under which the new menu item should
1168      be inserted. ITEM-NAME, FUNCTION, and ENABLED-P are the first,
1169      second, and third elements of a menu item vector (*note Menu
1170      Format::).
1171
1172      BEFORE, if provided, is the name of a menu item before which this
1173      item should be added, if this item is not on the menu already.  If
1174      the item is already present, it will not be moved.
1175
1176 \1f
1177 File: lispref.info,  Node: Menu Filters,  Next: Menu Accelerators,  Prev: Pop-Up Menus,  Up: Menus
1178
1179 Menu Filters
1180 ============
1181
1182    The following filter functions are provided for use in
1183 `default-menubar'.  You may want to use them in your own menubar
1184 description.
1185
1186  - Function: file-menu-filter menu-items
1187      This function changes the arguments and sensitivity of these File
1188      menu items:
1189
1190     `Delete Buffer'
1191           Has the name of the current buffer appended to it.
1192
1193     `Print Buffer'
1194           Has the name of the current buffer appended to it.
1195
1196     `Pretty-Print Buffer'
1197           Has the name of the current buffer appended to it.
1198
1199     `Save Buffer'
1200           Has the name of the current buffer appended to it, and is
1201           sensitive only when the current buffer is modified.
1202
1203     `Revert Buffer'
1204           Has the name of the current buffer appended to it, and is
1205           sensitive only when the current buffer has a file.
1206
1207     `Delete Frame'
1208           Sensitive only when there is more than one visible frame.
1209
1210  - Function: edit-menu-filter menu-items
1211      This function changes the arguments and sensitivity of these Edit
1212      menu items:
1213
1214     `Cut'
1215           Sensitive only when XEmacs owns the primary X Selection (if
1216           `zmacs-regions' is `t', this is equivalent to saying that
1217           there is a region selected).
1218
1219     `Copy'
1220           Sensitive only when XEmacs owns the primary X Selection.
1221
1222     `Clear'
1223           Sensitive only when XEmacs owns the primary X Selection.
1224
1225     `Paste'
1226           Sensitive only when there is an owner for the X Clipboard
1227           Selection.
1228
1229     `Undo'
1230           Sensitive only when there is undo information.  While in the
1231           midst of an undo, this is changed to `Undo More'.
1232
1233  - Function: buffers-menu-filter menu-items
1234      This function sets up the Buffers menu.  *Note Buffers Menu::, for
1235      more information.
1236