1 /* Manipulation of keymaps
2 Copyright (C) 1985, 1986, 1987, 1988, 1992 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
29 #define min(a, b) ((a) < (b) ? (a) : (b))
31 /* The number of elements in keymap vectors. */
32 #define DENSE_TABLE_SIZE (0200)
34 /* Actually allocate storage for these variables */
36 Lisp_Object current_global_map
; /* Current global keymap */
38 Lisp_Object global_map
; /* default global key bindings */
40 Lisp_Object meta_map
; /* The keymap used for globally bound
41 ESC-prefixed default commands */
43 Lisp_Object control_x_map
; /* The keymap used for globally bound
44 C-x-prefixed default commands */
46 /* was MinibufLocalMap */
47 Lisp_Object Vminibuffer_local_map
;
48 /* The keymap used by the minibuf for local
49 bindings when spaces are allowed in the
52 /* was MinibufLocalNSMap */
53 Lisp_Object Vminibuffer_local_ns_map
;
54 /* The keymap used by the minibuf for local
55 bindings when spaces are not encouraged
58 /* keymap used for minibuffers when doing completion */
59 /* was MinibufLocalCompletionMap */
60 Lisp_Object Vminibuffer_local_completion_map
;
62 /* keymap used for minibuffers when doing completion and require a match */
63 /* was MinibufLocalMustMatchMap */
64 Lisp_Object Vminibuffer_local_must_match_map
;
66 /* Alist of minor mode variables and keymaps. */
67 Lisp_Object Vminor_mode_map_alist
;
69 /* Keymap mapping ASCII function key sequences onto their preferred forms.
70 Initialized by the terminal-specific lisp files. See DEFVAR for more
72 Lisp_Object Vfunction_key_map
;
74 Lisp_Object Qkeymapp
, Qkeymap
;
76 /* A char over 0200 in a key sequence
77 is equivalent to prefixing with this character. */
79 extern Lisp_Object meta_prefix_char
;
81 void describe_map_tree ();
82 static Lisp_Object
describe_buffer_bindings ();
83 static void describe_command ();
84 static void describe_map ();
85 static void describe_map_2 ();
87 /* Keymap object support - constructors and predicates. */
89 DEFUN ("make-keymap", Fmake_keymap
, Smake_keymap
, 0, 1, 0,
90 "Construct and return a new keymap, of the form (keymap VECTOR . ALIST).\n\
91 VECTOR is a 128-element vector which holds the bindings for the ASCII\n\
92 characters. ALIST is an assoc-list which holds bindings for function keys,\n\
93 mouse events, and any other things that appear in the input stream.\n\
94 All entries in it are initially nil, meaning \"command undefined\".\n\n\
95 The optional arg STRING supplies a menu name for the keymap\n\
96 in case you use it as a menu with `x-popup-menu'.")
102 tail
= Fcons (string
, Qnil
);
105 return Fcons (Qkeymap
,
106 Fcons (Fmake_vector (make_number (DENSE_TABLE_SIZE
), Qnil
),
110 DEFUN ("make-sparse-keymap", Fmake_sparse_keymap
, Smake_sparse_keymap
, 0, 1, 0,
111 "Construct and return a new sparse-keymap list.\n\
112 Its car is `keymap' and its cdr is an alist of (CHAR . DEFINITION),\n\
113 which binds the character CHAR to DEFINITION, or (SYMBOL . DEFINITION),\n\
114 which binds the function key or mouse event SYMBOL to DEFINITION.\n\
115 Initially the alist is nil.\n\n\
116 The optional arg STRING supplies a menu name for the keymap\n\
117 in case you use it as a menu with `x-popup-menu'.")
122 return Fcons (Qkeymap
, Fcons (string
, Qnil
));
123 return Fcons (Qkeymap
, Qnil
);
126 /* This function is used for installing the standard key bindings
127 at initialization time.
131 initial_define_key (control_x_map, Ctl('X'), "exchange-point-and-mark");
133 I haven't extended these to allow the initializing code to bind
134 function keys and mouse events; since they are called by many files,
135 I'd have to fix lots of callers, and nobody right now would be using
136 the new functionality, so it seems like a waste of time. But there's
137 no technical reason not to. -JimB */
140 initial_define_key (keymap
, key
, defname
)
145 store_in_keymap (keymap
, make_number (key
), intern (defname
));
148 /* Define character fromchar in map frommap as an alias for character
149 tochar in map tomap. Subsequent redefinitions of the latter WILL
150 affect the former. */
154 synkey (frommap
, fromchar
, tomap
, tochar
)
155 struct Lisp_Vector
*frommap
, *tomap
;
156 int fromchar
, tochar
;
159 XSET (v
, Lisp_Vector
, tomap
);
160 XFASTINT (c
) = tochar
;
161 frommap
->contents
[fromchar
] = Fcons (v
, c
);
165 DEFUN ("keymapp", Fkeymapp
, Skeymapp
, 1, 1, 0,
166 "Return t if ARG is a keymap.\n\
168 A keymap is list (keymap . ALIST), a list (keymap VECTOR . ALIST),\n\
169 or a symbol whose function definition is a keymap is itself a keymap.\n\
170 ALIST elements look like (CHAR . DEFN) or (SYMBOL . DEFN);\n\
171 VECTOR is a 128-element vector of bindings for ASCII characters.")
175 return (NILP (get_keymap_1 (object
, 0)) ? Qnil
: Qt
);
178 /* Check that OBJECT is a keymap (after dereferencing through any
179 symbols). If it is, return it; otherwise, return nil, or signal an
180 error if ERROR != 0. */
182 get_keymap_1 (object
, error
)
186 register Lisp_Object tem
;
188 tem
= indirect_function (object
);
189 if (CONSP (tem
) && EQ (XCONS (tem
)->car
, Qkeymap
))
193 wrong_type_argument (Qkeymapp
, object
);
202 return get_keymap_1 (object
, 1);
206 /* Look up IDX in MAP. IDX may be any sort of event.
207 Note that this does only one level of lookup; IDX must be a single
208 event, not a sequence. */
211 access_keymap (map
, idx
)
215 /* If idx is a list (some sort of mouse click, perhaps?),
216 the index we want to use is the car of the list, which
217 ought to be a symbol. */
218 if (EVENT_HAS_PARAMETERS (idx
))
219 idx
= EVENT_HEAD (idx
);
221 if (XTYPE (idx
) == Lisp_Int
222 && (XINT (idx
) < 0 || XINT (idx
) >= DENSE_TABLE_SIZE
))
223 error ("only ASCII characters may used as keymap indices");
225 /* If idx is a symbol, it might have modifiers, which need to
226 be put in the canonical order. */
227 else if (XTYPE (idx
) == Lisp_Symbol
)
228 idx
= reorder_modifiers (idx
);
233 for (tail
= map
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
235 Lisp_Object binding
= XCONS (tail
)->car
;
237 switch (XTYPE (binding
))
240 if (EQ (XCONS (binding
)->car
, idx
))
241 return XCONS (binding
)->cdr
;
245 if (XVECTOR (binding
)->size
== DENSE_TABLE_SIZE
246 && XTYPE (idx
) == Lisp_Int
)
247 return XVECTOR (binding
)->contents
[XINT (idx
)];
258 /* Given OBJECT which was found in a slot in a keymap,
259 trace indirect definitions to get the actual definition of that slot.
260 An indirect definition is a list of the form
261 (KEYMAP . INDEX), where KEYMAP is a keymap or a symbol defined as one
262 and INDEX is the object to look up in KEYMAP to yield the definition.
264 Also if OBJECT has a menu string as the first element,
265 remove that. Also remove a menu help string as second element. */
269 register Lisp_Object object
;
273 register Lisp_Object map
, tem
;
275 /* If the contents are (KEYMAP . ELEMENT), go indirect. */
276 map
= get_keymap_1 (Fcar_safe (object
), 0);
277 tem
= Fkeymapp (map
);
279 object
= access_keymap (map
, Fcdr (object
));
281 /* If the keymap contents looks like (STRING . DEFN),
283 Keymap alist elements like (CHAR MENUSTRING . DEFN)
284 will be used by HierarKey menus. */
285 else if (XTYPE (object
) == Lisp_Cons
286 && XTYPE (XCONS (object
)->car
) == Lisp_String
)
288 object
= XCONS (object
)->cdr
;
289 /* Also remove a menu help string, if any,
290 following the menu item name. */
291 if (XTYPE (object
) == Lisp_Cons
292 && XTYPE (XCONS (object
)->car
) == Lisp_String
)
293 object
= XCONS (object
)->cdr
;
297 /* Anything else is really the value. */
303 store_in_keymap (keymap
, idx
, def
)
305 register Lisp_Object idx
;
306 register Lisp_Object def
;
308 if (XTYPE (keymap
) != Lisp_Cons
309 || ! EQ (XCONS (keymap
)->car
, Qkeymap
))
310 error ("attempt to define a key in a non-keymap");
312 /* If idx is a list (some sort of mouse click, perhaps?),
313 the index we want to use is the car of the list, which
314 ought to be a symbol. */
315 if (EVENT_HAS_PARAMETERS (idx
))
316 idx
= EVENT_HEAD (idx
);
318 if (XTYPE (idx
) == Lisp_Int
319 && (XINT (idx
) < 0 || XINT (idx
) >= DENSE_TABLE_SIZE
))
320 error ("only ASCII characters may be used as keymap indices");
322 /* If idx is a symbol, it might have modifiers, which need to
323 be put in the canonical order. */
324 else if (XTYPE (idx
) == Lisp_Symbol
)
325 idx
= reorder_modifiers (idx
);
328 /* Scan the keymap for a binding of idx. */
332 /* The cons after which we should insert new bindings. If the
333 keymap has a table element, we record its position here, so new
334 bindings will go after it; this way, the table will stay
335 towards the front of the alist and character lookups in dense
336 keymaps will remain fast. Otherwise, this just points at the
337 front of the keymap. */
338 Lisp_Object insertion_point
= keymap
;
340 for (tail
= XCONS (keymap
)->cdr
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
342 Lisp_Object elt
= XCONS (tail
)->car
;
347 if (XTYPE (idx
) == Lisp_Int
)
349 XVECTOR (elt
)->contents
[XFASTINT (idx
)] = def
;
352 insertion_point
= tail
;
356 if (EQ (idx
, XCONS (elt
)->car
))
358 XCONS (elt
)->cdr
= def
;
364 /* If we find a 'keymap' symbol in the spine of KEYMAP,
365 then we must have found the start of a second keymap
366 being used as the tail of KEYMAP, and a binding for IDX
367 should be inserted before it. */
368 if (EQ (elt
, Qkeymap
))
375 /* We have scanned the entire keymap, and not found a binding for
376 IDX. Let's add one. */
377 XCONS (insertion_point
)->cdr
=
378 Fcons (Fcons (idx
, def
), XCONS (insertion_point
)->cdr
);
385 DEFUN ("copy-keymap", Fcopy_keymap
, Scopy_keymap
, 1, 1, 0,
386 "Return a copy of the keymap KEYMAP.\n\
387 The copy starts out with the same definitions of KEYMAP,\n\
388 but changing either the copy or KEYMAP does not affect the other.\n\
389 Any key definitions that are subkeymaps are recursively copied.\n\
390 However, a key definition which is a symbol whose definition is a keymap\n\
395 register Lisp_Object copy
, tail
;
397 copy
= Fcopy_alist (get_keymap (keymap
));
399 for (tail
= copy
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
401 Lisp_Object elt
= XCONS (tail
)->car
;
403 if (XTYPE (elt
) == Lisp_Vector
404 && XVECTOR (elt
)->size
== DENSE_TABLE_SIZE
)
408 elt
= Fcopy_sequence (elt
);
409 XCONS (tail
)->car
= elt
;
411 for (i
= 0; i
< DENSE_TABLE_SIZE
; i
++)
412 if (XTYPE (XVECTOR (elt
)->contents
[i
]) != Lisp_Symbol
413 && Fkeymapp (XVECTOR (elt
)->contents
[i
]))
414 XVECTOR (elt
)->contents
[i
] =
415 Fcopy_keymap (XVECTOR (elt
)->contents
[i
]);
418 && XTYPE (XCONS (elt
)->cdr
) != Lisp_Symbol
419 && ! NILP (Fkeymapp (XCONS (elt
)->cdr
)))
420 XCONS (elt
)->cdr
= Fcopy_keymap (XCONS (elt
)->cdr
);
426 /* Simple Keymap mutators and accessors. */
428 DEFUN ("define-key", Fdefine_key
, Sdefine_key
, 3, 3, 0,
429 "Args KEYMAP, KEY, DEF. Define key sequence KEY, in KEYMAP, as DEF.\n\
430 KEYMAP is a keymap. KEY is a string or a vector of symbols and characters\n\
431 meaning a sequence of keystrokes and events.\n\
432 DEF is anything that can be a key's definition:\n\
433 nil (means key is undefined in this keymap),\n\
434 a command (a Lisp function suitable for interactive calling)\n\
435 a string (treated as a keyboard macro),\n\
436 a keymap (to define a prefix key),\n\
437 a symbol. When the key is looked up, the symbol will stand for its\n\
438 function definition, which should at that time be one of the above,\n\
439 or another symbol whose function definition is used, etc.\n\
440 a cons (STRING . DEFN), meaning that DEFN is the definition\n\
441 (DEFN should be a valid definition in its own right),\n\
442 or a cons (KEYMAP . CHAR), meaning use definition of CHAR in map KEYMAP.\n\
444 If KEYMAP is a sparse keymap, the pair binding KEY to DEF is added at\n\
445 the front of KEYMAP.")
447 register Lisp_Object keymap
;
452 register Lisp_Object c
;
453 register Lisp_Object tem
;
454 register Lisp_Object cmd
;
458 keymap
= get_keymap (keymap
);
460 if (XTYPE (key
) != Lisp_Vector
461 && XTYPE (key
) != Lisp_String
)
462 key
= wrong_type_argument (Qarrayp
, key
);
464 length
= Flength (key
);
471 c
= Faref (key
, make_number (idx
));
473 if (XTYPE (c
) == Lisp_Int
477 c
= meta_prefix_char
;
482 if (XTYPE (c
) == Lisp_Int
)
483 XSETINT (c
, XINT (c
) & 0177);
490 return store_in_keymap (keymap
, c
, def
);
492 cmd
= get_keyelt (access_keymap (keymap
, c
));
496 cmd
= Fmake_sparse_keymap (Qnil
);
497 store_in_keymap (keymap
, c
, cmd
);
500 tem
= Fkeymapp (cmd
);
502 error ("Key sequence %s uses invalid prefix characters",
503 XSTRING (key
)->data
);
505 keymap
= get_keymap (cmd
);
509 /* Value is number if KEY is too long; NIL if valid but has no definition. */
511 DEFUN ("lookup-key", Flookup_key
, Slookup_key
, 2, 2, 0,
512 "In keymap KEYMAP, look up key sequence KEY. Return the definition.\n\
513 nil means undefined. See doc of `define-key' for kinds of definitions.\n\
514 A number as value means KEY is \"too long\";\n\
515 that is, characters or symbols in it except for the last one\n\
516 fail to be a valid sequence of prefix characters in KEYMAP.\n\
517 The number is how many characters at the front of KEY\n\
518 it takes to reach a non-prefix command.")
520 register Lisp_Object keymap
;
524 register Lisp_Object tem
;
525 register Lisp_Object cmd
;
526 register Lisp_Object c
;
530 keymap
= get_keymap (keymap
);
532 if (XTYPE (key
) != Lisp_Vector
533 && XTYPE (key
) != Lisp_String
)
534 key
= wrong_type_argument (Qarrayp
, key
);
536 length
= Flength (key
);
543 c
= Faref (key
, make_number (idx
));
545 if (XTYPE (c
) == Lisp_Int
549 c
= meta_prefix_char
;
554 if (XTYPE (c
) == Lisp_Int
)
555 XSETINT (c
, XINT (c
) & 0177);
561 cmd
= get_keyelt (access_keymap (keymap
, c
));
565 tem
= Fkeymapp (cmd
);
567 return make_number (idx
);
569 keymap
= get_keymap (cmd
);
574 /* Append a key to the end of a key sequence. If key_sequence is a
575 string and key is a character, the result will be another string;
576 otherwise, it will be a vector. */
578 append_key (key_sequence
, key
)
579 Lisp_Object key_sequence
, key
;
583 args
[0] = key_sequence
;
585 if (XTYPE (key_sequence
) == Lisp_String
586 && XTYPE (key
) == Lisp_Int
)
588 args
[1] = Fchar_to_string (key
);
589 return Fconcat (2, args
);
593 args
[1] = Fcons (key
, Qnil
);
594 return Fvconcat (2, args
);
599 /* Global, local, and minor mode keymap stuff. */
601 /* We can't put these variables inside current_minor_maps, since under
602 some systems, static gets macro-defined to be the empty string.
604 static Lisp_Object
*cmm_modes
, *cmm_maps
;
607 /* Store a pointer to an array of the keymaps of the currently active
608 minor modes in *buf, and return the number of maps it contains.
610 This function always returns a pointer to the same buffer, and may
611 free or reallocate it, so if you want to keep it for a long time or
612 hand it out to lisp code, copy it. This procedure will be called
613 for every key sequence read, so the nice lispy approach (return a
614 new assoclist, list, what have you) for each invocation would
615 result in a lot of consing over time.
617 If we used xrealloc/xmalloc and ran out of memory, they would throw
618 back to the command loop, which would try to read a key sequence,
619 which would call this function again, resulting in an infinite
620 loop. Instead, we'll use realloc/malloc and silently truncate the
621 list, let the key sequence be read, and hope some other piece of
622 code signals the error. */
624 current_minor_maps (modeptr
, mapptr
)
625 Lisp_Object
**modeptr
, **mapptr
;
628 Lisp_Object alist
, assoc
, var
, val
;
630 for (alist
= Vminor_mode_map_alist
;
632 alist
= XCONS (alist
)->cdr
)
633 if (CONSP (assoc
= XCONS (alist
)->car
)
634 && XTYPE (var
= XCONS (assoc
)->car
) == Lisp_Symbol
635 && ! EQ ((val
= find_symbol_value (var
)), Qunbound
)
640 Lisp_Object
*newmodes
, *newmaps
;
644 newmodes
= (Lisp_Object
*) realloc (cmm_modes
, cmm_size
*= 2);
645 newmaps
= (Lisp_Object
*) realloc (cmm_maps
, cmm_size
);
649 newmodes
= (Lisp_Object
*) malloc (cmm_size
= 30);
650 newmaps
= (Lisp_Object
*) malloc (cmm_size
);
653 if (newmaps
&& newmodes
)
655 cmm_modes
= newmodes
;
662 cmm_maps
[i
] = XCONS (assoc
)->cdr
;
666 if (modeptr
) *modeptr
= cmm_modes
;
667 if (mapptr
) *mapptr
= cmm_maps
;
671 DEFUN ("key-binding", Fkey_binding
, Skey_binding
, 1, 1, 0,
672 "Return the binding for command KEY in current keymaps.\n\
673 KEY is a string, a sequence of keystrokes.\n\
674 The binding is probably a symbol with a function definition.")
678 Lisp_Object
*maps
, value
;
681 nmaps
= current_minor_maps (0, &maps
);
682 for (i
= 0; i
< nmaps
; i
++)
683 if (! NILP (maps
[i
]))
685 value
= Flookup_key (maps
[i
], key
);
686 if (! NILP (value
) && XTYPE (value
) != Lisp_Int
)
690 if (! NILP (current_buffer
->keymap
))
692 value
= Flookup_key (current_buffer
->keymap
, key
);
693 if (! NILP (value
) && XTYPE (value
) != Lisp_Int
)
697 value
= Flookup_key (current_global_map
, key
);
698 if (! NILP (value
) && XTYPE (value
) != Lisp_Int
)
704 DEFUN ("local-key-binding", Flocal_key_binding
, Slocal_key_binding
, 1, 1, 0,
705 "Return the binding for command KEYS in current local keymap only.\n\
706 KEYS is a string, a sequence of keystrokes.\n\
707 The binding is probably a symbol with a function definition.")
711 register Lisp_Object map
;
712 map
= current_buffer
->keymap
;
715 return Flookup_key (map
, keys
);
718 DEFUN ("global-key-binding", Fglobal_key_binding
, Sglobal_key_binding
, 1, 1, 0,
719 "Return the binding for command KEYS in current global keymap only.\n\
720 KEYS is a string, a sequence of keystrokes.\n\
721 The binding is probably a symbol with a function definition.\n\
722 This function's return values are the same as those of lookup-key\n\
727 return Flookup_key (current_global_map
, keys
);
730 DEFUN ("minor-mode-key-binding", Fminor_mode_key_binding
, Sminor_mode_key_binding
, 1, 1, 0,
731 "Find the visible minor mode bindings of KEY.\n\
732 Return an alist of pairs (MODENAME . BINDING), where MODENAME is the\n\
733 the symbol which names the minor mode binding KEY, and BINDING is\n\
734 KEY's definition in that mode. In particular, if KEY has no\n\
735 minor-mode bindings, return nil. If the first binding is a\n\
736 non-prefix, all subsequent bindings will be omitted, since they would\n\
737 be ignored. Similarly, the list doesn't include non-prefix bindings\n\
738 that come after prefix bindings.")
741 Lisp_Object
*modes
, *maps
;
746 nmaps
= current_minor_maps (&modes
, &maps
);
748 for (i
= j
= 0; i
< nmaps
; i
++)
750 && ! NILP (binding
= Flookup_key (maps
[i
], key
))
751 && XTYPE (binding
) != Lisp_Int
)
753 if (! NILP (get_keymap_1 (binding
, 0)))
754 maps
[j
++] = Fcons (modes
[i
], binding
);
756 return Fcons (Fcons (modes
[i
], binding
), Qnil
);
759 return Flist (j
, maps
);
762 DEFUN ("global-set-key", Fglobal_set_key
, Sglobal_set_key
, 2, 2,
763 "kSet key globally: \nCSet key %s to command: ",
764 "Give KEY a global binding as COMMAND.\n\
765 COMMAND is a symbol naming an interactively-callable function.\n\
766 KEY is a string representing a sequence of keystrokes.\n\
767 Note that if KEY has a local binding in the current buffer\n\
768 that local binding will continue to shadow any global binding.")
770 Lisp_Object keys
, function
;
772 if (XTYPE (keys
) != Lisp_Vector
773 && XTYPE (keys
) != Lisp_String
)
774 keys
= wrong_type_argument (Qarrayp
, keys
);
776 Fdefine_key (current_global_map
, keys
, function
);
780 DEFUN ("local-set-key", Flocal_set_key
, Slocal_set_key
, 2, 2,
781 "kSet key locally: \nCSet key %s locally to command: ",
782 "Give KEY a local binding as COMMAND.\n\
783 COMMAND is a symbol naming an interactively-callable function.\n\
784 KEY is a string representing a sequence of keystrokes.\n\
785 The binding goes in the current buffer's local map,\n\
786 which is shared with other buffers in the same major mode.")
788 Lisp_Object keys
, function
;
790 register Lisp_Object map
;
791 map
= current_buffer
->keymap
;
794 map
= Fmake_sparse_keymap (Qnil
);
795 current_buffer
->keymap
= map
;
798 if (XTYPE (keys
) != Lisp_Vector
799 && XTYPE (keys
) != Lisp_String
)
800 keys
= wrong_type_argument (Qarrayp
, keys
);
802 Fdefine_key (map
, keys
, function
);
806 DEFUN ("global-unset-key", Fglobal_unset_key
, Sglobal_unset_key
,
807 1, 1, "kUnset key globally: ",
808 "Remove global binding of KEY.\n\
809 KEY is a string representing a sequence of keystrokes.")
813 return Fglobal_set_key (keys
, Qnil
);
816 DEFUN ("local-unset-key", Flocal_unset_key
, Slocal_unset_key
, 1, 1,
817 "kUnset key locally: ",
818 "Remove local binding of KEY.\n\
819 KEY is a string representing a sequence of keystrokes.")
823 if (!NILP (current_buffer
->keymap
))
824 Flocal_set_key (keys
, Qnil
);
828 DEFUN ("define-prefix-command", Fdefine_prefix_command
, Sdefine_prefix_command
, 1, 2, 0,
829 "Define COMMAND as a prefix command.\n\
830 A new sparse keymap is stored as COMMAND's function definition and its value.\n\
831 If a second optional argument MAPVAR is given, the map is stored as\n\
832 its value instead of as COMMAND's value; but COMMAND is still defined\n\
835 Lisp_Object name
, mapvar
;
838 map
= Fmake_sparse_keymap (Qnil
);
847 DEFUN ("use-global-map", Fuse_global_map
, Suse_global_map
, 1, 1, 0,
848 "Select KEYMAP as the global keymap.")
852 keymap
= get_keymap (keymap
);
853 current_global_map
= keymap
;
857 DEFUN ("use-local-map", Fuse_local_map
, Suse_local_map
, 1, 1, 0,
858 "Select KEYMAP as the local keymap.\n\
859 If KEYMAP is nil, that means no local keymap.")
864 keymap
= get_keymap (keymap
);
866 current_buffer
->keymap
= keymap
;
871 DEFUN ("current-local-map", Fcurrent_local_map
, Scurrent_local_map
, 0, 0, 0,
872 "Return current buffer's local keymap, or nil if it has none.")
875 return current_buffer
->keymap
;
878 DEFUN ("current-global-map", Fcurrent_global_map
, Scurrent_global_map
, 0, 0, 0,
879 "Return the current global keymap.")
882 return current_global_map
;
885 DEFUN ("current-minor-mode-maps", Fcurrent_minor_mode_maps
, Scurrent_minor_mode_maps
, 0, 0, 0,
886 "Return a list of keymaps for the minor modes of the current buffer.")
890 int nmaps
= current_minor_maps (0, &maps
);
892 return Flist (nmaps
, maps
);
895 /* Help functions for describing and documenting keymaps. */
897 DEFUN ("accessible-keymaps", Faccessible_keymaps
, Saccessible_keymaps
,
899 "Find all keymaps accessible via prefix characters from KEYMAP.\n\
900 Returns a list of elements of the form (KEYS . MAP), where the sequence\n\
901 KEYS starting from KEYMAP gets you to MAP. These elements are ordered\n\
902 so that the KEYS increase in length. The first element is (\"\" . KEYMAP).")
904 Lisp_Object startmap
;
906 Lisp_Object maps
, tail
;
908 maps
= Fcons (Fcons (build_string (""), get_keymap (startmap
)), Qnil
);
910 /* For each map in the list maps,
911 look at any other maps it points to,
912 and stick them at the end if they are not already in the list.
914 This is a breadth-first traversal, where tail is the queue of
915 nodes, and maps accumulates a list of all nodes visited. */
917 for (tail
= maps
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
919 register Lisp_Object thisseq
= Fcar (Fcar (tail
));
920 register Lisp_Object thismap
= Fcdr (Fcar (tail
));
921 Lisp_Object last
= make_number (XINT (Flength (thisseq
)) - 1);
923 /* Does the current sequence end in the meta-prefix-char? */
924 int is_metized
= (XINT (last
) >= 0
925 && EQ (Faref (thisseq
, last
), meta_prefix_char
));
927 for (; CONSP (thismap
); thismap
= XCONS (thismap
)->cdr
)
929 Lisp_Object elt
= XCONS (thismap
)->car
;
933 if (XTYPE (elt
) == Lisp_Vector
)
937 /* Vector keymap. Scan all the elements. */
938 for (i
= 0; i
< DENSE_TABLE_SIZE
; i
++)
940 register Lisp_Object tem
;
941 register Lisp_Object cmd
;
943 cmd
= get_keyelt (XVECTOR (elt
)->contents
[i
]);
944 if (NILP (cmd
)) continue;
945 tem
= Fkeymapp (cmd
);
948 cmd
= get_keymap (cmd
);
949 /* Ignore keymaps that are already added to maps. */
950 tem
= Frassq (cmd
, maps
);
953 /* If the last key in thisseq is meta-prefix-char,
954 turn it into a meta-ized keystroke. We know
955 that the event we're about to append is an
956 ascii keystroke since we're processing a
960 tem
= Fcopy_sequence (thisseq
);
961 Faset (tem
, last
, make_number (i
| 0200));
963 /* This new sequence is the same length as
964 thisseq, so stick it in the list right
967 Fcons (Fcons (tem
, cmd
), XCONS (tail
)->cdr
);
971 tem
= append_key (thisseq
, make_number (i
));
972 nconc2 (tail
, Fcons (Fcons (tem
, cmd
), Qnil
));
978 else if (CONSP (elt
))
980 register Lisp_Object cmd
= get_keyelt (XCONS (elt
)->cdr
);
981 register Lisp_Object tem
;
983 /* Ignore definitions that aren't keymaps themselves. */
984 tem
= Fkeymapp (cmd
);
987 /* Ignore keymaps that have been seen already. */
988 cmd
= get_keymap (cmd
);
989 tem
= Frassq (cmd
, maps
);
992 /* let elt be the event defined by this map entry. */
993 elt
= XCONS (elt
)->car
;
995 /* If the last key in thisseq is meta-prefix-char, and
996 this entry is a binding for an ascii keystroke,
997 turn it into a meta-ized keystroke. */
998 if (is_metized
&& XTYPE (elt
) == Lisp_Int
)
1000 tem
= Fcopy_sequence (thisseq
);
1001 Faset (tem
, last
, make_number (XINT (elt
) | 0200));
1003 /* This new sequence is the same length as
1004 thisseq, so stick it in the list right
1007 Fcons (Fcons (tem
, cmd
), XCONS (tail
)->cdr
);
1011 Fcons (Fcons (append_key (thisseq
, elt
), cmd
),
1022 Lisp_Object Qsingle_key_description
, Qkey_description
;
1024 DEFUN ("key-description", Fkey_description
, Skey_description
, 1, 1, 0,
1025 "Return a pretty description of key-sequence KEYS.\n\
1026 Control characters turn into \"C-foo\" sequences, meta into \"M-foo\"\n\
1027 spaces are put between sequence elements, etc.")
1031 return Fmapconcat (Qsingle_key_description
, keys
, build_string (" "));
1035 push_key_description (c
, p
)
1036 register unsigned int c
;
1053 else if (c
== Ctl('I'))
1059 else if (c
== Ctl('J'))
1065 else if (c
== Ctl('M'))
1075 if (c
> 0 && c
<= Ctl ('Z'))
1099 DEFUN ("single-key-description", Fsingle_key_description
, Ssingle_key_description
, 1, 1, 0,
1100 "Return a pretty description of command character KEY.\n\
1101 Control characters turn into C-whatever, etc.")
1105 register unsigned char c
;
1108 if (EVENT_HAS_PARAMETERS (key
))
1109 key
= EVENT_HEAD (key
);
1111 switch (XTYPE (key
))
1113 case Lisp_Int
: /* Normal character */
1114 c
= XINT (key
) & 0377;
1115 *push_key_description (c
, tem
) = 0;
1116 return build_string (tem
);
1118 case Lisp_Symbol
: /* Function key or event-symbol */
1119 return Fsymbol_name (key
);
1122 error ("KEY must be an integer, cons, or symbol.");
1127 push_text_char_description (c
, p
)
1128 register unsigned int c
;
1140 *p
++ = c
+ 64; /* 'A' - 1 */
1152 DEFUN ("text-char-description", Ftext_char_description
, Stext_char_description
, 1, 1, 0,
1153 "Return a pretty description of file-character CHAR.\n\
1154 Control characters turn into \"^char\", etc.")
1160 CHECK_NUMBER (chr
, 0);
1162 *push_text_char_description (XINT (chr
) & 0377, tem
) = 0;
1164 return build_string (tem
);
1167 /* where-is - finding a command in a set of keymaps. */
1169 DEFUN ("where-is-internal", Fwhere_is_internal
, Swhere_is_internal
, 1, 5, 0,
1170 "Return list of keys that invoke DEFINITION in KEYMAP or KEYMAP1.\n\
1171 If KEYMAP is nil, search only KEYMAP1.\n\
1172 If KEYMAP1 is nil, use the current global map.\n\
1174 If optional 4th arg FIRSTONLY is non-nil,\n\
1175 return a string representing the first key sequence found,\n\
1176 rather than a list of all possible key sequences.\n\
1178 If optional 5th arg NOINDIRECT is non-nil, don't follow indirections\n\
1179 to other keymaps or slots. This makes it possible to search for an\n\
1180 indirect definition itself.")
1181 (definition
, local_keymap
, global_keymap
, firstonly
, noindirect
)
1182 Lisp_Object definition
, local_keymap
, global_keymap
;
1183 Lisp_Object firstonly
, noindirect
;
1185 register Lisp_Object maps
;
1188 if (NILP (global_keymap
))
1189 global_keymap
= current_global_map
;
1191 if (!NILP (local_keymap
))
1192 maps
= nconc2 (Faccessible_keymaps (get_keymap (local_keymap
)),
1193 Faccessible_keymaps (get_keymap (global_keymap
)));
1195 maps
= Faccessible_keymaps (get_keymap (global_keymap
));
1199 for (; !NILP (maps
); maps
= Fcdr (maps
))
1201 /* Key sequence to reach map */
1202 register Lisp_Object
this = Fcar (Fcar (maps
));
1204 /* The map that it reaches */
1205 register Lisp_Object map
= Fcdr (Fcar (maps
));
1207 /* If Fcar (map) is a VECTOR, the current element within that vector. */
1210 /* In order to fold [META-PREFIX-CHAR CHAR] sequences into
1211 [M-CHAR] sequences, check if last character of the sequence
1212 is the meta-prefix char. */
1213 Lisp_Object last
= make_number (XINT (Flength (this)) - 1);
1214 int last_is_meta
= (XINT (last
) >= 0
1215 && EQ (Faref (this, last
), meta_prefix_char
));
1221 /* Because the code we want to run on each binding is rather
1222 large, we don't want to have two separate loop bodies for
1223 sparse keymap bindings and tables; we want to iterate one
1224 loop body over both keymap and vector bindings.
1226 For this reason, if Fcar (map) is a vector, we don't
1227 advance map to the next element until i indicates that we
1228 have finished off the vector. */
1230 Lisp_Object elt
= XCONS (map
)->car
;
1231 Lisp_Object key
, binding
, sequence
;
1235 /* Set key and binding to the current key and binding, and
1236 advance map and i to the next binding. */
1237 if (XTYPE (elt
) == Lisp_Vector
)
1239 /* In a vector, look at each element. */
1240 binding
= XVECTOR (elt
)->contents
[i
];
1244 /* If we've just finished scanning a vector, advance map
1245 to the next element, and reset i in anticipation of the
1246 next vector we may find. */
1247 if (i
>= DENSE_TABLE_SIZE
)
1249 map
= XCONS (map
)->cdr
;
1253 else if (CONSP (elt
))
1255 key
= Fcar (Fcar (map
));
1256 binding
= Fcdr (Fcar (map
));
1258 map
= XCONS (map
)->cdr
;
1261 /* We want to ignore keymap elements that are neither
1262 vectors nor conses. */
1264 map
= XCONS (map
)->cdr
;
1268 /* Search through indirections unless that's not wanted. */
1269 if (NILP (noindirect
))
1270 binding
= get_keyelt (binding
);
1272 /* End this iteration if this element does not match
1275 if (XTYPE (definition
) == Lisp_Cons
)
1278 tem
= Fequal (binding
, definition
);
1283 if (!EQ (binding
, definition
))
1286 /* We have found a match.
1287 Construct the key sequence where we found it. */
1288 if (XTYPE (key
) == Lisp_Int
&& last_is_meta
)
1290 sequence
= Fcopy_sequence (this);
1291 Faset (sequence
, last
, make_number (XINT (key
) | 0200));
1294 sequence
= append_key (this, key
);
1296 /* Verify that this key binding is not shadowed by another
1297 binding for the same key, before we say it exists.
1299 Mechanism: look for local definition of this key and if
1300 it is defined and does not match what we found then
1303 Either nil or number as value from Flookup_key
1305 if (!NILP (local_keymap
))
1307 binding
= Flookup_key (local_keymap
, sequence
);
1308 if (!NILP (binding
) && XTYPE (binding
) != Lisp_Int
)
1310 if (XTYPE (definition
) == Lisp_Cons
)
1313 tem
= Fequal (binding
, definition
);
1318 if (!EQ (binding
, definition
))
1323 /* It is a true unshadowed match. Record it. */
1325 if (!NILP (firstonly
))
1327 found
= Fcons (sequence
, found
);
1330 return Fnreverse (found
);
1333 /* Return a string listing the keys and buttons that run DEFINITION. */
1336 where_is_string (definition
)
1337 Lisp_Object definition
;
1339 register Lisp_Object keys
, keys1
;
1341 keys
= Fwhere_is_internal (definition
,
1342 current_buffer
->keymap
, Qnil
, Qnil
, Qnil
);
1343 keys1
= Fmapconcat (Qkey_description
, keys
, build_string (", "));
1348 DEFUN ("where-is", Fwhere_is
, Swhere_is
, 1, 1, "CWhere is command: ",
1349 "Print message listing key sequences that invoke specified command.\n\
1350 Argument is a command definition, usually a symbol with a function definition.")
1352 Lisp_Object definition
;
1354 register Lisp_Object string
;
1356 CHECK_SYMBOL (definition
, 0);
1357 string
= where_is_string (definition
);
1359 if (XSTRING (string
)->size
)
1360 message ("%s is on %s", XSYMBOL (definition
)->name
->data
,
1361 XSTRING (string
)->data
);
1363 message ("%s is not on any key", XSYMBOL (definition
)->name
->data
);
1367 /* describe-bindings - summarizing all the bindings in a set of keymaps. */
1369 DEFUN ("describe-bindings", Fdescribe_bindings
, Sdescribe_bindings
, 0, 0, "",
1370 "Show a list of all defined keys, and their definitions.\n\
1371 The list is put in a buffer, which is displayed.")
1374 register Lisp_Object thisbuf
;
1375 XSET (thisbuf
, Lisp_Buffer
, current_buffer
);
1376 internal_with_output_to_temp_buffer ("*Help*",
1377 describe_buffer_bindings
,
1383 describe_buffer_bindings (descbuf
)
1384 Lisp_Object descbuf
;
1386 register Lisp_Object start1
, start2
;
1392 char *alternate_heading
1394 Alternate Characters (use anywhere the nominal character is listed):\n\
1395 nominal alternate\n\
1396 ------- ---------\n";
1398 Fset_buffer (Vstandard_output
);
1400 /* Report on alternates for keys. */
1401 if (XTYPE (Vkeyboard_translate_table
) == Lisp_String
)
1404 unsigned char *translate
= XSTRING (Vkeyboard_translate_table
)->data
;
1405 int translate_len
= XSTRING (Vkeyboard_translate_table
)->size
;
1407 for (c
= 0; c
< translate_len
; c
++)
1408 if (translate
[c
] != c
)
1413 if (alternate_heading
)
1415 insert_string (alternate_heading
);
1416 alternate_heading
= 0;
1419 bufend
= push_key_description (translate
[c
], buf
);
1420 insert (buf
, bufend
- buf
);
1421 Findent_to (make_number (16), make_number (1));
1422 bufend
= push_key_description (c
, buf
);
1423 insert (buf
, bufend
- buf
);
1433 Lisp_Object
*modes
, *maps
;
1435 /* Temporarily switch to descbuf, so that we can get that buffer's
1436 minor modes correctly. */
1437 Fset_buffer (descbuf
);
1438 nmaps
= current_minor_maps (&modes
, &maps
);
1439 Fset_buffer (Vstandard_output
);
1441 for (i
= 0; i
< nmaps
; i
++)
1443 if (XTYPE (modes
[i
]) == Lisp_Symbol
)
1446 insert_string (XSYMBOL (modes
[i
])->name
->data
);
1450 insert_string ("Strangely Named");
1451 insert_string (" Minor Mode Bindings:\n");
1452 insert_string (key_heading
);
1453 describe_map_tree (maps
[i
], 0, Qnil
);
1458 start1
= XBUFFER (descbuf
)->keymap
;
1461 insert_string ("Local Bindings:\n");
1462 insert_string (key_heading
);
1463 describe_map_tree (start1
, 0, Qnil
);
1464 insert_string ("\n");
1467 insert_string ("Global Bindings:\n");
1469 insert_string (key_heading
);
1471 describe_map_tree (current_global_map
, 0, XBUFFER (descbuf
)->keymap
);
1473 Fset_buffer (descbuf
);
1477 /* Insert a desription of the key bindings in STARTMAP,
1478 followed by those of all maps reachable through STARTMAP.
1479 If PARTIAL is nonzero, omit certain "uninteresting" commands
1480 (such as `undefined').
1481 If SHADOW is non-nil, it is another map;
1482 don't mention keys which would be shadowed by it. */
1485 describe_map_tree (startmap
, partial
, shadow
)
1486 Lisp_Object startmap
, shadow
;
1489 register Lisp_Object elt
, sh
;
1491 struct gcpro gcpro1
;
1493 maps
= Faccessible_keymaps (startmap
);
1496 for (; !NILP (maps
); maps
= Fcdr (maps
))
1501 /* If there is no shadow keymap given, don't shadow. */
1505 /* If the sequence by which we reach this keymap is zero-length,
1506 then the shadow map for this keymap is just SHADOW. */
1507 else if ((XTYPE (sh
) == Lisp_String
1508 && XSTRING (sh
)->size
== 0)
1509 || (XTYPE (sh
) == Lisp_Vector
1510 && XVECTOR (sh
)->size
== 0))
1513 /* If the sequence by which we reach this keymap actually has
1514 some elements, then the sequence's definition in SHADOW is
1515 what we should use. */
1518 sh
= Flookup_key (shadow
, Fcar (elt
));
1519 if (XTYPE (sh
) == Lisp_Int
)
1523 /* If sh is null (meaning that the current map is not shadowed),
1524 or a keymap (meaning that bindings from the current map might
1525 show through), describe the map. Otherwise, sh is a command
1526 that completely shadows the current map, and we shouldn't
1528 if (NILP (sh
) || !NILP (Fkeymapp (sh
)))
1529 describe_map (Fcdr (elt
), Fcar (elt
), partial
, sh
);
1536 describe_command (definition
)
1537 Lisp_Object definition
;
1539 register Lisp_Object tem1
;
1541 Findent_to (make_number (16), make_number (1));
1543 if (XTYPE (definition
) == Lisp_Symbol
)
1545 XSET (tem1
, Lisp_String
, XSYMBOL (definition
)->name
);
1547 insert_string ("\n");
1551 tem1
= Fkeymapp (definition
);
1553 insert_string ("Prefix Command\n");
1555 insert_string ("??\n");
1559 /* Describe the contents of map MAP, assuming that this map itself is
1560 reached by the sequence of prefix keys KEYS (a string or vector).
1561 PARTIAL, SHADOW is as in `describe_map_tree' above. */
1564 describe_map (map
, keys
, partial
, shadow
)
1565 Lisp_Object map
, keys
;
1569 register Lisp_Object keysdesc
;
1571 if (!NILP (keys
) && Flength (keys
) > 0)
1572 keysdesc
= concat2 (Fkey_description (keys
),
1573 build_string (" "));
1577 describe_map_2 (map
, keysdesc
, describe_command
, partial
, shadow
);
1580 /* Insert a description of KEYMAP into the current buffer. */
1583 describe_map_2 (keymap
, elt_prefix
, elt_describer
, partial
, shadow
)
1584 register Lisp_Object keymap
;
1585 Lisp_Object elt_prefix
;
1586 int (*elt_describer
) ();
1591 Lisp_Object tem1
, tem2
= Qnil
;
1592 Lisp_Object suppress
;
1595 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1598 suppress
= intern ("suppress-keymap");
1600 /* This vector gets used to present single keys to Flookup_key. Since
1601 that is done once per keymap element, we don't want to cons up a
1602 fresh vector every time. */
1603 kludge
= Fmake_vector (make_number (1), Qnil
);
1605 GCPRO3 (elt_prefix
, tem2
, kludge
);
1607 for (; CONSP (keymap
); keymap
= Fcdr (keymap
))
1611 if (XTYPE (XCONS (keymap
)->car
) == Lisp_Vector
)
1612 describe_vector (XCONS (keymap
)->car
,
1613 elt_prefix
, elt_describer
, partial
, shadow
);
1616 tem1
= Fcar_safe (Fcar (keymap
));
1617 tem2
= get_keyelt (Fcdr_safe (Fcar (keymap
)));
1619 /* Don't show undefined commands or suppressed commands. */
1620 if (NILP (tem2
)) continue;
1621 if (XTYPE (tem2
) == Lisp_Symbol
&& partial
)
1623 this = Fget (tem2
, suppress
);
1628 /* Don't show a command that isn't really visible
1629 because a local definition of the same key shadows it. */
1635 XVECTOR (kludge
)->contents
[0] = tem1
;
1636 tem
= Flookup_key (shadow
, kludge
);
1637 if (!NILP (tem
)) continue;
1646 if (!NILP (elt_prefix
))
1647 insert1 (elt_prefix
);
1649 /* THIS gets the string to describe the character TEM1. */
1650 this = Fsingle_key_description (tem1
);
1653 /* Print a description of the definition of this character.
1654 elt_describer will take care of spacing out far enough
1655 for alignment purposes. */
1656 (*elt_describer
) (tem2
);
1664 describe_vector_princ (elt
)
1670 DEFUN ("describe-vector", Fdescribe_vector
, Sdescribe_vector
, 1, 1, 0,
1671 "Print on `standard-output' a description of contents of VECTOR.\n\
1672 This is text showing the elements of vector matched against indices.")
1676 CHECK_VECTOR (vector
, 0);
1677 describe_vector (vector
, Qnil
, describe_vector_princ
, 0, Qnil
, Qnil
);
1680 describe_vector (vector
, elt_prefix
, elt_describer
, partial
, shadow
)
1681 register Lisp_Object vector
;
1682 Lisp_Object elt_prefix
;
1683 int (*elt_describer
) ();
1689 Lisp_Object tem1
, tem2
;
1691 Lisp_Object suppress
;
1694 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1698 /* This vector gets used to present single keys to Flookup_key. Since
1699 that is done once per vector element, we don't want to cons up a
1700 fresh vector every time. */
1701 kludge
= Fmake_vector (make_number (1), Qnil
);
1702 GCPRO3 (elt_prefix
, tem1
, kludge
);
1705 suppress
= intern ("suppress-keymap");
1707 for (i
= 0; i
< DENSE_TABLE_SIZE
; i
++)
1710 tem1
= get_keyelt (XVECTOR (vector
)->contents
[i
]);
1712 if (NILP (tem1
)) continue;
1714 /* Don't mention suppressed commands. */
1715 if (XTYPE (tem1
) == Lisp_Symbol
&& partial
)
1717 this = Fget (tem1
, suppress
);
1722 /* If this command in this map is shadowed by some other map,
1728 XVECTOR (kludge
)->contents
[0] = make_number (i
);
1729 tem
= Flookup_key (shadow
, kludge
);
1731 if (!NILP (tem
)) continue;
1740 /* Output the prefix that applies to every entry in this map. */
1741 if (!NILP (elt_prefix
))
1742 insert1 (elt_prefix
);
1744 /* Get the string to describe the character I, and print it. */
1745 XFASTINT (dummy
) = i
;
1747 /* THIS gets the string to describe the character DUMMY. */
1748 this = Fsingle_key_description (dummy
);
1751 /* Find all consecutive characters that have the same definition. */
1752 while (i
+ 1 < DENSE_TABLE_SIZE
1753 && (tem2
= get_keyelt (XVECTOR (vector
)->contents
[i
+1]),
1757 /* If we have a range of more than one character,
1758 print where the range reaches to. */
1760 if (i
!= XINT (dummy
))
1763 if (!NILP (elt_prefix
))
1764 insert1 (elt_prefix
);
1766 XFASTINT (dummy
) = i
;
1767 insert1 (Fsingle_key_description (dummy
));
1770 /* Print a description of the definition of this character.
1771 elt_describer will take care of spacing out far enough
1772 for alignment purposes. */
1773 (*elt_describer
) (tem1
);
1779 /* Apropos - finding all symbols whose names match a regexp. */
1780 Lisp_Object apropos_predicate
;
1781 Lisp_Object apropos_accumulate
;
1784 apropos_accum (symbol
, string
)
1785 Lisp_Object symbol
, string
;
1787 register Lisp_Object tem
;
1789 tem
= Fstring_match (string
, Fsymbol_name (symbol
), Qnil
);
1790 if (!NILP (tem
) && !NILP (apropos_predicate
))
1791 tem
= call1 (apropos_predicate
, symbol
);
1793 apropos_accumulate
= Fcons (symbol
, apropos_accumulate
);
1796 DEFUN ("apropos-internal", Fapropos_internal
, Sapropos_internal
, 1, 2, 0,
1797 "Show all symbols whose names contain match for REGEXP.\n\
1798 If optional 2nd arg PRED is non-nil, (funcall PRED SYM) is done\n\
1799 for each symbol and a symbol is mentioned only if that returns non-nil.\n\
1800 Return list of symbols found.")
1802 Lisp_Object string
, pred
;
1804 struct gcpro gcpro1
, gcpro2
;
1805 CHECK_STRING (string
, 0);
1806 apropos_predicate
= pred
;
1807 GCPRO2 (apropos_predicate
, apropos_accumulate
);
1808 apropos_accumulate
= Qnil
;
1809 map_obarray (Vobarray
, apropos_accum
, string
);
1810 apropos_accumulate
= Fsort (apropos_accumulate
, Qstring_lessp
);
1812 return apropos_accumulate
;
1819 Qkeymap
= intern ("keymap");
1820 staticpro (&Qkeymap
);
1822 /* Initialize the keymaps standardly used.
1823 Each one is the value of a Lisp variable, and is also
1824 pointed to by a C variable */
1826 global_map
= Fmake_keymap (Qnil
);
1827 Fset (intern ("global-map"), global_map
);
1829 meta_map
= Fmake_keymap (Qnil
);
1830 Fset (intern ("esc-map"), meta_map
);
1831 Ffset (intern ("ESC-prefix"), meta_map
);
1833 control_x_map
= Fmake_keymap (Qnil
);
1834 Fset (intern ("ctl-x-map"), control_x_map
);
1835 Ffset (intern ("Control-X-prefix"), control_x_map
);
1837 DEFVAR_LISP ("minibuffer-local-map", &Vminibuffer_local_map
,
1838 "Default keymap to use when reading from the minibuffer.");
1839 Vminibuffer_local_map
= Fmake_sparse_keymap (Qnil
);
1841 DEFVAR_LISP ("minibuffer-local-ns-map", &Vminibuffer_local_ns_map
,
1842 "Local keymap for the minibuffer when spaces are not allowed.");
1843 Vminibuffer_local_ns_map
= Fmake_sparse_keymap (Qnil
);
1845 DEFVAR_LISP ("minibuffer-local-completion-map", &Vminibuffer_local_completion_map
,
1846 "Local keymap for minibuffer input with completion.");
1847 Vminibuffer_local_completion_map
= Fmake_sparse_keymap (Qnil
);
1849 DEFVAR_LISP ("minibuffer-local-must-match-map", &Vminibuffer_local_must_match_map
,
1850 "Local keymap for minibuffer input with completion, for exact match.");
1851 Vminibuffer_local_must_match_map
= Fmake_sparse_keymap (Qnil
);
1853 current_global_map
= global_map
;
1855 DEFVAR_LISP ("minor-mode-map-alist", &Vminor_mode_map_alist
,
1856 "Alist of keymaps to use for minor modes.\n\
1857 Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read\n\
1858 key sequences and look up bindings iff VARIABLE's value is non-nil.\n\
1859 If two active keymaps bind the same key, the keymap appearing earlier\n\
1860 in the list takes precedence.");
1861 Vminor_mode_map_alist
= Qnil
;
1863 DEFVAR_LISP ("function-key-map", &Vfunction_key_map
,
1864 "Keymap mapping ASCII function key sequences onto their preferred forms.\n\
1865 This allows Emacs to recognize function keys sent from ASCII\n\
1866 terminals at any point in a key sequence.\n\
1868 The read-key-sequence function replaces subsequences bound by\n\
1869 function-key-map with their bindings. When the current local and global\n\
1870 keymaps have no binding for the current key sequence but\n\
1871 function-key-map binds a suffix of the sequence to a vector,\n\
1872 read-key-sequence replaces the matching suffix with its binding, and\n\
1873 continues with the new sequence.\n\
1875 For example, suppose function-key-map binds `ESC O P' to [pf1].\n\
1876 Typing `ESC O P' to read-key-sequence would return [pf1]. Typing\n\
1877 `C-x ESC O P' would return [?\C-x pf1]. If [pf1] were a prefix\n\
1878 key, typing `ESC O P x' would return [pf1 x].");
1879 Vfunction_key_map
= Fmake_sparse_keymap (Qnil
);
1881 Qsingle_key_description
= intern ("single-key-description");
1882 staticpro (&Qsingle_key_description
);
1884 Qkey_description
= intern ("key-description");
1885 staticpro (&Qkey_description
);
1887 Qkeymapp
= intern ("keymapp");
1888 staticpro (&Qkeymapp
);
1890 defsubr (&Skeymapp
);
1891 defsubr (&Smake_keymap
);
1892 defsubr (&Smake_sparse_keymap
);
1893 defsubr (&Scopy_keymap
);
1894 defsubr (&Skey_binding
);
1895 defsubr (&Slocal_key_binding
);
1896 defsubr (&Sglobal_key_binding
);
1897 defsubr (&Sminor_mode_key_binding
);
1898 defsubr (&Sglobal_set_key
);
1899 defsubr (&Slocal_set_key
);
1900 defsubr (&Sdefine_key
);
1901 defsubr (&Slookup_key
);
1902 defsubr (&Sglobal_unset_key
);
1903 defsubr (&Slocal_unset_key
);
1904 defsubr (&Sdefine_prefix_command
);
1905 defsubr (&Suse_global_map
);
1906 defsubr (&Suse_local_map
);
1907 defsubr (&Scurrent_local_map
);
1908 defsubr (&Scurrent_global_map
);
1909 defsubr (&Scurrent_minor_mode_maps
);
1910 defsubr (&Saccessible_keymaps
);
1911 defsubr (&Skey_description
);
1912 defsubr (&Sdescribe_vector
);
1913 defsubr (&Ssingle_key_description
);
1914 defsubr (&Stext_char_description
);
1915 defsubr (&Swhere_is_internal
);
1916 defsubr (&Swhere_is
);
1917 defsubr (&Sdescribe_bindings
);
1918 defsubr (&Sapropos_internal
);
1925 initial_define_key (global_map
, 033, "ESC-prefix");
1926 initial_define_key (global_map
, Ctl('X'), "Control-X-prefix");