1 This is Info file ../../info/lispref.info, produced by Makeinfo version
2 1.68 from the input file lispref.texi.
4 INFO-DIR-SECTION XEmacs Editor
6 * Lispref: (lispref). XEmacs Lisp Reference Manual.
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
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.
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.
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.
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.
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.
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.
53 File: lispref.info, Node: Key Lookup, Next: Functions for Key Lookup, Prev: Active Keymaps, Up: Keymaps
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
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.
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
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:
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.
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.
98 The events used so far in the lookup form a complete key, and
99 COMMAND is its binding. *Note What Is a Function::.
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::.)
110 The meaning of a list depends on the types of the elements of the
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
117 * If the CAR of LIST is a keymap and the CDR is an event type,
118 then this is an "indirect entry":
120 (OTHERMAP . OTHERTYPE)
122 When key lookup encounters an indirect entry, it looks up
123 instead the binding of OTHERTYPE in OTHERMAP and uses that.
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
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
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::.).
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.
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
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.
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'.
166 File: lispref.info, Node: Functions for Key Lookup, Next: Changing Key Bindings, Prev: Key Lookup, Up: Keymaps
168 Functions for Key Lookup
169 ========================
171 Here are the functions and variables pertaining to key lookup.
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.
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.
186 All the other functions described in this chapter that look up
187 keys use `lookup-key'.
189 (lookup-key (current-global-map) "\C-x\C-f")
191 (lookup-key (current-global-map) "\C-x\C-f12345")
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.
199 (lookup-key (current-global-map) "\ef")
201 (lookup-key (current-global-map) "\M-f")
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
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.
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.
219 The argument ACCEPT-DEFAULTS controls checking for default
220 bindings, as in `lookup-key' (above).
222 (key-binding "\C-x\C-f")
224 (key-binding '(control home))
225 => beginning-of-buffer
226 (key-binding [escape escape escape])
227 => keyboard-escape-quit
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.
233 The argument ACCEPT-DEFAULTS controls checking for default
234 bindings, as in `lookup-key' (above).
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.
240 The argument ACCEPT-DEFAULTS controls checking for default
241 bindings, as in `lookup-key' (above).
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'.
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.
255 The argument ACCEPT-DEFAULTS controls checking for default
256 bindings, as in `lookup-key' (above).
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
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
274 meta-prefix-char ; The default value.
275 => ?\^[ ; Under XEmacs 20.
276 => 27 ; Under XEmacs 19.
281 ?\C-x ; The print representation
283 => ?\^X ; Under XEmacs 20.
284 => 24 ; Under XEmacs 19.
286 (setq meta-prefix-char 24)
289 (key-binding "\C-xb")
290 => backward-word ; Now, typing `C-x b' is
293 (setq meta-prefix-char ?\e) ; Avoid confusion!
294 ; Restore the default value!
295 => ?\^[ ; Under XEmacs 20.
296 => 27 ; Under XEmacs 19.
299 File: lispref.info, Node: Changing Key Bindings, Next: Key Binding Commands, Prev: Functions for Key Lookup, Up: Keymaps
301 Changing Key Bindings
302 =====================
304 The way to rebind a key is to change its entry in a keymap. If you
305 change a binding in the global keymap, the change is effective in all
306 buffers (though it has no direct effect in buffers that shadow the
307 global binding with a local one). If you change the current buffer's
308 local map, that usually affects all buffers using the same major mode.
309 The `global-set-key' and `local-set-key' functions are convenient
310 interfaces for these operations (*note Key Binding Commands::.). You
311 can also use `define-key', a more general function; then you must
312 specify explicitly the map to change.
314 The way to specify the key sequence that you want to rebind is
315 described above (*note Key Sequences::.).
317 For the functions below, an error is signaled if KEYMAP is not a
318 keymap or if KEY is not a string or vector representing a key sequence.
319 You can use event types (symbols) as shorthand for events that are
322 - Function: define-key KEYMAP KEY BINDING
323 This function sets the binding for KEY in KEYMAP. (If KEY is more
324 than one event long, the change is actually made in another keymap
325 reached from KEYMAP.) The argument BINDING can be any Lisp
326 object, but only certain types are meaningful. (For a list of
327 meaningful types, see *Note Key Lookup::.) The value returned by
328 `define-key' is BINDING.
330 Every prefix of KEY must be a prefix key (i.e., bound to a keymap)
331 or undefined; otherwise an error is signaled.
333 If some prefix of KEY is undefined, then `define-key' defines it
334 as a prefix key so that the rest of KEY may be defined as
337 Here is an example that creates a sparse keymap and makes a number of
340 (setq map (make-sparse-keymap))
341 => #<keymap 0 entries 0xbee>
343 (define-key map "\C-f" 'forward-char)
347 => #<keymap 1 entry 0xbee>
348 (describe-bindings-internal map)
349 => ; (Inserted in buffer)
352 ;; Build sparse submap for `C-x' and bind `f' in that.
353 (define-key map "\C-xf" 'forward-word)
357 => #<keymap 2 entries 0xbee>
358 (describe-bindings-internal map)
359 => ; (Inserted in buffer)
361 C-x << Prefix Command >>
365 ;; Bind `C-p' to the `ctl-x-map'.
366 (define-key map "\C-p" ctl-x-map)
368 => #<keymap Control-X-prefix 77 entries 0x3bf>
370 ;; Bind `C-f' to `foo' in the `ctl-x-map'.
371 (define-key map "\C-p\C-f" 'foo)
375 => #<keymap 3 entries 0xbee>
376 (describe-bindings-internal map)
377 => ; (Inserted in buffer)
379 C-p << Prefix command Control-X-prefix >>
380 C-x << Prefix Command >>
382 C-p tab indent-rigidly
383 C-p $ set-selective-display
385 C-p ( start-kbd-macro
388 C-p C-x exchange-point-and-mark
389 C-p C-z suspend-or-iconify-emacs
390 C-p M-escape repeat-complex-command
391 C-p M-C-[ repeat-complex-command
395 C-p 4 . find-tag-other-window
397 C-p 4 C-o display-buffer
401 C-p 5 C-f find-file-other-frame
405 C-p a i g inverse-add-global-abbrev
406 C-p a i l inverse-add-mode-abbrev
408 Note that storing a new binding for `C-p C-f' actually works by
409 changing an entry in `ctl-x-map', and this has the effect of changing
410 the bindings of both `C-p C-f' and `C-x C-f' in the default global map.
412 - Function: substitute-key-definition OLDDEF NEWDEF KEYMAP &optional
414 This function replaces OLDDEF with NEWDEF for any keys in KEYMAP
415 that were bound to OLDDEF. In other words, OLDDEF is replaced
416 with NEWDEF wherever it appears. The function returns `nil'.
418 For example, this redefines `C-x C-f', if you do it in an XEmacs
419 with standard bindings:
421 (substitute-key-definition
422 'find-file 'find-file-read-only (current-global-map))
424 If OLDMAP is non-`nil', then its bindings determine which keys to
425 rebind. The rebindings still happen in NEWMAP, not in OLDMAP.
426 Thus, you can change one map under the control of the bindings in
427 another. For example,
429 (substitute-key-definition
430 'delete-backward-char 'my-funny-delete
433 puts the special deletion command in `my-map' for whichever keys
434 are globally bound to the standard deletion command.
437 - Function: suppress-keymap KEYMAP &optional NODIGITS
438 This function changes the contents of the full keymap KEYMAP by
439 making all the printing characters undefined. More precisely, it
440 binds them to the command `undefined'. This makes ordinary
441 insertion of text impossible. `suppress-keymap' returns `nil'.
443 If NODIGITS is `nil', then `suppress-keymap' defines digits to run
444 `digit-argument', and `-' to run `negative-argument'. Otherwise
445 it makes them undefined like the rest of the printing characters.
447 The `suppress-keymap' function does not make it impossible to
448 modify a buffer, as it does not suppress commands such as `yank'
449 and `quoted-insert'. To prevent any modification of a buffer, make
450 it read-only (*note Read Only Buffers::.).
452 Since this function modifies KEYMAP, you would normally use it on
453 a newly created keymap. Operating on an existing keymap that is
454 used for some other purpose is likely to cause trouble; for
455 example, suppressing `global-map' would make it impossible to use
458 Most often, `suppress-keymap' is used to initialize local keymaps
459 of modes such as Rmail and Dired where insertion of text is not
460 desirable and the buffer is read-only. Here is an example taken
461 from the file `emacs/lisp/dired.el', showing how the local keymap
462 for Dired mode is set up:
465 (setq dired-mode-map (make-keymap))
466 (suppress-keymap dired-mode-map)
467 (define-key dired-mode-map "r" 'dired-rename-file)
468 (define-key dired-mode-map "\C-d" 'dired-flag-file-deleted)
469 (define-key dired-mode-map "d" 'dired-flag-file-deleted)
470 (define-key dired-mode-map "v" 'dired-view-file)
471 (define-key dired-mode-map "e" 'dired-find-file)
472 (define-key dired-mode-map "f" 'dired-find-file)
476 File: lispref.info, Node: Key Binding Commands, Next: Scanning Keymaps, Prev: Changing Key Bindings, Up: Keymaps
478 Commands for Binding Keys
479 =========================
481 This section describes some convenient interactive interfaces for
482 changing key bindings. They work by calling `define-key'.
484 People often use `global-set-key' in their `.emacs' file for simple
485 customization. For example,
487 (global-set-key "\C-x\C-\\" 'next-line)
491 (global-set-key [(control ?x) (control ?\\)] 'next-line)
495 (global-set-key [?\C-x ?\C-\\] 'next-line)
497 redefines `C-x C-\' to move down a line.
499 (global-set-key [(meta button1)] 'mouse-set-point)
501 redefines the first (leftmost) mouse button, typed with the Meta key, to
502 set point where you click.
504 - Command: global-set-key KEY DEFINITION
505 This function sets the binding of KEY in the current global map to
508 (global-set-key KEY DEFINITION)
510 (define-key (current-global-map) KEY DEFINITION)
512 - Command: global-unset-key KEY
513 This function removes the binding of KEY from the current global
516 One use of this function is in preparation for defining a longer
517 key that uses KEY as a prefix--which would not be allowed if KEY
518 has a non-prefix binding. For example:
520 (global-unset-key "\C-l")
523 (global-set-key "\C-l\C-l" 'redraw-display)
526 This function is implemented simply using `define-key':
528 (global-unset-key KEY)
530 (define-key (current-global-map) KEY nil)
532 - Command: local-set-key KEY DEFINITION
533 This function sets the binding of KEY in the current local keymap
536 (local-set-key KEY DEFINITION)
538 (define-key (current-local-map) KEY DEFINITION)
540 - Command: local-unset-key KEY
541 This function removes the binding of KEY from the current local
544 (local-unset-key KEY)
546 (define-key (current-local-map) KEY nil)
549 File: lispref.info, Node: Scanning Keymaps, Next: Other Keymap Functions, Prev: Key Binding Commands, Up: Keymaps
554 This section describes functions used to scan all the current
555 keymaps, or all keys within a keymap, for the sake of printing help
558 - Function: accessible-keymaps KEYMAP &optional PREFIX
559 This function returns a list of all the keymaps that can be
560 accessed (via prefix keys) from KEYMAP. The value is an
561 association list with elements of the form `(KEY . MAP)', where
562 KEY is a prefix key whose definition in KEYMAP is MAP.
564 The elements of the alist are ordered so that the KEY increases in
565 length. The first element is always `([] . KEYMAP)', because the
566 specified keymap is accessible from itself with a prefix of no
569 If PREFIX is given, it should be a prefix key sequence; then
570 `accessible-keymaps' includes only the submaps whose prefixes start
571 with PREFIX. These elements look just as they do in the value of
572 `(accessible-keymaps)'; the only difference is that some elements
575 In the example below, the returned alist indicates that the key
576 `C-x', which is displayed as `[(control x)]', is a prefix key
577 whose definition is the keymap `#<keymap ((control x) #<keymap
578 emacs-lisp-mode-map 8 entries 0x546>) 1 entry 0x8a2>'. (The strange
579 notation for the keymap's name indicates that this is an internal
580 submap of `emacs-lisp-mode-map'. This is because
581 `lisp-interaction-mode-map' has set up `emacs-lisp-mode-map' as
582 its parent, and `lisp-interaction-mode-map' defines no key
583 sequences beginning with `C-x'.)
586 => #<keymap lisp-interaction-mode-map 5 entries 0x558>
587 (accessible-keymaps (current-local-map))
588 =>(([] . #<keymap lisp-interaction-mode-map 5 entries 0x558>)
590 #<keymap ((control x) #<keymap emacs-lisp-mode-map 8 entries 0x546>)
593 The following example shows the results of calling
594 `accessible-keymaps' on a large, complex keymap. Notice how some
595 keymaps were given explicit names using `set-keymap-name'; those
596 submaps without explicit names are given descriptive names
597 indicating their relationship to their enclosing keymap.
599 (accessible-keymaps (current-global-map))
600 => (([] . #<keymap global-map 639 entries 0x221>)
601 ([(control c)] . #<keymap mode-specific-command-prefix 1 entry 0x3cb>)
602 ([(control h)] . #<keymap help-map 33 entries 0x4ec>)
603 ([(control x)] . #<keymap Control-X-prefix 77 entries 0x3bf>)
605 #<keymap ((meta escape) #<keymap global-map 639 entries 0x221>)
607 ([(meta control \[)] .
608 #<keymap ((meta escape) #<keymap global-map 639 entries 0x221>)
610 ([f1] . #<keymap help-map 33 entries 0x4ec>)
611 ([(control x) \4] . #<keymap ctl-x-4-prefix 9 entries 0x3c5>)
612 ([(control x) \5] . #<keymap ctl-x-5-prefix 8 entries 0x3c8>)
613 ([(control x) \6] . #<keymap 13 entries 0x4d2>)
615 #<keymap (a #<keymap Control-X-prefix 77 entries 0x3bf>)
617 ([(control x) n] . #<keymap narrowing-prefix 3 entries 0x3dd>)
618 ([(control x) r] . #<keymap rectangle-prefix 18 entries 0x3e9>)
619 ([(control x) v] . #<keymap vc-prefix-map 13 entries 0x60e>)
621 #<keymap (i #<keymap (a #<keymap Control-X-prefix 77 entries 0x3bf>)
625 - Function: map-keymap FUNCTION KEYMAP &optional SORT-FIRST
626 This function applies FUNCTION to each element of `KEYMAP'.
627 FUNCTION will be called with two arguments: a key-description
628 list, and the binding. The order in which the elements of the
629 keymap are passed to the function is unspecified. If the function
630 inserts new elements into the keymap, it may or may not be called
631 with them later. No element of the keymap will ever be passed to
632 the function more than once.
634 The function will not be called on elements of this keymap's
635 parents (*note Inheritance and Keymaps::.) or upon keymaps which
636 are contained within this keymap (multi-character definitions).
637 It will be called on <META> characters since they are not really
638 two-character sequences.
640 If the optional third argument SORT-FIRST is non-`nil', then the
641 elements of the keymap will be passed to the mapper function in a
642 canonical order. Otherwise, they will be passed in hash (that is,
643 random) order, which is faster.
645 - Function: keymap-fullness KEYMAP
646 This function returns the number of bindings in the keymap.
648 - Function: where-is-internal DEFINITION &optional KEYMAPS FIRSTONLY
649 NOINDIRECT EVENT-OR-KEYS
650 This function returns a list of key sequences (of any length) that
651 are bound to DEFINITION in a set of keymaps.
653 The argument DEFINITION can be any object; it is compared with all
654 keymap entries using `eq'.
656 KEYMAPS can be either a keymap (meaning search in that keymap and
657 the current global keymap) or a list of keymaps (meaning search in
658 exactly those keymaps and no others). If KEYMAPS is nil, search
659 in the currently applicable maps for EVENT-OR-KEYS.
661 If KEYMAP is a keymap, then the maps searched are KEYMAP and the
662 global keymap. If KEYMAP is a list of keymaps, then the maps
663 searched are exactly those keymaps, and no others. If KEYMAP is
664 `nil', then the maps used are the current active keymaps for
665 EVENT-OR-KEYS (this is equivalent to specifying `(current-keymaps
666 EVENT-OR-KEYS)' as the argument to KEYMAPS).
668 If FIRSTONLY is non-`nil', then the value is a single vector
669 representing the first key sequence found, rather than a list of
670 all possible key sequences.
672 If NOINDIRECT is non-`nil', `where-is-internal' doesn't follow
673 indirect keymap bindings. This makes it possible to search for an
674 indirect definition itself.
676 This function is used by `where-is' (*note Help: (emacs)Help.).
678 (where-is-internal 'describe-function)
679 => ([(control h) d] [(control h) f] [f1 d] [f1 f])
681 - Function: describe-bindings-internal MAP &optional ALL SHADOW PREFIX
683 This function inserts (into the current buffer) a list of all
684 defined keys and their definitions in MAP. Optional second
685 argument ALL says whether to include even "uninteresting"
686 definitions, i.e. symbols with a non-`nil' `suppress-keymap'
687 property. Third argument SHADOW is a list of keymaps whose
688 bindings shadow those of map; if a binding is present in any
689 shadowing map, it is not printed. Fourth argument PREFIX, if
690 non-`nil', should be a key sequence; only bindings which start
691 with that key sequence will be printed. Fifth argument
692 MOUSE-ONLY-P says to only print bindings for mouse clicks.
694 `describe-bindings-internal' is used to implement the help command
697 - Command: describe-bindings PREFIX MOUSE-ONLY-P
698 This function creates a listing of all defined keys and their
699 definitions. It writes the listing in a buffer named `*Help*' and
700 displays it in a window.
702 If PREFIX is non-`nil', it should be a prefix key; then the
703 listing includes only keys that start with PREFIX.
705 When several characters with consecutive ASCII codes have the same
706 definition, they are shown together, as `FIRSTCHAR..LASTCHAR'. In
707 this instance, you need to know the ASCII codes to understand
708 which characters this means. For example, in the default global
709 map, the characters `<SPC> .. ~' are described by a single line.
710 <SPC> is ASCII 32, `~' is ASCII 126, and the characters between
711 them include all the normal printing characters, (e.g., letters,
712 digits, punctuation, etc.); all these characters are bound to
713 `self-insert-command'.
715 If the second argument (prefix arg, interactively) is non-`nil'
716 then only the mouse bindings are displayed.
719 File: lispref.info, Node: Other Keymap Functions, Prev: Scanning Keymaps, Up: Keymaps
721 Other Keymap Functions
722 ======================
724 - Function: set-keymap-prompt KEYMAP NEW-PROMPT
725 This function sets the "prompt" of KEYMAP to string NEW-PROMPT, or
726 `nil' if no prompt is desired. The prompt is shown in the
727 echo-area when reading a key-sequence to be looked-up in this
730 - Function: keymap-prompt KEYMAP &optional USE-INHERITED
731 This function returns the "prompt" of the given keymap. If
732 USE-INHERITED is non-`nil', any parent keymaps will also be
733 searched for a prompt.
736 File: lispref.info, Node: Menus, Next: Dialog Boxes, Prev: Keymaps, Up: Top
743 * Menu Format:: Format of a menu description.
744 * Menubar Format:: How to specify a menubar.
745 * Menubar:: Functions for controlling the menubar.
746 * Modifying Menus:: Modifying a menu description.
747 * Pop-Up Menus:: Functions for specifying pop-up menus.
748 * Menu Filters:: Filter functions for the default menubar.
749 * Menu Accelerators:: Using and controlling menu accelerator keys
750 * Buffers Menu:: The menu that displays the list of buffers.
753 File: lispref.info, Node: Menu Format, Next: Menubar Format, Up: Menus
758 A menu is described using a "menu description", which is a list of
759 menu items, keyword-value pairs, strings, and submenus. The menu
760 description specifies which items are present in the menu, what function
761 each item invokes, and whether the item is selectable or not. Pop-up
762 menus are directly described with a menu description, while menubars are
763 described slightly differently (see below).
765 The first element of a menu must be a string, which is the name of
766 the menu. This is the string that will be displayed in the parent menu
767 or menubar, if any. This string is not displayed in the menu itself,
768 except in the case of the top level pop-up menu, where there is no
769 parent. In this case, the string will be displayed at the top of the
770 menu if `popup-menu-titles' is non-`nil'.
772 Immediately following the first element there may optionally be up
773 to four keyword-value pairs, as follows:
776 This can be used to control the visibility of a menu. The form is
777 evaluated and the menu will be omitted if the result is `nil'.
780 This is an efficient shorthand for `:included (memq SYMBOL
781 menubar-configuration)'. See the variable `menubar-configuration'.
784 A menu filter is used to sensitize or incrementally create a
785 submenu only when it is selected by the user and not every time
786 the menubar is activated. The filter function is passed the list
787 of menu items in the submenu and must return a list of menu items
788 to be used for the menu. It is called only when the menu is about
789 to be displayed, so other menus may already be displayed. Vile
790 and terrible things will happen if a menu filter function changes
791 the current buffer, window, or frame. It also should not raise,
792 lower, or iconify any frames. Basically, the filter function
793 should have no side-effects.
796 A menu accelerator is a keystroke which can be pressed while the
797 menu is visible which will immediately activate the item. KEY
798 must be a char or the symbol name of a key. *Note Menu
801 The rest of the menu consists of elements as follows:
803 * A "menu item", which is a vector in the following form:
805 `[ NAME CALLBACK :KEYWORD VALUE :KEYWORD VALUE ... ]'
807 NAME is a string, the name of the menu item; it is the string to
808 display on the menu. It is filtered through the resource
809 database, so it is possible for resources to override what string
810 is actually displayed.
812 CALLBACK is a form that will be invoked when the menu item is
813 selected. If the callback of a menu item is a symbol, then it
814 must name a command. It will be invoked with
815 `call-interactively'. If it is a list, then it is evaluated with
818 The valid keywords and their meanings are described below.
820 Note that for compatibility purposes, the form
822 `[ NAME CALLBACK ACTIVE-P ]'
824 is also accepted and is equivalent to
826 `[ NAME CALLBACK :active ACTIVE-P ]'
830 `[ NAME CALLBACK ACTIVE-P SUFFIX]'
832 is accepted and is equivalent to
834 `[ NAME CALLBACK :active ACTIVE-P :suffix SUFFIX]'
836 However, these older forms are deprecated and should generally not
839 * If an element of a menu is a string, then that string will be
840 presented in the menu as unselectable text.
842 * If an element of a menu is a string consisting solely of hyphens,
843 then that item will be presented as a solid horizontal line.
845 * If an element of a menu is a string beginning with `--:', then a
846 particular sort of horizontal line will be displayed, as follows:
849 A solid horizontal line. This is equivalent to a string
850 consisting solely of hyphens.
853 A solid double horizontal line.
855 `"--:singleDashedLine"'
856 A dashed horizontal line.
858 `"--:doubleDashedLine"'
859 A dashed double horizontal line.
862 No line (but a small space is left).
864 `"--:shadowEtchedIn"'
865 A solid horizontal line with a 3-d recessed appearance.
867 `"--:shadowEtchedOut"'
868 A solid horizontal line with a 3-d pushed-out appearance.
870 `"--:shadowDoubleEtchedIn"'
871 A solid double horizontal line with a 3-d recessed appearance.
873 `"--:shadowDoubleEtchedOut"'
874 A solid double horizontal line with a 3-d pushed-out
877 `"--:shadowEtchedInDash"'
878 A dashed horizontal line with a 3-d recessed appearance.
880 `"--:shadowEtchedOutDash"'
881 A dashed horizontal line with a 3-d pushed-out appearance.
883 `"--:shadowDoubleEtchedInDash"'
884 A dashed double horizontal line with a 3-d recessed
887 `"--:shadowDoubleEtchedOutDash"'
888 A dashed double horizontal line with a 3-d pushed-out
891 * If an element of a menu is a list, it is treated as a submenu.
892 The name of that submenu (the first element in the list) will be
893 used as the name of the item representing this menu on the parent.
895 The possible keywords are as follows:
898 FORM will be evaluated when the menu that this item is a part of
899 is about to be displayed, and the item will be selectable only if
900 the result is non-`nil'. If the item is unselectable, it will
901 usually be displayed grayed-out to indicate this.
904 FORM will be evaluated when the menu that this item is a part of
905 is about to be displayed, and the resulting string is appended to
906 the displayed name. This provides a convenient way of adding the
907 name of a command's "argument" to the menu, like `Kill Buffer
911 Normally, the keyboard equivalents of commands in menus are
912 displayed when the "callback" is a symbol. This can be used to
913 specify keys for more complex menu items. It is passed through
914 `substitute-command-keys' first.
917 Specifies what kind of object this menu item is. STYLE be one of
932 The only difference between toggle and radio buttons is how they
933 are displayed. But for consistency, a toggle button should be
934 used when there is one option whose value can be turned on or off,
935 and radio buttons should be used when there is a set of mutually
936 exclusive options. When using a group of radio buttons, you
937 should arrange for no more than one to be marked as selected at a
941 Meaningful only when STYLE is `toggle', `radio' or `button'. This
942 specifies whether the button will be in the selected or unselected
943 state. FORM is evaluated, as for `:active'.
946 This can be used to control the visibility of a menu item. The
947 form is evaluated and the menu item is only displayed if the
948 result is non-`nil'. Note that this is different from `:active':
949 If `:active' evaluates to `nil', the item will be displayed grayed
950 out, while if `:included' evaluates to `nil', the item will be
954 This is an efficient shorthand for `:included (memq SYMBOL
955 menubar-configuration)'. See the variable `menubar-configuration'.
958 A menu accelerator is a keystroke which can be pressed while the
959 menu is visible which will immediately activate the item. KEY
960 must be a char or the symbol name of a key. *Note Menu
963 - Variable: menubar-configuration
964 This variable holds a list of symbols, against which the value of
965 the `:config' tag for each menubar item will be compared. If a
966 menubar item has a `:config' tag, then it is omitted from the
967 menubar if that tag is not a member of the `menubar-configuration'
973 :filter file-menu-filter ; file-menu-filter is a function that takes
974 ; one argument (a list of menu items) and
975 ; returns a list of menu items
976 [ "Save As..." write-file]
977 [ "Revert Buffer" revert-buffer :active (buffer-modified-p) ]
978 [ "Read Only" toggle-read-only :style toggle :selected buffer-read-only ]
982 File: lispref.info, Node: Menubar Format, Next: Menubar, Prev: Menu Format, Up: Menus
984 Format of the Menubar
985 =====================
987 A menubar is a list of menus, menu items, and strings. The format is
988 similar to that of a menu, except:
990 * The first item need not be a string, and is not treated specially.
992 * A string consisting solely of hyphens is not treated specially.
994 * If an element of a menubar is `nil', then it is used to represent
995 the division between the set of menubar items which are flush-left
996 and those which are flush-right. (Note: this isn't completely
1000 File: lispref.info, Node: Menubar, Next: Modifying Menus, Prev: Menubar Format, Up: Menus
1005 - Variable: current-menubar
1006 This variable holds the description of the current menubar. This
1007 may be buffer-local. When the menubar is changed, the function
1008 `set-menubar-dirty-flag' has to be called in order for the menubar
1009 to be updated on the screen.
1011 - Constant: default-menubar
1012 This variable holds the menubar description of the menubar that is
1013 visible at startup. This is the value that `current-menubar' has
1016 - Function: set-menubar-dirty-flag
1017 This function tells XEmacs that the menubar widget has to be
1018 updated. Changes to the menubar will generally not be visible
1019 until this function is called.
1021 The following convenience functions are provided for setting the
1022 menubar. They are equivalent to doing the appropriate action to change
1023 `current-menubar', and then calling `set-menubar-dirty-flag'. Note
1024 that these functions copy their argument using `copy-sequence'.
1026 - Function: set-menubar MENUBAR
1027 This function sets the default menubar to be MENUBAR (*note Menu
1028 Format::.). This is the menubar that will be visible in buffers
1029 that have not defined their own, buffer-local menubar.
1031 - Function: set-buffer-menubar MENUBAR
1032 This function sets the buffer-local menubar to be MENUBAR. This
1033 does not change the menubar in any buffers other than the current
1038 - Variable: menubar-show-keybindings
1039 If true, the menubar will display keyboard equivalents. If false,
1040 only the command names will be displayed.
1042 - Variable: activate-menubar-hook
1043 Function or functions called before a menubar menu is pulled down.
1044 These functions are called with no arguments, and should
1045 interrogate and modify the value of `current-menubar' as desired.
1047 The functions on this hook are invoked after the mouse goes down,
1048 but before the menu is mapped, and may be used to activate,
1049 deactivate, add, or delete items from the menus. However, using a
1050 filter (with the `:filter' keyword in a menu description) is
1051 generally a more efficient way of accomplishing the same thing,
1052 because the filter is invoked only when the actual menu goes down.
1053 With a complex menu, there can be a quite noticeable and
1054 sometimes aggravating delay if all menu modification is
1055 implemented using the `activate-menubar-hook'. See above.
1057 These functions may return the symbol `t' to assert that they have
1058 made no changes to the menubar. If any other value is returned,
1059 the menubar is recomputed. If `t' is returned but the menubar has
1060 been changed, then the changes may not show up right away.
1061 Returning `nil' when the menubar has not changed is not so bad;
1062 more computation will be done, but redisplay of the menubar will
1063 still be performed optimally.
1065 - Variable: menu-no-selection-hook
1066 Function or functions to call when a menu or dialog box is
1067 dismissed without a selection having been made.
1070 File: lispref.info, Node: Modifying Menus, Next: Pop-Up Menus, Prev: Menubar, Up: Menus
1075 The following functions are provided to modify the menubar of one of
1076 its submenus. Note that these functions modify the menu in-place,
1077 rather than copying it and making a new menu.
1079 Some of these functions take a "menu path", which is a list of
1080 strings identifying the menu to be modified. For example, `("File")'
1081 names the top-level "File" menu. `("File" "Foo")' names a hypothetical
1084 Others take a "menu item path", which is similar to a menu path but
1085 also specifies a particular item to be modified. For example, `("File"
1086 "Save")' means the menu item called "Save" under the top-level "File"
1087 menu. `("Menu" "Foo" "Item")' means the menu item called "Item" under
1088 the "Foo" submenu of "Menu".
1090 - Function: add-submenu MENU-PATH SUBMENU &optional BEFORE
1091 This function adds a menu to the menubar or one of its submenus.
1092 If the named menu exists already, it is changed.
1094 MENU-PATH identifies the menu under which the new menu should be
1095 inserted. If MENU-PATH is `nil', then the menu will be added to
1098 SUBMENU is the new menu to add (*note Menu Format::.).
1100 BEFORE, if provided, is the name of a menu before which this menu
1101 should be added, if this menu is not on its parent already. If
1102 the menu is already present, it will not be moved.
1104 - Function: add-menu-button MENU-PATH MENU-LEAF &optional BEFORE
1105 This function adds a menu item to some menu, creating the menu
1106 first if necessary. If the named item exists already, it is
1109 MENU-PATH identifies the menu under which the new menu item should
1112 MENU-LEAF is a menubar leaf node (*note Menu Format::.).
1114 BEFORE, if provided, is the name of a menu before which this item
1115 should be added, if this item is not on the menu already. If the
1116 item is already present, it will not be moved.
1118 - Function: delete-menu-item MENU-ITEM-PATH
1119 This function removes the menu item specified by MENU-ITEM-PATH
1120 from the menu hierarchy.
1122 - Function: enable-menu-item MENU-ITEM-PATH
1123 This function makes the menu item specified by MENU-ITEM-PATH be
1126 - Function: disable-menu-item MENU-ITEM-PATH
1127 This function makes the menu item specified by MENU-ITEM-PATH be
1130 - Function: relabel-menu-item MENU-ITEM-PATH NEW-NAME
1131 This function changes the string of the menu item specified by
1132 MENU-ITEM-PATH. NEW-NAME is the string that the menu item will be
1133 printed as from now on.
1135 The following function can be used to search for a particular item in
1136 a menubar specification, given a path to the item.
1138 - Function: find-menu-item MENUBAR MENU-ITEM-PATH &optional PARENT
1139 This function searches MENUBAR for the item given by
1140 MENU-ITEM-PATH starting from PARENT (`nil' means start at the top
1141 of MENUBAR). This function returns `(ITEM . PARENT)', where
1142 PARENT is the immediate parent of the item found (a menu
1143 description), and ITEM is either a vector, list, or string,
1144 depending on the nature of the menu item.
1146 This function signals an error if the item is not found.
1148 The following deprecated functions are also documented, so that
1149 existing code can be understood. You should not use these functions in
1152 - Function: add-menu MENU-PATH MENU-NAME MENU-ITEMS &optional BEFORE
1153 This function adds a menu to the menubar or one of its submenus.
1154 If the named menu exists already, it is changed. This is
1155 obsolete; use `add-submenu' instead.
1157 MENU-PATH identifies the menu under which the new menu should be
1158 inserted. If MENU-PATH is `nil', then the menu will be added to
1161 MENU-NAME is the string naming the menu to be added; MENU-ITEMS is
1162 a list of menu items, strings, and submenus. These two arguments
1163 are the same as the first and following elements of a menu
1164 description (*note Menu Format::.).
1166 BEFORE, if provided, is the name of a menu before which this menu
1167 should be added, if this menu is not on its parent already. If the
1168 menu is already present, it will not be moved.
1170 - Function: add-menu-item MENU-PATH ITEM-NAME FUNCTION ENABLED-P
1172 This function adds a menu item to some menu, creating the menu
1173 first if necessary. If the named item exists already, it is
1174 changed. This is obsolete; use `add-menu-button' instead.
1176 MENU-PATH identifies the menu under which the new menu item should
1177 be inserted. ITEM-NAME, FUNCTION, and ENABLED-P are the first,
1178 second, and third elements of a menu item vector (*note Menu
1181 BEFORE, if provided, is the name of a menu item before which this
1182 item should be added, if this item is not on the menu already. If
1183 the item is already present, it will not be moved.
1186 File: lispref.info, Node: Menu Filters, Next: Menu Accelerators, Prev: Pop-Up Menus, Up: Menus
1191 The following filter functions are provided for use in
1192 `default-menubar'. You may want to use them in your own menubar
1195 - Function: file-menu-filter MENU-ITEMS
1196 This function changes the arguments and sensitivity of these File
1200 Has the name of the current buffer appended to it.
1203 Has the name of the current buffer appended to it.
1205 `Pretty-Print Buffer'
1206 Has the name of the current buffer appended to it.
1209 Has the name of the current buffer appended to it, and is
1210 sensitive only when the current buffer is modified.
1213 Has the name of the current buffer appended to it, and is
1214 sensitive only when the current buffer has a file.
1217 Sensitive only when there is more than one visible frame.
1219 - Function: edit-menu-filter MENU-ITEMS
1220 This function changes the arguments and sensitivity of these Edit
1224 Sensitive only when XEmacs owns the primary X Selection (if
1225 `zmacs-regions' is `t', this is equivalent to saying that
1226 there is a region selected).
1229 Sensitive only when XEmacs owns the primary X Selection.
1232 Sensitive only when XEmacs owns the primary X Selection.
1235 Sensitive only when there is an owner for the X Clipboard
1239 Sensitive only when there is undo information. While in the
1240 midst of an undo, this is changed to `Undo More'.
1242 - Function: buffers-menu-filter MENU-ITEMS
1243 This function sets up the Buffers menu. *Note Buffers Menu::, for