1 /* Manipulation of keymaps
2 Copyright (C) 1985, 86,87,88,93,94,95,98,99, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
30 #include "termhooks.h"
31 #include "blockinput.h"
33 #include "intervals.h"
36 /* The number of elements in keymap vectors. */
37 #define DENSE_TABLE_SIZE (0200)
39 /* Actually allocate storage for these variables */
41 Lisp_Object current_global_map
; /* Current global keymap */
43 Lisp_Object global_map
; /* default global key bindings */
45 Lisp_Object meta_map
; /* The keymap used for globally bound
46 ESC-prefixed default commands */
48 Lisp_Object control_x_map
; /* The keymap used for globally bound
49 C-x-prefixed default commands */
51 /* was MinibufLocalMap */
52 Lisp_Object Vminibuffer_local_map
;
53 /* The keymap used by the minibuf for local
54 bindings when spaces are allowed in the
57 /* was MinibufLocalNSMap */
58 Lisp_Object Vminibuffer_local_ns_map
;
59 /* The keymap used by the minibuf for local
60 bindings when spaces are not encouraged
63 /* keymap used for minibuffers when doing completion */
64 /* was MinibufLocalCompletionMap */
65 Lisp_Object Vminibuffer_local_completion_map
;
67 /* keymap used for minibuffers when doing completion and require a match */
68 /* was MinibufLocalMustMatchMap */
69 Lisp_Object Vminibuffer_local_must_match_map
;
71 /* Alist of minor mode variables and keymaps. */
72 Lisp_Object Vminor_mode_map_alist
;
74 /* Alist of major-mode-specific overrides for
75 minor mode variables and keymaps. */
76 Lisp_Object Vminor_mode_overriding_map_alist
;
78 /* Keymap mapping ASCII function key sequences onto their preferred forms.
79 Initialized by the terminal-specific lisp files. See DEFVAR for more
81 Lisp_Object Vfunction_key_map
;
83 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
84 Lisp_Object Vkey_translation_map
;
86 /* A list of all commands given new bindings since a certain time
87 when nil was stored here.
88 This is used to speed up recomputation of menu key equivalents
89 when Emacs starts up. t means don't record anything here. */
90 Lisp_Object Vdefine_key_rebound_commands
;
92 Lisp_Object Qkeymapp
, Qkeymap
, Qnon_ascii
, Qmenu_item
;
94 /* A char with the CHAR_META bit set in a vector or the 0200 bit set
95 in a string key sequence is equivalent to prefixing with this
97 extern Lisp_Object meta_prefix_char
;
99 extern Lisp_Object Voverriding_local_map
;
101 /* Hash table used to cache a reverse-map to speed up calls to where-is. */
102 static Lisp_Object where_is_cache
;
103 /* Which keymaps are reverse-stored in the cache. */
104 static Lisp_Object where_is_cache_keymaps
;
106 static Lisp_Object store_in_keymap
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
107 static void fix_submap_inheritance
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
109 static Lisp_Object define_as_prefix
P_ ((Lisp_Object
, Lisp_Object
));
110 static Lisp_Object describe_buffer_bindings
P_ ((Lisp_Object
));
111 static void describe_command
P_ ((Lisp_Object
));
112 static void describe_translation
P_ ((Lisp_Object
));
113 static void describe_map
P_ ((Lisp_Object
, Lisp_Object
,
114 void (*) P_ ((Lisp_Object
)),
115 int, Lisp_Object
, Lisp_Object
*, int));
117 /* Keymap object support - constructors and predicates. */
119 DEFUN ("make-keymap", Fmake_keymap
, Smake_keymap
, 0, 1, 0,
120 "Construct and return a new keymap, of the form (keymap CHARTABLE . ALIST).\n\
121 CHARTABLE is a char-table that holds the bindings for the ASCII\n\
122 characters. ALIST is an assoc-list which holds bindings for function keys,\n\
123 mouse events, and any other things that appear in the input stream.\n\
124 All entries in it are initially nil, meaning \"command undefined\".\n\n\
125 The optional arg STRING supplies a menu name for the keymap\n\
126 in case you use it as a menu with `x-popup-menu'.")
132 tail
= Fcons (string
, Qnil
);
135 return Fcons (Qkeymap
,
136 Fcons (Fmake_char_table (Qkeymap
, Qnil
), tail
));
139 DEFUN ("make-sparse-keymap", Fmake_sparse_keymap
, Smake_sparse_keymap
, 0, 1, 0,
140 "Construct and return a new sparse keymap.\n\
141 Its car is `keymap' and its cdr is an alist of (CHAR . DEFINITION),\n\
142 which binds the character CHAR to DEFINITION, or (SYMBOL . DEFINITION),\n\
143 which binds the function key or mouse event SYMBOL to DEFINITION.\n\
144 Initially the alist is nil.\n\n\
145 The optional arg STRING supplies a menu name for the keymap\n\
146 in case you use it as a menu with `x-popup-menu'.")
151 return Fcons (Qkeymap
, Fcons (string
, Qnil
));
152 return Fcons (Qkeymap
, Qnil
);
155 /* This function is used for installing the standard key bindings
156 at initialization time.
160 initial_define_key (control_x_map, Ctl('X'), "exchange-point-and-mark"); */
163 initial_define_key (keymap
, key
, defname
)
168 store_in_keymap (keymap
, make_number (key
), intern (defname
));
172 initial_define_lispy_key (keymap
, keyname
, defname
)
177 store_in_keymap (keymap
, intern (keyname
), intern (defname
));
180 DEFUN ("keymapp", Fkeymapp
, Skeymapp
, 1, 1, 0,
181 "Return t if OBJECT is a keymap.\n\
183 A keymap is a list (keymap . ALIST),\n\
184 or a symbol whose function definition is itself a keymap.\n\
185 ALIST elements look like (CHAR . DEFN) or (SYMBOL . DEFN);\n\
186 a vector of densely packed bindings for small character codes\n\
187 is also allowed as an element.")
191 return (KEYMAPP (object
) ? Qt
: Qnil
);
194 DEFUN ("keymap-prompt", Fkeymap_prompt
, Skeymap_prompt
, 1, 1, 0,
195 "Return the prompt-string of a keymap MAP.\n\
196 If non-nil, the prompt is shown in the echo-area\n\
197 when reading a key-sequence to be looked-up in this keymap.")
203 register Lisp_Object tem
;
212 /* Check that OBJECT is a keymap (after dereferencing through any
213 symbols). If it is, return it.
215 If AUTOLOAD is non-zero and OBJECT is a symbol whose function value
216 is an autoload form, do the autoload and try again.
217 If AUTOLOAD is nonzero, callers must assume GC is possible.
219 If the map needs to be autoloaded, but AUTOLOAD is zero (and ERROR
220 is zero as well), return Qt.
222 ERROR controls how we respond if OBJECT isn't a keymap.
223 If ERROR is non-zero, signal an error; otherwise, just return Qnil.
225 Note that most of the time, we don't want to pursue autoloads.
226 Functions like Faccessible_keymaps which scan entire keymap trees
227 shouldn't load every autoloaded keymap. I'm not sure about this,
228 but it seems to me that only read_key_sequence, Flookup_key, and
229 Fdefine_key should cause keymaps to be autoloaded.
231 This function can GC when AUTOLOAD is non-zero, because it calls
232 do_autoload which can GC. */
235 get_keymap (object
, error
, autoload
)
244 if (CONSP (object
) && EQ (XCAR (object
), Qkeymap
))
247 tem
= indirect_function (object
);
250 if (EQ (XCAR (tem
), Qkeymap
))
253 /* Should we do an autoload? Autoload forms for keymaps have
254 Qkeymap as their fifth element. */
255 if ((autoload
|| !error
) && EQ (XCAR (tem
), Qautoload
))
259 tail
= Fnth (make_number (4), tem
);
260 if (EQ (tail
, Qkeymap
))
264 struct gcpro gcpro1
, gcpro2
;
266 GCPRO2 (tem
, object
);
267 do_autoload (tem
, object
);
280 wrong_type_argument (Qkeymapp
, object
);
284 /* Return the parent map of the keymap MAP, or nil if it has none.
285 We assume that MAP is a valid keymap. */
287 DEFUN ("keymap-parent", Fkeymap_parent
, Skeymap_parent
, 1, 1, 0,
288 "Return the parent keymap of KEYMAP.")
294 keymap
= get_keymap (keymap
, 1, 1);
296 /* Skip past the initial element `keymap'. */
297 list
= XCDR (keymap
);
298 for (; CONSP (list
); list
= XCDR (list
))
300 /* See if there is another `keymap'. */
305 return get_keymap (list
, 0, 1);
309 /* Check whether MAP is one of MAPS parents. */
311 keymap_memberp (map
, maps
)
312 Lisp_Object map
, maps
;
314 if (NILP (map
)) return 0;
315 while (KEYMAPP (maps
) && !EQ (map
, maps
))
316 maps
= Fkeymap_parent (maps
);
317 return (EQ (map
, maps
));
320 /* Set the parent keymap of MAP to PARENT. */
322 DEFUN ("set-keymap-parent", Fset_keymap_parent
, Sset_keymap_parent
, 2, 2, 0,
323 "Modify KEYMAP to set its parent map to PARENT.\n\
324 PARENT should be nil or another keymap.")
326 Lisp_Object keymap
, parent
;
328 Lisp_Object list
, prev
;
332 /* Force a keymap flush for the next call to where-is.
333 Since this can be called from within where-is, we don't set where_is_cache
334 directly but only where_is_cache_keymaps, since where_is_cache shouldn't
335 be changed during where-is, while where_is_cache_keymaps is only used at
336 the very beginning of where-is and can thus be changed here without any
338 This is a very minor correctness (rather than safety) issue. */
339 where_is_cache_keymaps
= Qt
;
341 keymap
= get_keymap (keymap
, 1, 1);
346 parent
= get_keymap (parent
, 1, 1);
348 /* Check for cycles. */
349 if (keymap_memberp (keymap
, parent
))
350 error ("Cyclic keymap inheritance");
353 /* Skip past the initial element `keymap'. */
358 /* If there is a parent keymap here, replace it.
359 If we came to the end, add the parent in PREV. */
360 if (!CONSP (list
) || KEYMAPP (list
))
362 /* If we already have the right parent, return now
363 so that we avoid the loops below. */
364 if (EQ (XCDR (prev
), parent
))
365 RETURN_UNGCPRO (parent
);
367 XCDR (prev
) = parent
;
373 /* Scan through for submaps, and set their parents too. */
375 for (list
= XCDR (keymap
); CONSP (list
); list
= XCDR (list
))
377 /* Stop the scan when we come to the parent. */
378 if (EQ (XCAR (list
), Qkeymap
))
381 /* If this element holds a prefix map, deal with it. */
382 if (CONSP (XCAR (list
))
383 && CONSP (XCDR (XCAR (list
))))
384 fix_submap_inheritance (keymap
, XCAR (XCAR (list
)),
387 if (VECTORP (XCAR (list
)))
388 for (i
= 0; i
< XVECTOR (XCAR (list
))->size
; i
++)
389 if (CONSP (XVECTOR (XCAR (list
))->contents
[i
]))
390 fix_submap_inheritance (keymap
, make_number (i
),
391 XVECTOR (XCAR (list
))->contents
[i
]);
393 if (CHAR_TABLE_P (XCAR (list
)))
395 Lisp_Object indices
[3];
397 map_char_table (fix_submap_inheritance
, Qnil
, XCAR (list
),
402 RETURN_UNGCPRO (parent
);
405 /* EVENT is defined in MAP as a prefix, and SUBMAP is its definition.
406 if EVENT is also a prefix in MAP's parent,
407 make sure that SUBMAP inherits that definition as its own parent. */
410 fix_submap_inheritance (map
, event
, submap
)
411 Lisp_Object map
, event
, submap
;
413 Lisp_Object map_parent
, parent_entry
;
415 /* SUBMAP is a cons that we found as a key binding.
416 Discard the other things found in a menu key binding. */
418 submap
= get_keymap (get_keyelt (submap
, 0), 0, 0);
420 /* If it isn't a keymap now, there's no work to do. */
424 map_parent
= Fkeymap_parent (map
);
425 if (!NILP (map_parent
))
427 get_keymap (access_keymap (map_parent
, event
, 0, 0, 0), 0, 0);
431 /* If MAP's parent has something other than a keymap,
432 our own submap shadows it completely. */
433 if (!CONSP (parent_entry
))
436 if (! EQ (parent_entry
, submap
))
438 Lisp_Object submap_parent
;
439 submap_parent
= submap
;
444 tem
= Fkeymap_parent (submap_parent
);
448 if (keymap_memberp (tem
, parent_entry
))
449 /* Fset_keymap_parent could create a cycle. */
456 Fset_keymap_parent (submap_parent
, parent_entry
);
460 /* Look up IDX in MAP. IDX may be any sort of event.
461 Note that this does only one level of lookup; IDX must be a single
462 event, not a sequence.
464 If T_OK is non-zero, bindings for Qt are treated as default
465 bindings; any key left unmentioned by other tables and bindings is
466 given the binding of Qt.
468 If T_OK is zero, bindings for Qt are not treated specially.
470 If NOINHERIT, don't accept a subkeymap found in an inherited keymap. */
473 access_keymap (map
, idx
, t_ok
, noinherit
, autoload
)
483 /* If idx is a list (some sort of mouse click, perhaps?),
484 the index we want to use is the car of the list, which
485 ought to be a symbol. */
486 idx
= EVENT_HEAD (idx
);
488 /* If idx is a symbol, it might have modifiers, which need to
489 be put in the canonical order. */
491 idx
= reorder_modifiers (idx
);
492 else if (INTEGERP (idx
))
493 /* Clobber the high bits that can be present on a machine
494 with more than 24 bits of integer. */
495 XSETFASTINT (idx
, XINT (idx
) & (CHAR_META
| (CHAR_META
- 1)));
497 /* Handle the special meta -> esc mapping. */
498 if (INTEGERP (idx
) && XUINT (idx
) & meta_modifier
)
500 /* See if there is a meta-map. If there's none, there is
501 no binding for IDX, unless a default binding exists in MAP. */
502 Lisp_Object meta_map
=
503 get_keymap (access_keymap (map
, meta_prefix_char
,
504 t_ok
, noinherit
, autoload
),
506 if (CONSP (meta_map
))
509 idx
= make_number (XUINT (idx
) & ~meta_modifier
);
512 /* Set IDX to t, so that we only find a default binding. */
515 /* We know there is no binding. */
521 Lisp_Object t_binding
;
522 Lisp_Object generic_binding
;
525 generic_binding
= Qnil
;
527 for (tail
= XCDR (map
);
529 || (tail
= get_keymap (tail
, 0, autoload
), CONSP (tail
)));
534 binding
= XCAR (tail
);
535 if (SYMBOLP (binding
))
537 /* If NOINHERIT, stop finding prefix definitions
538 after we pass a second occurrence of the `keymap' symbol. */
539 if (noinherit
&& EQ (binding
, Qkeymap
))
542 else if (CONSP (binding
))
544 Lisp_Object key
= XCAR (binding
);
549 val
= XCDR (binding
);
550 if (noprefix
&& KEYMAPP (val
))
553 fix_submap_inheritance (map
, idx
, val
);
554 return get_keyelt (val
, autoload
);
556 else if (INTEGERP (idx
)
557 && (XINT (idx
) & CHAR_MODIFIER_MASK
) == 0
559 && (XINT (key
) & CHAR_MODIFIER_MASK
) == 0
560 && !SINGLE_BYTE_CHAR_P (XINT (idx
))
561 && !SINGLE_BYTE_CHAR_P (XINT (key
))
562 && CHAR_VALID_P (XINT (key
), 1)
563 && !CHAR_VALID_P (XINT (key
), 0)
564 && (CHAR_CHARSET (XINT (key
))
565 == CHAR_CHARSET (XINT (idx
))))
567 /* KEY is the generic character of the charset of IDX.
568 Use KEY's binding if there isn't a binding for IDX
570 generic_binding
= XCDR (binding
);
572 else if (t_ok
&& EQ (XCAR (binding
), Qt
))
573 t_binding
= XCDR (binding
);
575 else if (VECTORP (binding
))
577 if (NATNUMP (idx
) && XFASTINT (idx
) < XVECTOR (binding
)->size
)
579 val
= XVECTOR (binding
)->contents
[XFASTINT (idx
)];
580 if (noprefix
&& KEYMAPP (val
))
583 fix_submap_inheritance (map
, idx
, val
);
584 return get_keyelt (val
, autoload
);
587 else if (CHAR_TABLE_P (binding
))
589 /* Character codes with modifiers
590 are not included in a char-table.
591 All character codes without modifiers are included. */
593 && (XFASTINT (idx
) & CHAR_MODIFIER_MASK
) == 0)
595 val
= Faref (binding
, idx
);
596 if (noprefix
&& KEYMAPP (val
))
599 fix_submap_inheritance (map
, idx
, val
);
600 return get_keyelt (val
, autoload
);
607 if (!NILP (generic_binding
))
608 return get_keyelt (generic_binding
, autoload
);
610 return get_keyelt (t_binding
, autoload
);
614 /* Given OBJECT which was found in a slot in a keymap,
615 trace indirect definitions to get the actual definition of that slot.
616 An indirect definition is a list of the form
617 (KEYMAP . INDEX), where KEYMAP is a keymap or a symbol defined as one
618 and INDEX is the object to look up in KEYMAP to yield the definition.
620 Also if OBJECT has a menu string as the first element,
621 remove that. Also remove a menu help string as second element.
623 If AUTOLOAD is nonzero, load autoloadable keymaps
624 that are referred to with indirection. */
627 get_keyelt (object
, autoload
)
628 register Lisp_Object object
;
633 if (!(CONSP (object
)))
634 /* This is really the value. */
637 /* If the keymap contents looks like (keymap ...) or (lambda ...)
639 else if (EQ (XCAR (object
), Qkeymap
) || EQ (XCAR (object
), Qlambda
))
642 /* If the keymap contents looks like (menu-item name . DEFN)
643 or (menu-item name DEFN ...) then use DEFN.
644 This is a new format menu item. */
645 else if (EQ (XCAR (object
), Qmenu_item
))
647 if (CONSP (XCDR (object
)))
651 object
= XCDR (XCDR (object
));
654 object
= XCAR (object
);
656 /* If there's a `:filter FILTER', apply FILTER to the
657 menu-item's definition to get the real definition to
659 for (; CONSP (tem
) && CONSP (XCDR (tem
)); tem
= XCDR (tem
))
660 if (EQ (XCAR (tem
), QCfilter
) && autoload
)
663 filter
= XCAR (XCDR (tem
));
664 filter
= list2 (filter
, list2 (Qquote
, object
));
665 object
= menu_item_eval_property (filter
);
674 /* If the keymap contents looks like (STRING . DEFN), use DEFN.
675 Keymap alist elements like (CHAR MENUSTRING . DEFN)
676 will be used by HierarKey menus. */
677 else if (STRINGP (XCAR (object
)))
679 object
= XCDR (object
);
680 /* Also remove a menu help string, if any,
681 following the menu item name. */
682 if (CONSP (object
) && STRINGP (XCAR (object
)))
683 object
= XCDR (object
);
684 /* Also remove the sublist that caches key equivalences, if any. */
685 if (CONSP (object
) && CONSP (XCAR (object
)))
688 carcar
= XCAR (XCAR (object
));
689 if (NILP (carcar
) || VECTORP (carcar
))
690 object
= XCDR (object
);
694 /* If the contents are (KEYMAP . ELEMENT), go indirect. */
698 map
= get_keymap (Fcar_safe (object
), 0, autoload
);
699 return (!CONSP (map
) ? object
/* Invalid keymap */
700 : access_keymap (map
, Fcdr (object
), 0, 0, autoload
));
706 store_in_keymap (keymap
, idx
, def
)
708 register Lisp_Object idx
;
709 register Lisp_Object def
;
711 /* Flush any reverse-map cache. */
712 where_is_cache
= Qnil
;
713 where_is_cache_keymaps
= Qt
;
715 /* If we are preparing to dump, and DEF is a menu element
716 with a menu item indicator, copy it to ensure it is not pure. */
717 if (CONSP (def
) && PURE_P (def
)
718 && (EQ (XCAR (def
), Qmenu_item
) || STRINGP (XCAR (def
))))
719 def
= Fcons (XCAR (def
), XCDR (def
));
721 if (!CONSP (keymap
) || !EQ (XCAR (keymap
), Qkeymap
))
722 error ("attempt to define a key in a non-keymap");
724 /* If idx is a list (some sort of mouse click, perhaps?),
725 the index we want to use is the car of the list, which
726 ought to be a symbol. */
727 idx
= EVENT_HEAD (idx
);
729 /* If idx is a symbol, it might have modifiers, which need to
730 be put in the canonical order. */
732 idx
= reorder_modifiers (idx
);
733 else if (INTEGERP (idx
))
734 /* Clobber the high bits that can be present on a machine
735 with more than 24 bits of integer. */
736 XSETFASTINT (idx
, XINT (idx
) & (CHAR_META
| (CHAR_META
- 1)));
738 /* Scan the keymap for a binding of idx. */
742 /* The cons after which we should insert new bindings. If the
743 keymap has a table element, we record its position here, so new
744 bindings will go after it; this way, the table will stay
745 towards the front of the alist and character lookups in dense
746 keymaps will remain fast. Otherwise, this just points at the
747 front of the keymap. */
748 Lisp_Object insertion_point
;
750 insertion_point
= keymap
;
751 for (tail
= XCDR (keymap
); CONSP (tail
); tail
= XCDR (tail
))
758 if (NATNUMP (idx
) && XFASTINT (idx
) < ASIZE (elt
))
760 ASET (elt
, XFASTINT (idx
), def
);
763 insertion_point
= tail
;
765 else if (CHAR_TABLE_P (elt
))
767 /* Character codes with modifiers
768 are not included in a char-table.
769 All character codes without modifiers are included. */
772 & (CHAR_ALT
| CHAR_SUPER
| CHAR_HYPER
773 | CHAR_SHIFT
| CHAR_CTL
| CHAR_META
)))
775 Faset (elt
, idx
, def
);
778 insertion_point
= tail
;
780 else if (CONSP (elt
))
782 if (EQ (idx
, XCAR (elt
)))
788 else if (EQ (elt
, Qkeymap
))
789 /* If we find a 'keymap' symbol in the spine of KEYMAP,
790 then we must have found the start of a second keymap
791 being used as the tail of KEYMAP, and a binding for IDX
792 should be inserted before it. */
799 /* We have scanned the entire keymap, and not found a binding for
800 IDX. Let's add one. */
801 XCDR (insertion_point
)
802 = Fcons (Fcons (idx
, def
), XCDR (insertion_point
));
809 copy_keymap_1 (chartable
, idx
, elt
)
810 Lisp_Object chartable
, idx
, elt
;
812 if (CONSP (elt
) && EQ (XCAR (elt
), Qkeymap
))
813 Faset (chartable
, idx
, Fcopy_keymap (elt
));
816 DEFUN ("copy-keymap", Fcopy_keymap
, Scopy_keymap
, 1, 1, 0,
817 "Return a copy of the keymap KEYMAP.\n\
818 The copy starts out with the same definitions of KEYMAP,\n\
819 but changing either the copy or KEYMAP does not affect the other.\n\
820 Any key definitions that are subkeymaps are recursively copied.\n\
821 However, a key definition which is a symbol whose definition is a keymap\n\
826 /* FIXME: This doesn't properly copy menu-items in vectors. */
827 /* FIXME: This also copies the parent keymap. */
829 register Lisp_Object copy
, tail
;
831 copy
= Fcopy_alist (get_keymap (keymap
, 1, 0));
833 for (tail
= copy
; CONSP (tail
); tail
= XCDR (tail
))
838 if (CHAR_TABLE_P (elt
))
840 Lisp_Object indices
[3];
842 elt
= Fcopy_sequence (elt
);
845 map_char_table (copy_keymap_1
, Qnil
, elt
, elt
, 0, indices
);
847 else if (VECTORP (elt
))
851 elt
= Fcopy_sequence (elt
);
854 for (i
= 0; i
< ASIZE (elt
); i
++)
855 if (CONSP (AREF (elt
, i
)) && EQ (XCAR (AREF (elt
, i
)), Qkeymap
))
856 ASET (elt
, i
, Fcopy_keymap (AREF (elt
, i
)));
858 else if (CONSP (elt
) && CONSP (XCDR (elt
)))
863 /* Is this a new format menu item. */
864 if (EQ (XCAR (tem
),Qmenu_item
))
866 /* Copy cell with menu-item marker. */
868 = Fcons (XCAR (tem
), XCDR (tem
));
873 /* Copy cell with menu-item name. */
875 = Fcons (XCAR (tem
), XCDR (tem
));
881 /* Copy cell with binding and if the binding is a keymap,
884 = Fcons (XCAR (tem
), XCDR (tem
));
887 if (CONSP (tem
) && EQ (XCAR (tem
), Qkeymap
))
888 XCAR (elt
) = Fcopy_keymap (tem
);
890 if (CONSP (tem
) && CONSP (XCAR (tem
)))
891 /* Delete cache for key equivalences. */
892 XCDR (elt
) = XCDR (tem
);
897 /* It may be an old fomat menu item.
898 Skip the optional menu string.
900 if (STRINGP (XCAR (tem
)))
902 /* Copy the cell, since copy-alist didn't go this deep. */
904 = Fcons (XCAR (tem
), XCDR (tem
));
907 /* Also skip the optional menu help string. */
908 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
911 = Fcons (XCAR (tem
), XCDR (tem
));
915 /* There may also be a list that caches key equivalences.
916 Just delete it for the new keymap. */
918 && CONSP (XCAR (tem
))
919 && (NILP (XCAR (XCAR (tem
)))
920 || VECTORP (XCAR (XCAR (tem
)))))
921 XCDR (elt
) = XCDR (tem
);
924 && CONSP (XCDR (elt
))
925 && EQ (XCAR (XCDR (elt
)), Qkeymap
))
926 XCDR (elt
) = Fcopy_keymap (XCDR (elt
));
935 /* Simple Keymap mutators and accessors. */
937 /* GC is possible in this function if it autoloads a keymap. */
939 DEFUN ("define-key", Fdefine_key
, Sdefine_key
, 3, 3, 0,
940 "Args KEYMAP, KEY, DEF. Define key sequence KEY, in KEYMAP, as DEF.\n\
941 KEYMAP is a keymap. KEY is a string or a vector of symbols and characters\n\
942 meaning a sequence of keystrokes and events.\n\
943 Non-ASCII characters with codes above 127 (such as ISO Latin-1)\n\
944 can be included if you use a vector.\n\
945 DEF is anything that can be a key's definition:\n\
946 nil (means key is undefined in this keymap),\n\
947 a command (a Lisp function suitable for interactive calling)\n\
948 a string (treated as a keyboard macro),\n\
949 a keymap (to define a prefix key),\n\
950 a symbol. When the key is looked up, the symbol will stand for its\n\
951 function definition, which should at that time be one of the above,\n\
952 or another symbol whose function definition is used, etc.\n\
953 a cons (STRING . DEFN), meaning that DEFN is the definition\n\
954 (DEFN should be a valid definition in its own right),\n\
955 or a cons (KEYMAP . CHAR), meaning use definition of CHAR in map KEYMAP.\n\
957 If KEYMAP is a sparse keymap, the pair binding KEY to DEF is added at\n\
958 the front of KEYMAP.")
965 register Lisp_Object c
;
966 register Lisp_Object cmd
;
970 struct gcpro gcpro1
, gcpro2
, gcpro3
;
972 keymap
= get_keymap (keymap
, 1, 1);
974 if (!VECTORP (key
) && !STRINGP (key
))
975 key
= wrong_type_argument (Qarrayp
, key
);
977 length
= XFASTINT (Flength (key
));
981 if (SYMBOLP (def
) && !EQ (Vdefine_key_rebound_commands
, Qt
))
982 Vdefine_key_rebound_commands
= Fcons (def
, Vdefine_key_rebound_commands
);
984 GCPRO3 (keymap
, key
, def
);
987 meta_bit
= meta_modifier
;
994 c
= Faref (key
, make_number (idx
));
996 if (CONSP (c
) && lucid_event_type_list_p (c
))
997 c
= Fevent_convert_list (c
);
1000 && (XINT (c
) & meta_bit
)
1003 c
= meta_prefix_char
;
1009 XSETINT (c
, XINT (c
) & ~meta_bit
);
1015 if (!INTEGERP (c
) && !SYMBOLP (c
) && !CONSP (c
))
1016 error ("Key sequence contains invalid events");
1019 RETURN_UNGCPRO (store_in_keymap (keymap
, c
, def
));
1021 cmd
= access_keymap (keymap
, c
, 0, 1, 1);
1023 /* If this key is undefined, make it a prefix. */
1025 cmd
= define_as_prefix (keymap
, c
);
1027 keymap
= get_keymap (cmd
, 0, 1);
1028 if (!CONSP (keymap
))
1029 /* We must use Fkey_description rather than just passing key to
1030 error; key might be a vector, not a string. */
1031 error ("Key sequence %s uses invalid prefix characters",
1032 XSTRING (Fkey_description (key
))->data
);
1036 /* Value is number if KEY is too long; NIL if valid but has no definition. */
1037 /* GC is possible in this function if it autoloads a keymap. */
1039 DEFUN ("lookup-key", Flookup_key
, Slookup_key
, 2, 3, 0,
1040 "In keymap KEYMAP, look up key sequence KEY. Return the definition.\n\
1041 nil means undefined. See doc of `define-key' for kinds of definitions.\n\
1043 A number as value means KEY is \"too long\";\n\
1044 that is, characters or symbols in it except for the last one\n\
1045 fail to be a valid sequence of prefix characters in KEYMAP.\n\
1046 The number is how many characters at the front of KEY\n\
1047 it takes to reach a non-prefix command.\n\
1049 Normally, `lookup-key' ignores bindings for t, which act as default\n\
1050 bindings, used when nothing else in the keymap applies; this makes it\n\
1051 usable as a general function for probing keymaps. However, if the\n\
1052 third optional argument ACCEPT-DEFAULT is non-nil, `lookup-key' will\n\
1053 recognize the default bindings, just as `read-key-sequence' does.")
1054 (keymap
, key
, accept_default
)
1055 register Lisp_Object keymap
;
1057 Lisp_Object accept_default
;
1060 register Lisp_Object cmd
;
1061 register Lisp_Object c
;
1063 int t_ok
= !NILP (accept_default
);
1064 struct gcpro gcpro1
;
1066 keymap
= get_keymap (keymap
, 1, 1);
1068 if (!VECTORP (key
) && !STRINGP (key
))
1069 key
= wrong_type_argument (Qarrayp
, key
);
1071 length
= XFASTINT (Flength (key
));
1080 c
= Faref (key
, make_number (idx
++));
1082 if (CONSP (c
) && lucid_event_type_list_p (c
))
1083 c
= Fevent_convert_list (c
);
1085 /* Turn the 8th bit of string chars into a meta modifier. */
1086 if (XINT (c
) & 0x80 && STRINGP (key
))
1087 XSETINT (c
, (XINT (c
) | meta_modifier
) & ~0x80);
1089 cmd
= access_keymap (keymap
, c
, t_ok
, 0, 1);
1091 RETURN_UNGCPRO (cmd
);
1093 keymap
= get_keymap (cmd
, 0, 1);
1094 if (!CONSP (keymap
))
1095 RETURN_UNGCPRO (make_number (idx
));
1101 /* Make KEYMAP define event C as a keymap (i.e., as a prefix).
1102 Assume that currently it does not define C at all.
1103 Return the keymap. */
1106 define_as_prefix (keymap
, c
)
1107 Lisp_Object keymap
, c
;
1111 cmd
= Fmake_sparse_keymap (Qnil
);
1112 /* If this key is defined as a prefix in an inherited keymap,
1113 make it a prefix in this map, and make its definition
1114 inherit the other prefix definition. */
1115 cmd
= nconc2 (cmd
, access_keymap (keymap
, c
, 0, 0, 0));
1116 store_in_keymap (keymap
, c
, cmd
);
1121 /* Append a key to the end of a key sequence. We always make a vector. */
1124 append_key (key_sequence
, key
)
1125 Lisp_Object key_sequence
, key
;
1127 Lisp_Object args
[2];
1129 args
[0] = key_sequence
;
1131 args
[1] = Fcons (key
, Qnil
);
1132 return Fvconcat (2, args
);
1136 /* Global, local, and minor mode keymap stuff. */
1138 /* We can't put these variables inside current_minor_maps, since under
1139 some systems, static gets macro-defined to be the empty string.
1141 static Lisp_Object
*cmm_modes
, *cmm_maps
;
1142 static int cmm_size
;
1144 /* Error handler used in current_minor_maps. */
1146 current_minor_maps_error ()
1151 /* Store a pointer to an array of the keymaps of the currently active
1152 minor modes in *buf, and return the number of maps it contains.
1154 This function always returns a pointer to the same buffer, and may
1155 free or reallocate it, so if you want to keep it for a long time or
1156 hand it out to lisp code, copy it. This procedure will be called
1157 for every key sequence read, so the nice lispy approach (return a
1158 new assoclist, list, what have you) for each invocation would
1159 result in a lot of consing over time.
1161 If we used xrealloc/xmalloc and ran out of memory, they would throw
1162 back to the command loop, which would try to read a key sequence,
1163 which would call this function again, resulting in an infinite
1164 loop. Instead, we'll use realloc/malloc and silently truncate the
1165 list, let the key sequence be read, and hope some other piece of
1166 code signals the error. */
1168 current_minor_maps (modeptr
, mapptr
)
1169 Lisp_Object
**modeptr
, **mapptr
;
1172 int list_number
= 0;
1173 Lisp_Object alist
, assoc
, var
, val
;
1174 Lisp_Object lists
[2];
1176 lists
[0] = Vminor_mode_overriding_map_alist
;
1177 lists
[1] = Vminor_mode_map_alist
;
1179 for (list_number
= 0; list_number
< 2; list_number
++)
1180 for (alist
= lists
[list_number
];
1182 alist
= XCDR (alist
))
1183 if ((assoc
= XCAR (alist
), CONSP (assoc
))
1184 && (var
= XCAR (assoc
), SYMBOLP (var
))
1185 && (val
= find_symbol_value (var
), !EQ (val
, Qunbound
))
1190 /* If a variable has an entry in Vminor_mode_overriding_map_alist,
1191 and also an entry in Vminor_mode_map_alist,
1192 ignore the latter. */
1193 if (list_number
== 1)
1195 val
= assq_no_quit (var
, lists
[0]);
1202 Lisp_Object
*newmodes
, *newmaps
;
1204 /* Use malloc/realloc here. See the comment above
1211 = (Lisp_Object
*) realloc (cmm_modes
,
1212 cmm_size
* sizeof *newmodes
);
1214 = (Lisp_Object
*) realloc (cmm_maps
,
1215 cmm_size
* sizeof *newmaps
);
1223 = (Lisp_Object
*) malloc (cmm_size
* sizeof *newmodes
);
1225 = (Lisp_Object
*) malloc (cmm_size
* sizeof *newmaps
);
1230 cmm_modes
= newmodes
;
1234 if (newmodes
== NULL
|| newmaps
== NULL
)
1238 /* Get the keymap definition--or nil if it is not defined. */
1239 temp
= internal_condition_case_1 (Findirect_function
,
1241 Qerror
, current_minor_maps_error
);
1245 cmm_maps
[i
] = temp
;
1250 if (modeptr
) *modeptr
= cmm_modes
;
1251 if (mapptr
) *mapptr
= cmm_maps
;
1255 DEFUN ("current-active-maps", Fcurrent_active_maps
, Scurrent_active_maps
,
1257 "Return a list of the currently active keymaps.\n\
1258 OLP if non-nil indicates that we should obey `overriding-local-map' and\n\
1259 `overriding-terminal-local-map'.")
1263 Lisp_Object keymaps
= Fcons (current_global_map
, Qnil
);
1267 if (!NILP (Voverriding_local_map
))
1268 keymaps
= Fcons (Voverriding_local_map
, keymaps
);
1269 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
1270 keymaps
= Fcons (current_kboard
->Voverriding_terminal_local_map
, keymaps
);
1272 if (NILP (XCDR (keymaps
)))
1278 local
= get_local_map (PT
, current_buffer
, Qlocal_map
);
1280 keymaps
= Fcons (local
, keymaps
);
1282 local
= get_local_map (PT
, current_buffer
, Qkeymap
);
1284 keymaps
= Fcons (local
, keymaps
);
1286 nmaps
= current_minor_maps (0, &maps
);
1288 for (i
= --nmaps
; i
>= 0; i
--)
1289 if (!NILP (maps
[i
]))
1290 keymaps
= Fcons (maps
[i
], keymaps
);
1296 /* GC is possible in this function if it autoloads a keymap. */
1298 DEFUN ("key-binding", Fkey_binding
, Skey_binding
, 1, 2, 0,
1299 "Return the binding for command KEY in current keymaps.\n\
1300 KEY is a string or vector, a sequence of keystrokes.\n\
1301 The binding is probably a symbol with a function definition.\n\
1303 Normally, `key-binding' ignores bindings for t, which act as default\n\
1304 bindings, used when nothing else in the keymap applies; this makes it\n\
1305 usable as a general function for probing keymaps. However, if the\n\
1306 optional second argument ACCEPT-DEFAULT is non-nil, `key-binding' does\n\
1307 recognize the default bindings, just as `read-key-sequence' does.")
1308 (key
, accept_default
)
1309 Lisp_Object key
, accept_default
;
1311 Lisp_Object
*maps
, value
;
1313 struct gcpro gcpro1
;
1317 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
1319 value
= Flookup_key (current_kboard
->Voverriding_terminal_local_map
,
1320 key
, accept_default
);
1321 if (! NILP (value
) && !INTEGERP (value
))
1322 RETURN_UNGCPRO (value
);
1324 else if (!NILP (Voverriding_local_map
))
1326 value
= Flookup_key (Voverriding_local_map
, key
, accept_default
);
1327 if (! NILP (value
) && !INTEGERP (value
))
1328 RETURN_UNGCPRO (value
);
1334 nmaps
= current_minor_maps (0, &maps
);
1335 /* Note that all these maps are GCPRO'd
1336 in the places where we found them. */
1338 for (i
= 0; i
< nmaps
; i
++)
1339 if (! NILP (maps
[i
]))
1341 value
= Flookup_key (maps
[i
], key
, accept_default
);
1342 if (! NILP (value
) && !INTEGERP (value
))
1343 RETURN_UNGCPRO (value
);
1346 local
= get_local_map (PT
, current_buffer
, Qkeymap
);
1349 value
= Flookup_key (local
, key
, accept_default
);
1350 if (! NILP (value
) && !INTEGERP (value
))
1351 RETURN_UNGCPRO (value
);
1354 local
= get_local_map (PT
, current_buffer
, Qlocal_map
);
1358 value
= Flookup_key (local
, key
, accept_default
);
1359 if (! NILP (value
) && !INTEGERP (value
))
1360 RETURN_UNGCPRO (value
);
1364 value
= Flookup_key (current_global_map
, key
, accept_default
);
1366 if (! NILP (value
) && !INTEGERP (value
))
1372 /* GC is possible in this function if it autoloads a keymap. */
1374 DEFUN ("local-key-binding", Flocal_key_binding
, Slocal_key_binding
, 1, 2, 0,
1375 "Return the binding for command KEYS in current local keymap only.\n\
1376 KEYS is a string, a sequence of keystrokes.\n\
1377 The binding is probably a symbol with a function definition.\n\
1379 If optional argument ACCEPT-DEFAULT is non-nil, recognize default\n\
1380 bindings; see the description of `lookup-key' for more details about this.")
1381 (keys
, accept_default
)
1382 Lisp_Object keys
, accept_default
;
1384 register Lisp_Object map
;
1385 map
= current_buffer
->keymap
;
1388 return Flookup_key (map
, keys
, accept_default
);
1391 /* GC is possible in this function if it autoloads a keymap. */
1393 DEFUN ("global-key-binding", Fglobal_key_binding
, Sglobal_key_binding
, 1, 2, 0,
1394 "Return the binding for command KEYS in current global keymap only.\n\
1395 KEYS is a string, a sequence of keystrokes.\n\
1396 The binding is probably a symbol with a function definition.\n\
1397 This function's return values are the same as those of lookup-key\n\
1400 If optional argument ACCEPT-DEFAULT is non-nil, recognize default\n\
1401 bindings; see the description of `lookup-key' for more details about this.")
1402 (keys
, accept_default
)
1403 Lisp_Object keys
, accept_default
;
1405 return Flookup_key (current_global_map
, keys
, accept_default
);
1408 /* GC is possible in this function if it autoloads a keymap. */
1410 DEFUN ("minor-mode-key-binding", Fminor_mode_key_binding
, Sminor_mode_key_binding
, 1, 2, 0,
1411 "Find the visible minor mode bindings of KEY.\n\
1412 Return an alist of pairs (MODENAME . BINDING), where MODENAME is the\n\
1413 the symbol which names the minor mode binding KEY, and BINDING is\n\
1414 KEY's definition in that mode. In particular, if KEY has no\n\
1415 minor-mode bindings, return nil. If the first binding is a\n\
1416 non-prefix, all subsequent bindings will be omitted, since they would\n\
1417 be ignored. Similarly, the list doesn't include non-prefix bindings\n\
1418 that come after prefix bindings.\n\
1420 If optional argument ACCEPT-DEFAULT is non-nil, recognize default\n\
1421 bindings; see the description of `lookup-key' for more details about this.")
1422 (key
, accept_default
)
1423 Lisp_Object key
, accept_default
;
1425 Lisp_Object
*modes
, *maps
;
1427 Lisp_Object binding
;
1429 struct gcpro gcpro1
, gcpro2
;
1431 nmaps
= current_minor_maps (&modes
, &maps
);
1432 /* Note that all these maps are GCPRO'd
1433 in the places where we found them. */
1436 GCPRO2 (key
, binding
);
1438 for (i
= j
= 0; i
< nmaps
; i
++)
1440 && !NILP (binding
= Flookup_key (maps
[i
], key
, accept_default
))
1441 && !INTEGERP (binding
))
1443 if (KEYMAPP (binding
))
1444 maps
[j
++] = Fcons (modes
[i
], binding
);
1446 RETURN_UNGCPRO (Fcons (Fcons (modes
[i
], binding
), Qnil
));
1450 return Flist (j
, maps
);
1453 DEFUN ("define-prefix-command", Fdefine_prefix_command
, Sdefine_prefix_command
, 1, 3, 0,
1454 "Define COMMAND as a prefix command. COMMAND should be a symbol.\n\
1455 A new sparse keymap is stored as COMMAND's function definition and its value.\n\
1456 If a second optional argument MAPVAR is given, the map is stored as\n\
1457 its value instead of as COMMAND's value; but COMMAND is still defined\n\
1459 The third optional argument NAME, if given, supplies a menu name\n\
1460 string for the map. This is required to use the keymap as a menu.")
1461 (command
, mapvar
, name
)
1462 Lisp_Object command
, mapvar
, name
;
1465 map
= Fmake_sparse_keymap (name
);
1466 Ffset (command
, map
);
1470 Fset (command
, map
);
1474 DEFUN ("use-global-map", Fuse_global_map
, Suse_global_map
, 1, 1, 0,
1475 "Select KEYMAP as the global keymap.")
1479 keymap
= get_keymap (keymap
, 1, 1);
1480 current_global_map
= keymap
;
1485 DEFUN ("use-local-map", Fuse_local_map
, Suse_local_map
, 1, 1, 0,
1486 "Select KEYMAP as the local keymap.\n\
1487 If KEYMAP is nil, that means no local keymap.")
1492 keymap
= get_keymap (keymap
, 1, 1);
1494 current_buffer
->keymap
= keymap
;
1499 DEFUN ("current-local-map", Fcurrent_local_map
, Scurrent_local_map
, 0, 0, 0,
1500 "Return current buffer's local keymap, or nil if it has none.")
1503 return current_buffer
->keymap
;
1506 DEFUN ("current-global-map", Fcurrent_global_map
, Scurrent_global_map
, 0, 0, 0,
1507 "Return the current global keymap.")
1510 return current_global_map
;
1513 DEFUN ("current-minor-mode-maps", Fcurrent_minor_mode_maps
, Scurrent_minor_mode_maps
, 0, 0, 0,
1514 "Return a list of keymaps for the minor modes of the current buffer.")
1518 int nmaps
= current_minor_maps (0, &maps
);
1520 return Flist (nmaps
, maps
);
1523 /* Help functions for describing and documenting keymaps. */
1527 accessible_keymaps_1 (key
, cmd
, maps
, tail
, thisseq
, is_metized
)
1528 Lisp_Object maps
, tail
, thisseq
, key
, cmd
;
1529 int is_metized
; /* If 1, `key' is assumed to be INTEGERP. */
1533 cmd
= get_keyelt (cmd
, 0);
1537 tem
= get_keymap (cmd
, 0, 0);
1541 /* Ignore keymaps that are already added to maps. */
1542 tem
= Frassq (cmd
, maps
);
1545 /* If the last key in thisseq is meta-prefix-char,
1546 turn it into a meta-ized keystroke. We know
1547 that the event we're about to append is an
1548 ascii keystroke since we're processing a
1552 int meta_bit
= meta_modifier
;
1553 Lisp_Object last
= make_number (XINT (Flength (thisseq
)) - 1);
1554 tem
= Fcopy_sequence (thisseq
);
1556 Faset (tem
, last
, make_number (XINT (key
) | meta_bit
));
1558 /* This new sequence is the same length as
1559 thisseq, so stick it in the list right
1562 = Fcons (Fcons (tem
, cmd
), XCDR (tail
));
1566 tem
= append_key (thisseq
, key
);
1567 nconc2 (tail
, Fcons (Fcons (tem
, cmd
), Qnil
));
1574 accessible_keymaps_char_table (args
, index
, cmd
)
1575 Lisp_Object args
, index
, cmd
;
1577 accessible_keymaps_1 (index
, cmd
,
1581 XINT (XCDR (XCAR (args
))));
1584 /* This function cannot GC. */
1586 DEFUN ("accessible-keymaps", Faccessible_keymaps
, Saccessible_keymaps
,
1588 "Find all keymaps accessible via prefix characters from KEYMAP.\n\
1589 Returns a list of elements of the form (KEYS . MAP), where the sequence\n\
1590 KEYS starting from KEYMAP gets you to MAP. These elements are ordered\n\
1591 so that the KEYS increase in length. The first element is ([] . KEYMAP).\n\
1592 An optional argument PREFIX, if non-nil, should be a key sequence;\n\
1593 then the value includes only maps for prefixes that start with PREFIX.")
1595 Lisp_Object keymap
, prefix
;
1597 Lisp_Object maps
, good_maps
, tail
;
1600 /* no need for gcpro because we don't autoload any keymaps. */
1603 prefixlen
= XINT (Flength (prefix
));
1607 /* If a prefix was specified, start with the keymap (if any) for
1608 that prefix, so we don't waste time considering other prefixes. */
1610 tem
= Flookup_key (keymap
, prefix
, Qt
);
1611 /* Flookup_key may give us nil, or a number,
1612 if the prefix is not defined in this particular map.
1613 It might even give us a list that isn't a keymap. */
1614 tem
= get_keymap (tem
, 0, 0);
1617 /* Convert PREFIX to a vector now, so that later on
1618 we don't have to deal with the possibility of a string. */
1619 if (STRINGP (prefix
))
1624 copy
= Fmake_vector (make_number (XSTRING (prefix
)->size
), Qnil
);
1625 for (i
= 0, i_byte
= 0; i
< XSTRING (prefix
)->size
;)
1629 FETCH_STRING_CHAR_ADVANCE (c
, prefix
, i
, i_byte
);
1630 if (SINGLE_BYTE_CHAR_P (c
) && (c
& 0200))
1631 c
^= 0200 | meta_modifier
;
1632 ASET (copy
, i_before
, make_number (c
));
1636 maps
= Fcons (Fcons (prefix
, tem
), Qnil
);
1642 maps
= Fcons (Fcons (Fmake_vector (make_number (0), Qnil
),
1643 get_keymap (keymap
, 1, 0)),
1646 /* For each map in the list maps,
1647 look at any other maps it points to,
1648 and stick them at the end if they are not already in the list.
1650 This is a breadth-first traversal, where tail is the queue of
1651 nodes, and maps accumulates a list of all nodes visited. */
1653 for (tail
= maps
; CONSP (tail
); tail
= XCDR (tail
))
1655 register Lisp_Object thisseq
, thismap
;
1657 /* Does the current sequence end in the meta-prefix-char? */
1660 thisseq
= Fcar (Fcar (tail
));
1661 thismap
= Fcdr (Fcar (tail
));
1662 last
= make_number (XINT (Flength (thisseq
)) - 1);
1663 is_metized
= (XINT (last
) >= 0
1664 /* Don't metize the last char of PREFIX. */
1665 && XINT (last
) >= prefixlen
1666 && EQ (Faref (thisseq
, last
), meta_prefix_char
));
1668 for (; CONSP (thismap
); thismap
= XCDR (thismap
))
1672 elt
= XCAR (thismap
);
1676 if (CHAR_TABLE_P (elt
))
1678 Lisp_Object indices
[3];
1680 map_char_table (accessible_keymaps_char_table
, Qnil
,
1681 elt
, Fcons (Fcons (maps
, make_number (is_metized
)),
1682 Fcons (tail
, thisseq
)),
1685 else if (VECTORP (elt
))
1689 /* Vector keymap. Scan all the elements. */
1690 for (i
= 0; i
< ASIZE (elt
); i
++)
1691 accessible_keymaps_1 (make_number (i
), AREF (elt
, i
),
1692 maps
, tail
, thisseq
, is_metized
);
1695 else if (CONSP (elt
))
1696 accessible_keymaps_1 (XCAR (elt
), XCDR (elt
),
1697 maps
, tail
, thisseq
,
1698 is_metized
&& INTEGERP (XCAR (elt
)));
1706 /* Now find just the maps whose access prefixes start with PREFIX. */
1709 for (; CONSP (maps
); maps
= XCDR (maps
))
1711 Lisp_Object elt
, thisseq
;
1713 thisseq
= XCAR (elt
);
1714 /* The access prefix must be at least as long as PREFIX,
1715 and the first elements must match those of PREFIX. */
1716 if (XINT (Flength (thisseq
)) >= prefixlen
)
1719 for (i
= 0; i
< prefixlen
; i
++)
1722 XSETFASTINT (i1
, i
);
1723 if (!EQ (Faref (thisseq
, i1
), Faref (prefix
, i1
)))
1727 good_maps
= Fcons (elt
, good_maps
);
1731 return Fnreverse (good_maps
);
1734 Lisp_Object Qsingle_key_description
, Qkey_description
;
1736 /* This function cannot GC. */
1738 DEFUN ("key-description", Fkey_description
, Skey_description
, 1, 1, 0,
1739 "Return a pretty description of key-sequence KEYS.\n\
1740 Control characters turn into \"C-foo\" sequences, meta into \"M-foo\"\n\
1741 spaces are put between sequence elements, etc.")
1748 Lisp_Object
*args
= NULL
;
1753 vector
= Fmake_vector (Flength (keys
), Qnil
);
1754 for (i
= 0, i_byte
= 0; i
< XSTRING (keys
)->size
; )
1759 FETCH_STRING_CHAR_ADVANCE (c
, keys
, i
, i_byte
);
1760 if (SINGLE_BYTE_CHAR_P (c
) && (c
& 0200))
1761 c
^= 0200 | meta_modifier
;
1762 XSETFASTINT (AREF (vector
, i_before
), c
);
1769 /* In effect, this computes
1770 (mapconcat 'single-key-description keys " ")
1771 but we shouldn't use mapconcat because it can do GC. */
1773 len
= XVECTOR (keys
)->size
;
1774 sep
= build_string (" ");
1775 /* This has one extra element at the end that we don't pass to Fconcat. */
1776 args
= (Lisp_Object
*) alloca (len
* 2 * sizeof (Lisp_Object
));
1778 for (i
= 0; i
< len
; i
++)
1780 args
[i
* 2] = Fsingle_key_description (AREF (keys
, i
), Qnil
);
1781 args
[i
* 2 + 1] = sep
;
1784 else if (CONSP (keys
))
1786 /* In effect, this computes
1787 (mapconcat 'single-key-description keys " ")
1788 but we shouldn't use mapconcat because it can do GC. */
1790 len
= XFASTINT (Flength (keys
));
1791 sep
= build_string (" ");
1792 /* This has one extra element at the end that we don't pass to Fconcat. */
1793 args
= (Lisp_Object
*) alloca (len
* 2 * sizeof (Lisp_Object
));
1795 for (i
= 0; i
< len
; i
++)
1797 args
[i
* 2] = Fsingle_key_description (XCAR (keys
), Qnil
);
1798 args
[i
* 2 + 1] = sep
;
1803 keys
= wrong_type_argument (Qarrayp
, keys
);
1806 return build_string ("");
1807 return Fconcat (len
* 2 - 1, args
);
1811 push_key_description (c
, p
, force_multibyte
)
1812 register unsigned int c
;
1814 int force_multibyte
;
1818 /* Clear all the meaningless bits above the meta bit. */
1819 c
&= meta_modifier
| ~ - meta_modifier
;
1820 c2
= c
& ~(alt_modifier
| ctrl_modifier
| hyper_modifier
1821 | meta_modifier
| shift_modifier
| super_modifier
);
1823 if (c
& alt_modifier
)
1829 if ((c
& ctrl_modifier
) != 0
1830 || (c2
< ' ' && c2
!= 27 && c2
!= '\t' && c2
!= Ctl ('M')))
1834 c
&= ~ctrl_modifier
;
1836 if (c
& hyper_modifier
)
1840 c
-= hyper_modifier
;
1842 if (c
& meta_modifier
)
1848 if (c
& shift_modifier
)
1852 c
-= shift_modifier
;
1854 if (c
& super_modifier
)
1858 c
-= super_modifier
;
1874 else if (c
== Ctl ('M'))
1882 /* `C-' already added above. */
1883 if (c
> 0 && c
<= Ctl ('Z'))
1902 || (NILP (current_buffer
->enable_multibyte_characters
)
1903 && SINGLE_BYTE_CHAR_P (c
)
1904 && !force_multibyte
))
1910 int valid_p
= SINGLE_BYTE_CHAR_P (c
) || char_valid_p (c
, 0);
1912 if (force_multibyte
&& valid_p
)
1914 if (SINGLE_BYTE_CHAR_P (c
))
1915 c
= unibyte_char_to_multibyte (c
);
1916 p
+= CHAR_STRING (c
, p
);
1918 else if (NILP (current_buffer
->enable_multibyte_characters
)
1923 /* The biggest character code uses 19 bits. */
1924 for (bit_offset
= 18; bit_offset
>= 0; bit_offset
-= 3)
1926 if (c
>= (1 << bit_offset
))
1927 *p
++ = ((c
& (7 << bit_offset
)) >> bit_offset
) + '0';
1931 p
+= CHAR_STRING (c
, p
);
1937 /* This function cannot GC. */
1939 DEFUN ("single-key-description", Fsingle_key_description
,
1940 Ssingle_key_description
, 1, 2, 0,
1941 "Return a pretty description of command character KEY.\n\
1942 Control characters turn into C-whatever, etc.\n\
1943 Optional argument NO-ANGLES non-nil means don't put angle brackets\n\
1944 around function keys and event symbols.")
1946 Lisp_Object key
, no_angles
;
1948 if (CONSP (key
) && lucid_event_type_list_p (key
))
1949 key
= Fevent_convert_list (key
);
1951 key
= EVENT_HEAD (key
);
1953 if (INTEGERP (key
)) /* Normal character */
1955 unsigned int charset
, c1
, c2
;
1956 int without_bits
= XINT (key
) & ~((-1) << CHARACTERBITS
);
1958 if (SINGLE_BYTE_CHAR_P (without_bits
))
1961 SPLIT_CHAR (without_bits
, charset
, c1
, c2
);
1964 && CHARSET_DEFINED_P (charset
)
1965 && ((c1
>= 0 && c1
< 32)
1966 || (c2
>= 0 && c2
< 32)))
1968 /* Handle a generic character. */
1970 name
= CHARSET_TABLE_INFO (charset
, CHARSET_LONG_NAME_IDX
);
1971 CHECK_STRING (name
, 0);
1972 return concat2 (build_string ("Character set "), name
);
1976 char tem
[KEY_DESCRIPTION_SIZE
], *end
;
1980 end
= push_key_description (XUINT (key
), tem
, 1);
1982 nchars
= multibyte_chars_in_text (tem
, nbytes
);
1983 if (nchars
== nbytes
)
1986 string
= build_string (tem
);
1989 string
= make_multibyte_string (tem
, nchars
, nbytes
);
1993 else if (SYMBOLP (key
)) /* Function key or event-symbol */
1995 if (NILP (no_angles
))
1998 = (char *) alloca (STRING_BYTES (XSYMBOL (key
)->name
) + 5);
1999 sprintf (buffer
, "<%s>", XSYMBOL (key
)->name
->data
);
2000 return build_string (buffer
);
2003 return Fsymbol_name (key
);
2005 else if (STRINGP (key
)) /* Buffer names in the menubar. */
2006 return Fcopy_sequence (key
);
2008 error ("KEY must be an integer, cons, symbol, or string");
2013 push_text_char_description (c
, p
)
2014 register unsigned int c
;
2026 *p
++ = c
+ 64; /* 'A' - 1 */
2038 /* This function cannot GC. */
2040 DEFUN ("text-char-description", Ftext_char_description
, Stext_char_description
, 1, 1, 0,
2041 "Return a pretty description of file-character CHARACTER.\n\
2042 Control characters turn into \"^char\", etc.")
2044 Lisp_Object character
;
2046 /* Currently MAX_MULTIBYTE_LENGTH is 4 (< 6). */
2047 unsigned char str
[6];
2050 CHECK_NUMBER (character
, 0);
2052 c
= XINT (character
);
2053 if (!SINGLE_BYTE_CHAR_P (c
))
2055 int len
= CHAR_STRING (c
, str
);
2057 return make_multibyte_string (str
, 1, len
);
2060 *push_text_char_description (c
& 0377, str
) = 0;
2062 return build_string (str
);
2065 /* Return non-zero if SEQ contains only ASCII characters, perhaps with
2068 ascii_sequence_p (seq
)
2072 int len
= XINT (Flength (seq
));
2074 for (i
= 0; i
< len
; i
++)
2076 Lisp_Object ii
, elt
;
2078 XSETFASTINT (ii
, i
);
2079 elt
= Faref (seq
, ii
);
2082 || (XUINT (elt
) & ~CHAR_META
) >= 0x80)
2090 /* where-is - finding a command in a set of keymaps. */
2092 static Lisp_Object
where_is_internal_1 ();
2093 static void where_is_internal_2 ();
2095 /* Like Flookup_key, but uses a list of keymaps SHADOW instead of a single map.
2096 Returns the first non-nil binding found in any of those maps. */
2099 shadow_lookup (shadow
, key
, flag
)
2100 Lisp_Object shadow
, key
, flag
;
2102 Lisp_Object tail
, value
;
2104 for (tail
= shadow
; CONSP (tail
); tail
= XCDR (tail
))
2106 value
= Flookup_key (XCAR (tail
), key
, flag
);
2107 if (!NILP (value
) && !NATNUMP (value
))
2113 /* This function can GC if Flookup_key autoloads any keymaps. */
2116 where_is_internal (definition
, keymaps
, firstonly
, noindirect
)
2117 Lisp_Object definition
, keymaps
;
2118 Lisp_Object firstonly
, noindirect
;
2120 Lisp_Object maps
= Qnil
;
2121 Lisp_Object found
, sequences
;
2122 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
2123 /* 1 means ignore all menu bindings entirely. */
2124 int nomenus
= !NILP (firstonly
) && !EQ (firstonly
, Qnon_ascii
);
2127 while (CONSP (found
))
2131 Faccessible_keymaps (get_keymap (XCAR (found
), 1, 0), Qnil
));
2132 found
= XCDR (found
);
2135 GCPRO5 (definition
, keymaps
, maps
, found
, sequences
);
2139 for (; !NILP (maps
); maps
= Fcdr (maps
))
2141 /* Key sequence to reach map, and the map that it reaches */
2142 register Lisp_Object
this, map
;
2144 /* In order to fold [META-PREFIX-CHAR CHAR] sequences into
2145 [M-CHAR] sequences, check if last character of the sequence
2146 is the meta-prefix char. */
2150 this = Fcar (Fcar (maps
));
2151 map
= Fcdr (Fcar (maps
));
2152 last
= make_number (XINT (Flength (this)) - 1);
2153 last_is_meta
= (XINT (last
) >= 0
2154 && EQ (Faref (this, last
), meta_prefix_char
));
2156 /* if (nomenus && !ascii_sequence_p (this)) */
2157 if (nomenus
&& XINT (last
) >= 0
2158 && !INTEGERP (Faref (this, make_number (0))))
2159 /* If no menu entries should be returned, skip over the
2160 keymaps bound to `menu-bar' and `tool-bar' and other
2161 non-ascii prefixes like `C-down-mouse-2'. */
2168 /* Because the code we want to run on each binding is rather
2169 large, we don't want to have two separate loop bodies for
2170 sparse keymap bindings and tables; we want to iterate one
2171 loop body over both keymap and vector bindings.
2173 For this reason, if Fcar (map) is a vector, we don't
2174 advance map to the next element until i indicates that we
2175 have finished off the vector. */
2176 Lisp_Object elt
, key
, binding
;
2184 /* Set key and binding to the current key and binding, and
2185 advance map and i to the next binding. */
2188 Lisp_Object sequence
;
2190 /* In a vector, look at each element. */
2191 for (i
= 0; i
< XVECTOR (elt
)->size
; i
++)
2193 binding
= AREF (elt
, i
);
2194 XSETFASTINT (key
, i
);
2195 sequence
= where_is_internal_1 (binding
, key
, definition
,
2197 last
, nomenus
, last_is_meta
);
2198 if (!NILP (sequence
))
2199 sequences
= Fcons (sequence
, sequences
);
2202 else if (CHAR_TABLE_P (elt
))
2204 Lisp_Object indices
[3];
2207 args
= Fcons (Fcons (Fcons (definition
, noindirect
),
2208 Qnil
), /* Result accumulator. */
2209 Fcons (Fcons (this, last
),
2210 Fcons (make_number (nomenus
),
2211 make_number (last_is_meta
))));
2212 map_char_table (where_is_internal_2
, Qnil
, elt
, args
,
2214 sequences
= XCDR (XCAR (args
));
2216 else if (CONSP (elt
))
2218 Lisp_Object sequence
;
2221 binding
= XCDR (elt
);
2223 sequence
= where_is_internal_1 (binding
, key
, definition
,
2225 last
, nomenus
, last_is_meta
);
2226 if (!NILP (sequence
))
2227 sequences
= Fcons (sequence
, sequences
);
2231 for (; !NILP (sequences
); sequences
= XCDR (sequences
))
2233 Lisp_Object sequence
;
2235 sequence
= XCAR (sequences
);
2237 /* Verify that this key binding is not shadowed by another
2238 binding for the same key, before we say it exists.
2240 Mechanism: look for local definition of this key and if
2241 it is defined and does not match what we found then
2244 Either nil or number as value from Flookup_key
2246 if (!EQ (shadow_lookup (keymaps
, sequence
, Qnil
), definition
))
2249 /* It is a true unshadowed match. Record it, unless it's already
2250 been seen (as could happen when inheriting keymaps). */
2251 if (NILP (Fmember (sequence
, found
)))
2252 found
= Fcons (sequence
, found
);
2254 /* If firstonly is Qnon_ascii, then we can return the first
2255 binding we find. If firstonly is not Qnon_ascii but not
2256 nil, then we should return the first ascii-only binding
2258 if (EQ (firstonly
, Qnon_ascii
))
2259 RETURN_UNGCPRO (sequence
);
2260 else if (!NILP (firstonly
) && ascii_sequence_p (sequence
))
2261 RETURN_UNGCPRO (sequence
);
2268 found
= Fnreverse (found
);
2270 /* firstonly may have been t, but we may have gone all the way through
2271 the keymaps without finding an all-ASCII key sequence. So just
2272 return the best we could find. */
2273 if (!NILP (firstonly
))
2274 return Fcar (found
);
2279 DEFUN ("where-is-internal", Fwhere_is_internal
, Swhere_is_internal
, 1, 4, 0,
2280 "Return list of keys that invoke DEFINITION.\n\
2281 If KEYMAP is non-nil, search only KEYMAP and the global keymap.\n\
2282 If KEYMAP is nil, search all the currently active keymaps.\n\
2283 If KEYMAP is a list of keymaps, search only those keymaps.\n\
2285 If optional 3rd arg FIRSTONLY is non-nil, return the first key sequence found,\n\
2286 rather than a list of all possible key sequences.\n\
2287 If FIRSTONLY is the symbol `non-ascii', return the first binding found,\n\
2288 no matter what it is.\n\
2289 If FIRSTONLY has another non-nil value, prefer sequences of ASCII characters,\n\
2290 and entirely reject menu bindings.\n\
2292 If optional 4th arg NOINDIRECT is non-nil, don't follow indirections\n\
2293 to other keymaps or slots. This makes it possible to search for an\n\
2294 indirect definition itself.")
2295 (definition
, keymap
, firstonly
, noindirect
)
2296 Lisp_Object definition
, keymap
;
2297 Lisp_Object firstonly
, noindirect
;
2299 Lisp_Object sequences
, keymaps
;
2300 /* 1 means ignore all menu bindings entirely. */
2301 int nomenus
= !NILP (firstonly
) && !EQ (firstonly
, Qnon_ascii
);
2304 /* Find the relevant keymaps. */
2305 if (CONSP (keymap
) && KEYMAPP (XCAR (keymap
)))
2307 else if (!NILP (keymap
))
2308 keymaps
= Fcons (keymap
, Fcons (current_global_map
, Qnil
));
2310 keymaps
= Fcurrent_active_maps (Qnil
);
2312 /* Only use caching for the menubar (i.e. called with (def nil t nil).
2313 We don't really need to check `keymap'. */
2314 if (nomenus
&& NILP (noindirect
) && NILP (keymap
))
2318 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2320 /* Check heuristic-consistency of the cache. */
2321 if (NILP (Fequal (keymaps
, where_is_cache_keymaps
)))
2322 where_is_cache
= Qnil
;
2324 if (NILP (where_is_cache
))
2326 /* We need to create the cache. */
2327 Lisp_Object args
[2];
2328 where_is_cache
= Fmake_hash_table (0, args
);
2329 where_is_cache_keymaps
= Qt
;
2331 /* Fill in the cache. */
2332 GCPRO4 (definition
, keymaps
, firstonly
, noindirect
);
2333 where_is_internal (definition
, keymaps
, firstonly
, noindirect
);
2336 where_is_cache_keymaps
= keymaps
;
2339 /* We want to process definitions from the last to the first.
2340 Instead of consing, copy definitions to a vector and step
2341 over that vector. */
2342 sequences
= Fgethash (definition
, where_is_cache
, Qnil
);
2343 n
= XINT (Flength (sequences
));
2344 defns
= (Lisp_Object
*) alloca (n
* sizeof *defns
);
2345 for (i
= 0; CONSP (sequences
); sequences
= XCDR (sequences
))
2346 defns
[i
++] = XCAR (sequences
);
2348 /* Verify that the key bindings are not shadowed. Note that
2349 the following can GC. */
2350 GCPRO2 (definition
, keymaps
);
2353 for (i
= n
- 1; i
>= 0; --i
)
2354 if (EQ (shadow_lookup (keymaps
, defns
[i
], Qnil
), definition
))
2356 if (ascii_sequence_p (defns
[i
]))
2362 result
= i
>= 0 ? defns
[i
] : (j
>= 0 ? defns
[j
] : Qnil
);
2367 /* Kill the cache so that where_is_internal_1 doesn't think
2368 we're filling it up. */
2369 where_is_cache
= Qnil
;
2370 result
= where_is_internal (definition
, keymaps
, firstonly
, noindirect
);
2376 /* This is the function that Fwhere_is_internal calls using map_char_table.
2378 (((DEFINITION . NOINDIRECT) . (KEYMAP . RESULT))
2380 ((THIS . LAST) . (NOMENUS . LAST_IS_META)))
2381 Since map_char_table doesn't really use the return value from this function,
2382 we the result append to RESULT, the slot in ARGS.
2384 This function can GC because it calls where_is_internal_1 which can
2388 where_is_internal_2 (args
, key
, binding
)
2389 Lisp_Object args
, key
, binding
;
2391 Lisp_Object definition
, noindirect
, this, last
;
2392 Lisp_Object result
, sequence
;
2393 int nomenus
, last_is_meta
;
2394 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2396 GCPRO3 (args
, key
, binding
);
2397 result
= XCDR (XCAR (args
));
2398 definition
= XCAR (XCAR (XCAR (args
)));
2399 noindirect
= XCDR (XCAR (XCAR (args
)));
2400 this = XCAR (XCAR (XCDR (args
)));
2401 last
= XCDR (XCAR (XCDR (args
)));
2402 nomenus
= XFASTINT (XCAR (XCDR (XCDR (args
))));
2403 last_is_meta
= XFASTINT (XCDR (XCDR (XCDR (args
))));
2405 sequence
= where_is_internal_1 (binding
, key
, definition
, noindirect
,
2406 this, last
, nomenus
, last_is_meta
);
2408 if (!NILP (sequence
))
2409 XCDR (XCAR (args
)) = Fcons (sequence
, result
);
2415 /* This function cannot GC. */
2418 where_is_internal_1 (binding
, key
, definition
, noindirect
, this, last
,
2419 nomenus
, last_is_meta
)
2420 Lisp_Object binding
, key
, definition
, noindirect
, this, last
;
2421 int nomenus
, last_is_meta
;
2423 Lisp_Object sequence
;
2425 /* Search through indirections unless that's not wanted. */
2426 if (NILP (noindirect
))
2427 binding
= get_keyelt (binding
, 0);
2429 /* End this iteration if this element does not match
2432 if (!(!NILP (where_is_cache
) /* everything "matches" during cache-fill. */
2433 || EQ (binding
, definition
)
2434 || (CONSP (definition
) && !NILP (Fequal (binding
, definition
)))))
2435 /* Doesn't match. */
2438 /* We have found a match. Construct the key sequence where we found it. */
2439 if (INTEGERP (key
) && last_is_meta
)
2441 sequence
= Fcopy_sequence (this);
2442 Faset (sequence
, last
, make_number (XINT (key
) | meta_modifier
));
2445 sequence
= append_key (this, key
);
2447 if (!NILP (where_is_cache
))
2449 Lisp_Object sequences
= Fgethash (binding
, where_is_cache
, Qnil
);
2450 Fputhash (binding
, Fcons (sequence
, sequences
), where_is_cache
);
2457 /* describe-bindings - summarizing all the bindings in a set of keymaps. */
2459 DEFUN ("describe-bindings-internal", Fdescribe_bindings_internal
, Sdescribe_bindings_internal
, 0, 2, "",
2460 "Show a list of all defined keys, and their definitions.\n\
2461 We put that list in a buffer, and display the buffer.\n\
2463 The optional argument MENUS, if non-nil, says to mention menu bindings.\n\
2464 \(Ordinarily these are omitted from the output.)\n\
2465 The optional argument PREFIX, if non-nil, should be a key sequence;\n\
2466 then we display only bindings that start with that prefix.")
2468 Lisp_Object menus
, prefix
;
2470 register Lisp_Object thisbuf
;
2471 XSETBUFFER (thisbuf
, current_buffer
);
2472 internal_with_output_to_temp_buffer ("*Help*",
2473 describe_buffer_bindings
,
2474 list3 (thisbuf
, prefix
, menus
));
2478 DEFUN ("describe-buffer-bindings", Fdescribe_buffer_bindings
, Sdescribe_buffer_bindings
, 1, 3, 0,
2479 "Insert the list of all defined keys and their definitions.\n\
2480 The list is inserted in the current buffer, while the bindings are\n\
2481 looked up in BUFFER.\n\
2482 The optional argument PREFIX, if non-nil, should be a key sequence;\n\
2483 then we display only bindings that start with that prefix.\n\
2484 The optional argument MENUS, if non-nil, says to mention menu bindings.\n\
2485 \(Ordinarily these are omitted from the output.)")
2486 (buffer
, prefix
, menus
)
2487 Lisp_Object buffer
, prefix
, menus
;
2489 Lisp_Object outbuf
, shadow
;
2490 int nomenu
= NILP (menus
);
2491 register Lisp_Object start1
;
2492 struct gcpro gcpro1
;
2494 char *alternate_heading
2496 Keyboard translations:\n\n\
2497 You type Translation\n\
2498 -------- -----------\n";
2503 outbuf
= Fcurrent_buffer();
2505 /* Report on alternates for keys. */
2506 if (STRINGP (Vkeyboard_translate_table
) && !NILP (prefix
))
2509 unsigned char *translate
= XSTRING (Vkeyboard_translate_table
)->data
;
2510 int translate_len
= XSTRING (Vkeyboard_translate_table
)->size
;
2512 for (c
= 0; c
< translate_len
; c
++)
2513 if (translate
[c
] != c
)
2515 char buf
[KEY_DESCRIPTION_SIZE
];
2518 if (alternate_heading
)
2520 insert_string (alternate_heading
);
2521 alternate_heading
= 0;
2524 bufend
= push_key_description (translate
[c
], buf
, 1);
2525 insert (buf
, bufend
- buf
);
2526 Findent_to (make_number (16), make_number (1));
2527 bufend
= push_key_description (c
, buf
, 1);
2528 insert (buf
, bufend
- buf
);
2536 if (!NILP (Vkey_translation_map
))
2537 describe_map_tree (Vkey_translation_map
, 0, Qnil
, prefix
,
2538 "Key translations", nomenu
, 1, 0);
2542 Lisp_Object
*modes
, *maps
;
2544 /* Temporarily switch to `buffer', so that we can get that buffer's
2545 minor modes correctly. */
2546 Fset_buffer (buffer
);
2548 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
2549 || !NILP (Voverriding_local_map
))
2552 nmaps
= current_minor_maps (&modes
, &maps
);
2553 Fset_buffer (outbuf
);
2555 /* Print the minor mode maps. */
2556 for (i
= 0; i
< nmaps
; i
++)
2558 /* The title for a minor mode keymap
2559 is constructed at run time.
2560 We let describe_map_tree do the actual insertion
2561 because it takes care of other features when doing so. */
2564 if (!SYMBOLP (modes
[i
]))
2567 p
= title
= (char *) alloca (42 + XSYMBOL (modes
[i
])->name
->size
);
2571 bcopy (XSYMBOL (modes
[i
])->name
->data
, p
,
2572 XSYMBOL (modes
[i
])->name
->size
);
2573 p
+= XSYMBOL (modes
[i
])->name
->size
;
2575 bcopy (" Minor Mode Bindings", p
, sizeof (" Minor Mode Bindings") - 1);
2576 p
+= sizeof (" Minor Mode Bindings") - 1;
2579 describe_map_tree (maps
[i
], 1, shadow
, prefix
, title
, nomenu
, 0, 0);
2580 shadow
= Fcons (maps
[i
], shadow
);
2584 /* Print the (major mode) local map. */
2585 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
2586 start1
= current_kboard
->Voverriding_terminal_local_map
;
2587 else if (!NILP (Voverriding_local_map
))
2588 start1
= Voverriding_local_map
;
2590 start1
= XBUFFER (buffer
)->keymap
;
2594 describe_map_tree (start1
, 1, shadow
, prefix
,
2595 "\f\nMajor Mode Bindings", nomenu
, 0, 0);
2596 shadow
= Fcons (start1
, shadow
);
2599 describe_map_tree (current_global_map
, 1, shadow
, prefix
,
2600 "\f\nGlobal Bindings", nomenu
, 0, 1);
2602 /* Print the function-key-map translations under this prefix. */
2603 if (!NILP (Vfunction_key_map
))
2604 describe_map_tree (Vfunction_key_map
, 0, Qnil
, prefix
,
2605 "\f\nFunction key map translations", nomenu
, 1, 0);
2611 /* ARG is (BUFFER PREFIX MENU-FLAG). */
2614 describe_buffer_bindings (arg
)
2617 Fset_buffer (Vstandard_output
);
2618 return Fdescribe_buffer_bindings (XCAR (arg
), XCAR (XCDR (arg
)),
2619 XCAR (XCDR (XCDR (arg
))));
2623 /* Insert a description of the key bindings in STARTMAP,
2624 followed by those of all maps reachable through STARTMAP.
2625 If PARTIAL is nonzero, omit certain "uninteresting" commands
2626 (such as `undefined').
2627 If SHADOW is non-nil, it is a list of maps;
2628 don't mention keys which would be shadowed by any of them.
2629 PREFIX, if non-nil, says mention only keys that start with PREFIX.
2630 TITLE, if not 0, is a string to insert at the beginning.
2631 TITLE should not end with a colon or a newline; we supply that.
2632 If NOMENU is not 0, then omit menu-bar commands.
2634 If TRANSL is nonzero, the definitions are actually key translations
2635 so print strings and vectors differently.
2637 If ALWAYS_TITLE is nonzero, print the title even if there are no maps
2641 describe_map_tree (startmap
, partial
, shadow
, prefix
, title
, nomenu
, transl
,
2643 Lisp_Object startmap
, shadow
, prefix
;
2650 Lisp_Object maps
, orig_maps
, seen
, sub_shadows
;
2651 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2658 orig_maps
= maps
= Faccessible_keymaps (startmap
, prefix
);
2661 GCPRO3 (maps
, seen
, sub_shadows
);
2667 /* Delete from MAPS each element that is for the menu bar. */
2668 for (list
= maps
; !NILP (list
); list
= XCDR (list
))
2670 Lisp_Object elt
, prefix
, tem
;
2673 prefix
= Fcar (elt
);
2674 if (XVECTOR (prefix
)->size
>= 1)
2676 tem
= Faref (prefix
, make_number (0));
2677 if (EQ (tem
, Qmenu_bar
))
2678 maps
= Fdelq (elt
, maps
);
2683 if (!NILP (maps
) || always_title
)
2687 insert_string (title
);
2690 insert_string (" Starting With ");
2691 insert1 (Fkey_description (prefix
));
2693 insert_string (":\n");
2695 insert_string (key_heading
);
2699 for (; !NILP (maps
); maps
= Fcdr (maps
))
2701 register Lisp_Object elt
, prefix
, tail
;
2704 prefix
= Fcar (elt
);
2708 for (tail
= shadow
; CONSP (tail
); tail
= XCDR (tail
))
2712 shmap
= XCAR (tail
);
2714 /* If the sequence by which we reach this keymap is zero-length,
2715 then the shadow map for this keymap is just SHADOW. */
2716 if ((STRINGP (prefix
) && XSTRING (prefix
)->size
== 0)
2717 || (VECTORP (prefix
) && XVECTOR (prefix
)->size
== 0))
2719 /* If the sequence by which we reach this keymap actually has
2720 some elements, then the sequence's definition in SHADOW is
2721 what we should use. */
2724 shmap
= Flookup_key (shmap
, Fcar (elt
), Qt
);
2725 if (INTEGERP (shmap
))
2729 /* If shmap is not nil and not a keymap,
2730 it completely shadows this map, so don't
2731 describe this map at all. */
2732 if (!NILP (shmap
) && !KEYMAPP (shmap
))
2736 sub_shadows
= Fcons (shmap
, sub_shadows
);
2739 /* Maps we have already listed in this loop shadow this map. */
2740 for (tail
= orig_maps
; !EQ (tail
, maps
); tail
= XCDR (tail
))
2743 tem
= Fequal (Fcar (XCAR (tail
)), prefix
);
2745 sub_shadows
= Fcons (XCDR (XCAR (tail
)), sub_shadows
);
2748 describe_map (Fcdr (elt
), prefix
,
2749 transl
? describe_translation
: describe_command
,
2750 partial
, sub_shadows
, &seen
, nomenu
);
2756 insert_string ("\n");
2761 static int previous_description_column
;
2764 describe_command (definition
)
2765 Lisp_Object definition
;
2767 register Lisp_Object tem1
;
2768 int column
= current_column ();
2769 int description_column
;
2771 /* If column 16 is no good, go to col 32;
2772 but don't push beyond that--go to next line instead. */
2776 description_column
= 32;
2778 else if (column
> 14 || (column
> 10 && previous_description_column
== 32))
2779 description_column
= 32;
2781 description_column
= 16;
2783 Findent_to (make_number (description_column
), make_number (1));
2784 previous_description_column
= description_column
;
2786 if (SYMBOLP (definition
))
2788 XSETSTRING (tem1
, XSYMBOL (definition
)->name
);
2790 insert_string ("\n");
2792 else if (STRINGP (definition
) || VECTORP (definition
))
2793 insert_string ("Keyboard Macro\n");
2794 else if (KEYMAPP (definition
))
2795 insert_string ("Prefix Command\n");
2797 insert_string ("??\n");
2801 describe_translation (definition
)
2802 Lisp_Object definition
;
2804 register Lisp_Object tem1
;
2806 Findent_to (make_number (16), make_number (1));
2808 if (SYMBOLP (definition
))
2810 XSETSTRING (tem1
, XSYMBOL (definition
)->name
);
2812 insert_string ("\n");
2814 else if (STRINGP (definition
) || VECTORP (definition
))
2816 insert1 (Fkey_description (definition
));
2817 insert_string ("\n");
2819 else if (KEYMAPP (definition
))
2820 insert_string ("Prefix Command\n");
2822 insert_string ("??\n");
2825 /* Describe the contents of map MAP, assuming that this map itself is
2826 reached by the sequence of prefix keys KEYS (a string or vector).
2827 PARTIAL, SHADOW, NOMENU are as in `describe_map_tree' above. */
2830 describe_map (map
, keys
, elt_describer
, partial
, shadow
, seen
, nomenu
)
2831 register Lisp_Object map
;
2833 void (*elt_describer
) P_ ((Lisp_Object
));
2839 Lisp_Object elt_prefix
;
2840 Lisp_Object tail
, definition
, event
;
2842 Lisp_Object suppress
;
2845 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2849 if (!NILP (keys
) && XFASTINT (Flength (keys
)) > 0)
2851 /* Call Fkey_description first, to avoid GC bug for the other string. */
2852 tem
= Fkey_description (keys
);
2853 elt_prefix
= concat2 (tem
, build_string (" "));
2859 suppress
= intern ("suppress-keymap");
2861 /* This vector gets used to present single keys to Flookup_key. Since
2862 that is done once per keymap element, we don't want to cons up a
2863 fresh vector every time. */
2864 kludge
= Fmake_vector (make_number (1), Qnil
);
2867 GCPRO3 (elt_prefix
, definition
, kludge
);
2869 for (tail
= map
; CONSP (tail
); tail
= XCDR (tail
))
2873 if (VECTORP (XCAR (tail
))
2874 || CHAR_TABLE_P (XCAR (tail
)))
2875 describe_vector (XCAR (tail
),
2876 elt_prefix
, elt_describer
, partial
, shadow
, map
,
2878 else if (CONSP (XCAR (tail
)))
2880 event
= XCAR (XCAR (tail
));
2882 /* Ignore bindings whose "keys" are not really valid events.
2883 (We get these in the frames and buffers menu.) */
2884 if (!(SYMBOLP (event
) || INTEGERP (event
)))
2887 if (nomenu
&& EQ (event
, Qmenu_bar
))
2890 definition
= get_keyelt (XCDR (XCAR (tail
)), 0);
2892 /* Don't show undefined commands or suppressed commands. */
2893 if (NILP (definition
)) continue;
2894 if (SYMBOLP (definition
) && partial
)
2896 tem
= Fget (definition
, suppress
);
2901 /* Don't show a command that isn't really visible
2902 because a local definition of the same key shadows it. */
2904 ASET (kludge
, 0, event
);
2907 tem
= shadow_lookup (shadow
, kludge
, Qt
);
2908 if (!NILP (tem
)) continue;
2911 tem
= Flookup_key (map
, kludge
, Qt
);
2912 if (!EQ (tem
, definition
)) continue;
2916 previous_description_column
= 0;
2921 if (!NILP (elt_prefix
))
2922 insert1 (elt_prefix
);
2924 /* THIS gets the string to describe the character EVENT. */
2925 insert1 (Fsingle_key_description (event
, Qnil
));
2927 /* Print a description of the definition of this character.
2928 elt_describer will take care of spacing out far enough
2929 for alignment purposes. */
2930 (*elt_describer
) (definition
);
2932 else if (EQ (XCAR (tail
), Qkeymap
))
2934 /* The same keymap might be in the structure twice, if we're
2935 using an inherited keymap. So skip anything we've already
2937 tem
= Fassq (tail
, *seen
);
2938 if (CONSP (tem
) && !NILP (Fequal (XCAR (tem
), keys
)))
2940 *seen
= Fcons (Fcons (tail
, keys
), *seen
);
2948 describe_vector_princ (elt
)
2951 Findent_to (make_number (16), make_number (1));
2956 DEFUN ("describe-vector", Fdescribe_vector
, Sdescribe_vector
, 1, 1, 0,
2957 "Insert a description of contents of VECTOR.\n\
2958 This is text showing the elements of vector matched against indices.")
2962 int count
= specpdl_ptr
- specpdl
;
2964 specbind (Qstandard_output
, Fcurrent_buffer ());
2965 CHECK_VECTOR_OR_CHAR_TABLE (vector
, 0);
2966 describe_vector (vector
, Qnil
, describe_vector_princ
, 0,
2967 Qnil
, Qnil
, (int *)0, 0);
2969 return unbind_to (count
, Qnil
);
2972 /* Insert in the current buffer a description of the contents of VECTOR.
2973 We call ELT_DESCRIBER to insert the description of one value found
2976 ELT_PREFIX describes what "comes before" the keys or indices defined
2977 by this vector. This is a human-readable string whose size
2978 is not necessarily related to the situation.
2980 If the vector is in a keymap, ELT_PREFIX is a prefix key which
2981 leads to this keymap.
2983 If the vector is a chartable, ELT_PREFIX is the vector
2984 of bytes that lead to the character set or portion of a character
2985 set described by this chartable.
2987 If PARTIAL is nonzero, it means do not mention suppressed commands
2988 (that assumes the vector is in a keymap).
2990 SHADOW is a list of keymaps that shadow this map.
2991 If it is non-nil, then we look up the key in those maps
2992 and we don't mention it now if it is defined by any of them.
2994 ENTIRE_MAP is the keymap in which this vector appears.
2995 If the definition in effect in the whole map does not match
2996 the one in this vector, we ignore this one.
2998 When describing a sub-char-table, INDICES is a list of
2999 indices at higher levels in this char-table,
3000 and CHAR_TABLE_DEPTH says how many levels down we have gone. */
3003 describe_vector (vector
, elt_prefix
, elt_describer
,
3004 partial
, shadow
, entire_map
,
3005 indices
, char_table_depth
)
3006 register Lisp_Object vector
;
3007 Lisp_Object elt_prefix
;
3008 void (*elt_describer
) P_ ((Lisp_Object
));
3011 Lisp_Object entire_map
;
3013 int char_table_depth
;
3015 Lisp_Object definition
;
3018 Lisp_Object suppress
;
3021 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3022 /* Range of elements to be handled. */
3024 /* A flag to tell if a leaf in this level of char-table is not a
3025 generic character (i.e. a complete multibyte character). */
3033 indices
= (int *) alloca (3 * sizeof (int));
3037 /* This vector gets used to present single keys to Flookup_key. Since
3038 that is done once per vector element, we don't want to cons up a
3039 fresh vector every time. */
3040 kludge
= Fmake_vector (make_number (1), Qnil
);
3041 GCPRO3 (elt_prefix
, definition
, kludge
);
3044 suppress
= intern ("suppress-keymap");
3046 if (CHAR_TABLE_P (vector
))
3048 if (char_table_depth
== 0)
3050 /* VECTOR is a top level char-table. */
3053 to
= CHAR_TABLE_ORDINARY_SLOTS
;
3057 /* VECTOR is a sub char-table. */
3058 if (char_table_depth
>= 3)
3059 /* A char-table is never that deep. */
3060 error ("Too deep char table");
3063 = (CHARSET_VALID_P (indices
[0])
3064 && ((CHARSET_DIMENSION (indices
[0]) == 1
3065 && char_table_depth
== 1)
3066 || char_table_depth
== 2));
3068 /* Meaningful elements are from 32th to 127th. */
3070 to
= SUB_CHAR_TABLE_ORDINARY_SLOTS
;
3075 /* This does the right thing for ordinary vectors. */
3079 to
= XVECTOR (vector
)->size
;
3082 for (i
= from
; i
< to
; i
++)
3086 if (CHAR_TABLE_P (vector
))
3088 if (char_table_depth
== 0 && i
>= CHAR_TABLE_SINGLE_BYTE_SLOTS
)
3091 if (i
>= CHAR_TABLE_SINGLE_BYTE_SLOTS
3092 && !CHARSET_DEFINED_P (i
- 128))
3096 = get_keyelt (XCHAR_TABLE (vector
)->contents
[i
], 0);
3099 definition
= get_keyelt (AREF (vector
, i
), 0);
3101 if (NILP (definition
)) continue;
3103 /* Don't mention suppressed commands. */
3104 if (SYMBOLP (definition
) && partial
)
3108 tem
= Fget (definition
, suppress
);
3110 if (!NILP (tem
)) continue;
3113 /* Set CHARACTER to the character this entry describes, if any.
3114 Also update *INDICES. */
3115 if (CHAR_TABLE_P (vector
))
3117 indices
[char_table_depth
] = i
;
3119 if (char_table_depth
== 0)
3122 indices
[0] = i
- 128;
3124 else if (complete_char
)
3126 character
= MAKE_CHAR (indices
[0], indices
[1], indices
[2]);
3134 /* If this binding is shadowed by some other map, ignore it. */
3135 if (!NILP (shadow
) && complete_char
)
3139 ASET (kludge
, 0, make_number (character
));
3140 tem
= shadow_lookup (shadow
, kludge
, Qt
);
3142 if (!NILP (tem
)) continue;
3145 /* Ignore this definition if it is shadowed by an earlier
3146 one in the same keymap. */
3147 if (!NILP (entire_map
) && complete_char
)
3151 ASET (kludge
, 0, make_number (character
));
3152 tem
= Flookup_key (entire_map
, kludge
, Qt
);
3154 if (!EQ (tem
, definition
))
3160 if (char_table_depth
== 0)
3165 /* For a sub char-table, show the depth by indentation.
3166 CHAR_TABLE_DEPTH can be greater than 0 only for a char-table. */
3167 if (char_table_depth
> 0)
3168 insert (" ", char_table_depth
* 2); /* depth is 1 or 2. */
3170 /* Output the prefix that applies to every entry in this map. */
3171 if (!NILP (elt_prefix
))
3172 insert1 (elt_prefix
);
3174 /* Insert or describe the character this slot is for,
3175 or a description of what it is for. */
3176 if (SUB_CHAR_TABLE_P (vector
))
3179 insert_char (character
);
3182 /* We need an octal representation for this block of
3185 sprintf (work
, "(row %d)", i
);
3186 insert (work
, strlen (work
));
3189 else if (CHAR_TABLE_P (vector
))
3192 insert1 (Fsingle_key_description (make_number (character
), Qnil
));
3195 /* Print the information for this character set. */
3196 insert_string ("<");
3197 tem2
= CHARSET_TABLE_INFO (i
- 128, CHARSET_SHORT_NAME_IDX
);
3199 insert_from_string (tem2
, 0, 0, XSTRING (tem2
)->size
,
3200 STRING_BYTES (XSTRING (tem2
)), 0);
3208 insert1 (Fsingle_key_description (make_number (character
), Qnil
));
3211 /* If we find a sub char-table within a char-table,
3212 scan it recursively; it defines the details for
3213 a character set or a portion of a character set. */
3214 if (CHAR_TABLE_P (vector
) && SUB_CHAR_TABLE_P (definition
))
3217 describe_vector (definition
, elt_prefix
, elt_describer
,
3218 partial
, shadow
, entire_map
,
3219 indices
, char_table_depth
+ 1);
3225 /* Find all consecutive characters or rows that have the same
3226 definition. But, for elements of a top level char table, if
3227 they are for charsets, we had better describe one by one even
3228 if they have the same definition. */
3229 if (CHAR_TABLE_P (vector
))
3233 if (char_table_depth
== 0)
3234 limit
= CHAR_TABLE_SINGLE_BYTE_SLOTS
;
3236 while (i
+ 1 < limit
3237 && (tem2
= get_keyelt (XCHAR_TABLE (vector
)->contents
[i
+ 1], 0),
3239 && !NILP (Fequal (tem2
, definition
)))
3244 && (tem2
= get_keyelt (AREF (vector
, i
+ 1), 0),
3246 && !NILP (Fequal (tem2
, definition
)))
3250 /* If we have a range of more than one character,
3251 print where the range reaches to. */
3253 if (i
!= starting_i
)
3257 if (!NILP (elt_prefix
))
3258 insert1 (elt_prefix
);
3260 if (CHAR_TABLE_P (vector
))
3262 if (char_table_depth
== 0)
3264 insert1 (Fsingle_key_description (make_number (i
), Qnil
));
3266 else if (complete_char
)
3268 indices
[char_table_depth
] = i
;
3269 character
= MAKE_CHAR (indices
[0], indices
[1], indices
[2]);
3270 insert_char (character
);
3274 /* We need an octal representation for this block of
3277 sprintf (work
, "(row %d)", i
);
3278 insert (work
, strlen (work
));
3283 insert1 (Fsingle_key_description (make_number (i
), Qnil
));
3287 /* Print a description of the definition of this character.
3288 elt_describer will take care of spacing out far enough
3289 for alignment purposes. */
3290 (*elt_describer
) (definition
);
3293 /* For (sub) char-table, print `defalt' slot at last. */
3294 if (CHAR_TABLE_P (vector
) && !NILP (XCHAR_TABLE (vector
)->defalt
))
3296 insert (" ", char_table_depth
* 2);
3297 insert_string ("<<default>>");
3298 (*elt_describer
) (XCHAR_TABLE (vector
)->defalt
);
3304 /* Apropos - finding all symbols whose names match a regexp. */
3305 Lisp_Object apropos_predicate
;
3306 Lisp_Object apropos_accumulate
;
3309 apropos_accum (symbol
, string
)
3310 Lisp_Object symbol
, string
;
3312 register Lisp_Object tem
;
3314 tem
= Fstring_match (string
, Fsymbol_name (symbol
), Qnil
);
3315 if (!NILP (tem
) && !NILP (apropos_predicate
))
3316 tem
= call1 (apropos_predicate
, symbol
);
3318 apropos_accumulate
= Fcons (symbol
, apropos_accumulate
);
3321 DEFUN ("apropos-internal", Fapropos_internal
, Sapropos_internal
, 1, 2, 0,
3322 "Show all symbols whose names contain match for REGEXP.\n\
3323 If optional 2nd arg PREDICATE is non-nil, (funcall PREDICATE SYMBOL) is done\n\
3324 for each symbol and a symbol is mentioned only if that returns non-nil.\n\
3325 Return list of symbols found.")
3327 Lisp_Object regexp
, predicate
;
3329 struct gcpro gcpro1
, gcpro2
;
3330 CHECK_STRING (regexp
, 0);
3331 apropos_predicate
= predicate
;
3332 GCPRO2 (apropos_predicate
, apropos_accumulate
);
3333 apropos_accumulate
= Qnil
;
3334 map_obarray (Vobarray
, apropos_accum
, regexp
);
3335 apropos_accumulate
= Fsort (apropos_accumulate
, Qstring_lessp
);
3337 return apropos_accumulate
;
3343 Qkeymap
= intern ("keymap");
3344 staticpro (&Qkeymap
);
3346 /* Now we are ready to set up this property, so we can
3347 create char tables. */
3348 Fput (Qkeymap
, Qchar_table_extra_slots
, make_number (0));
3350 /* Initialize the keymaps standardly used.
3351 Each one is the value of a Lisp variable, and is also
3352 pointed to by a C variable */
3354 global_map
= Fmake_keymap (Qnil
);
3355 Fset (intern ("global-map"), global_map
);
3357 current_global_map
= global_map
;
3358 staticpro (&global_map
);
3359 staticpro (¤t_global_map
);
3361 meta_map
= Fmake_keymap (Qnil
);
3362 Fset (intern ("esc-map"), meta_map
);
3363 Ffset (intern ("ESC-prefix"), meta_map
);
3365 control_x_map
= Fmake_keymap (Qnil
);
3366 Fset (intern ("ctl-x-map"), control_x_map
);
3367 Ffset (intern ("Control-X-prefix"), control_x_map
);
3369 DEFVAR_LISP ("define-key-rebound-commands", &Vdefine_key_rebound_commands
,
3370 "List of commands given new key bindings recently.\n\
3371 This is used for internal purposes during Emacs startup;\n\
3372 don't alter it yourself.");
3373 Vdefine_key_rebound_commands
= Qt
;
3375 DEFVAR_LISP ("minibuffer-local-map", &Vminibuffer_local_map
,
3376 "Default keymap to use when reading from the minibuffer.");
3377 Vminibuffer_local_map
= Fmake_sparse_keymap (Qnil
);
3379 DEFVAR_LISP ("minibuffer-local-ns-map", &Vminibuffer_local_ns_map
,
3380 "Local keymap for the minibuffer when spaces are not allowed.");
3381 Vminibuffer_local_ns_map
= Fmake_sparse_keymap (Qnil
);
3383 DEFVAR_LISP ("minibuffer-local-completion-map", &Vminibuffer_local_completion_map
,
3384 "Local keymap for minibuffer input with completion.");
3385 Vminibuffer_local_completion_map
= Fmake_sparse_keymap (Qnil
);
3387 DEFVAR_LISP ("minibuffer-local-must-match-map", &Vminibuffer_local_must_match_map
,
3388 "Local keymap for minibuffer input with completion, for exact match.");
3389 Vminibuffer_local_must_match_map
= Fmake_sparse_keymap (Qnil
);
3391 DEFVAR_LISP ("minor-mode-map-alist", &Vminor_mode_map_alist
,
3392 "Alist of keymaps to use for minor modes.\n\
3393 Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read\n\
3394 key sequences and look up bindings iff VARIABLE's value is non-nil.\n\
3395 If two active keymaps bind the same key, the keymap appearing earlier\n\
3396 in the list takes precedence.");
3397 Vminor_mode_map_alist
= Qnil
;
3399 DEFVAR_LISP ("minor-mode-overriding-map-alist", &Vminor_mode_overriding_map_alist
,
3400 "Alist of keymaps to use for minor modes, in current major mode.\n\
3401 This variable is a alist just like `minor-mode-map-alist', and it is\n\
3402 used the same way (and before `minor-mode-map-alist'); however,\n\
3403 it is provided for major modes to bind locally.");
3404 Vminor_mode_overriding_map_alist
= Qnil
;
3406 DEFVAR_LISP ("function-key-map", &Vfunction_key_map
,
3407 "Keymap mapping ASCII function key sequences onto their preferred forms.\n\
3408 This allows Emacs to recognize function keys sent from ASCII\n\
3409 terminals at any point in a key sequence.\n\
3411 The `read-key-sequence' function replaces any subsequence bound by\n\
3412 `function-key-map' with its binding. More precisely, when the active\n\
3413 keymaps have no binding for the current key sequence but\n\
3414 `function-key-map' binds a suffix of the sequence to a vector or string,\n\
3415 `read-key-sequence' replaces the matching suffix with its binding, and\n\
3416 continues with the new sequence.\n\
3418 The events that come from bindings in `function-key-map' are not\n\
3419 themselves looked up in `function-key-map'.\n\
3421 For example, suppose `function-key-map' binds `ESC O P' to [f1].\n\
3422 Typing `ESC O P' to `read-key-sequence' would return [f1]. Typing\n\
3423 `C-x ESC O P' would return [?\\C-x f1]. If [f1] were a prefix\n\
3424 key, typing `ESC O P x' would return [f1 x].");
3425 Vfunction_key_map
= Fmake_sparse_keymap (Qnil
);
3427 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map
,
3428 "Keymap of key translations that can override keymaps.\n\
3429 This keymap works like `function-key-map', but comes after that,\n\
3430 and applies even for keys that have ordinary bindings.");
3431 Vkey_translation_map
= Qnil
;
3433 Qsingle_key_description
= intern ("single-key-description");
3434 staticpro (&Qsingle_key_description
);
3436 Qkey_description
= intern ("key-description");
3437 staticpro (&Qkey_description
);
3439 Qkeymapp
= intern ("keymapp");
3440 staticpro (&Qkeymapp
);
3442 Qnon_ascii
= intern ("non-ascii");
3443 staticpro (&Qnon_ascii
);
3445 Qmenu_item
= intern ("menu-item");
3446 staticpro (&Qmenu_item
);
3448 where_is_cache_keymaps
= Qt
;
3449 where_is_cache
= Qnil
;
3450 staticpro (&where_is_cache
);
3451 staticpro (&where_is_cache_keymaps
);
3453 defsubr (&Skeymapp
);
3454 defsubr (&Skeymap_parent
);
3455 defsubr (&Skeymap_prompt
);
3456 defsubr (&Sset_keymap_parent
);
3457 defsubr (&Smake_keymap
);
3458 defsubr (&Smake_sparse_keymap
);
3459 defsubr (&Scopy_keymap
);
3460 defsubr (&Skey_binding
);
3461 defsubr (&Slocal_key_binding
);
3462 defsubr (&Sglobal_key_binding
);
3463 defsubr (&Sminor_mode_key_binding
);
3464 defsubr (&Sdefine_key
);
3465 defsubr (&Slookup_key
);
3466 defsubr (&Sdefine_prefix_command
);
3467 defsubr (&Suse_global_map
);
3468 defsubr (&Suse_local_map
);
3469 defsubr (&Scurrent_local_map
);
3470 defsubr (&Scurrent_global_map
);
3471 defsubr (&Scurrent_minor_mode_maps
);
3472 defsubr (&Scurrent_active_maps
);
3473 defsubr (&Saccessible_keymaps
);
3474 defsubr (&Skey_description
);
3475 defsubr (&Sdescribe_vector
);
3476 defsubr (&Ssingle_key_description
);
3477 defsubr (&Stext_char_description
);
3478 defsubr (&Swhere_is_internal
);
3479 defsubr (&Sdescribe_bindings_internal
);
3480 defsubr (&Sdescribe_buffer_bindings
);
3481 defsubr (&Sapropos_internal
);
3487 initial_define_key (global_map
, 033, "ESC-prefix");
3488 initial_define_key (global_map
, Ctl('X'), "Control-X-prefix");