comparison src/keymap.c @ 185:3d6bfa290dbd r20-3b19

Import from CVS: tag r20-3b19
author cvs
date Mon, 13 Aug 2007 09:55:28 +0200
parents e121b013d1f0
children 489f57a838ef
comparison
equal deleted inserted replaced
184:bcd2674570bf 185:3d6bfa290dbd
95 However, bucky bits ("modifiers" to the X-minded) are represented in the 95 However, bucky bits ("modifiers" to the X-minded) are represented in the
96 keymap hierarchy as well. (This lets us use EQable objects as hash keys.) 96 keymap hierarchy as well. (This lets us use EQable objects as hash keys.)
97 Each combination of modifiers (e.g. control-hyper) gets its own submap 97 Each combination of modifiers (e.g. control-hyper) gets its own submap
98 off of the main map. The hash key for a modifier combination is 98 off of the main map. The hash key for a modifier combination is
99 an integer, computed by MAKE_MODIFIER_HASH_KEY(). 99 an integer, computed by MAKE_MODIFIER_HASH_KEY().
100 100
101 If the key `C-a' was bound to some command, the hierarchy would look like 101 If the key `C-a' was bound to some command, the hierarchy would look like
102 102
103 keymap-1: associates the integer MOD_CONTROL with keymap-2 103 keymap-1: associates the integer MOD_CONTROL with keymap-2
104 keymap-2: associates "a" with the command 104 keymap-2: associates "a" with the command
105 105
140 compatibility. 140 compatibility.
141 141
142 Since keymaps are opaque, the only way to extract information from them 142 Since keymaps are opaque, the only way to extract information from them
143 is with the functions lookup-key, key-binding, local-key-binding, and 143 is with the functions lookup-key, key-binding, local-key-binding, and
144 global-key-binding, which work just as before, and the new function 144 global-key-binding, which work just as before, and the new function
145 map-keymap, which is roughly analagous to maphash. 145 map-keymap, which is roughly analagous to maphash.
146 146
147 Note that map-keymap perpetuates the illusion that the "bucky" submaps 147 Note that map-keymap perpetuates the illusion that the "bucky" submaps
148 don't exist: if you map over a keymap with bucky submaps, it will also 148 don't exist: if you map over a keymap with bucky submaps, it will also
149 map over those submaps. It does not, however, map over other random 149 map over those submaps. It does not, however, map over other random
150 submaps of the keymap, just the bucky ones. 150 submaps of the keymap, just the bucky ones.
162 struct lcrecord_header header; 162 struct lcrecord_header header;
163 Lisp_Object parents; /* Keymaps to be searched after this one 163 Lisp_Object parents; /* Keymaps to be searched after this one
164 * An ordered list */ 164 * An ordered list */
165 Lisp_Object prompt; /* Qnil or a string to print in the minibuffer 165 Lisp_Object prompt; /* Qnil or a string to print in the minibuffer
166 * when reading from this keymap */ 166 * when reading from this keymap */
167 167
168 Lisp_Object table; /* The contents of this keymap */ 168 Lisp_Object table; /* The contents of this keymap */
169 Lisp_Object inverse_table; /* The inverse mapping of the above */ 169 Lisp_Object inverse_table; /* The inverse mapping of the above */
170 170
171 Lisp_Object default_binding; /* Use this if no other binding is found 171 Lisp_Object default_binding; /* Use this if no other binding is found
172 * (this overrides parent maps and the 172 * (this overrides parent maps and the
227 Lisp_Object Qtoolbar_map; 227 Lisp_Object Qtoolbar_map;
228 228
229 static void describe_command (Lisp_Object definition); 229 static void describe_command (Lisp_Object definition);
230 static void describe_map (Lisp_Object keymap, Lisp_Object elt_prefix, 230 static void describe_map (Lisp_Object keymap, Lisp_Object elt_prefix,
231 void (*elt_describer) (Lisp_Object), 231 void (*elt_describer) (Lisp_Object),
232 int partial, 232 int partial,
233 Lisp_Object shadow, 233 Lisp_Object shadow,
234 int mice_only_p); 234 int mice_only_p);
235 Lisp_Object Qcontrol, Qctrl, Qmeta, Qsuper, Qhyper, Qalt, Qshift; 235 Lisp_Object Qcontrol, Qctrl, Qmeta, Qsuper, Qhyper, Qalt, Qshift;
236 /* Lisp_Object Qsymbol; defined in general.c */ 236 /* Lisp_Object Qsymbol; defined in general.c */
237 Lisp_Object Qbutton0, Qbutton1, Qbutton2, Qbutton3, Qbutton4, Qbutton5, 237 Lisp_Object Qbutton0, Qbutton1, Qbutton2, Qbutton3, Qbutton4, Qbutton5,
238 Qbutton6, Qbutton7; 238 Qbutton6, Qbutton7;
267 ((markobj) (keymap->sub_maps_cache)); 267 ((markobj) (keymap->sub_maps_cache));
268 ((markobj) (keymap->default_binding)); 268 ((markobj) (keymap->default_binding));
269 ((markobj) (keymap->name)); 269 ((markobj) (keymap->name));
270 return keymap->table; 270 return keymap->table;
271 } 271 }
272 272
273 static void 273 static void
274 print_keymap (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) 274 print_keymap (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
275 { 275 {
276 /* This function can GC */ 276 /* This function can GC */
277 struct keymap *keymap = XKEYMAP (obj); 277 struct keymap *keymap = XKEYMAP (obj);
405 /************************************************************************/ 405 /************************************************************************/
406 406
407 static unsigned int 407 static unsigned int
408 bucky_sym_to_bucky_bit (Lisp_Object sym) 408 bucky_sym_to_bucky_bit (Lisp_Object sym)
409 { 409 {
410 if (EQ (sym, Qcontrol)) 410 if (EQ (sym, Qcontrol)) return MOD_CONTROL;
411 return MOD_CONTROL; 411 if (EQ (sym, Qmeta)) return MOD_META;
412 else if (EQ (sym, Qmeta)) 412 if (EQ (sym, Qsuper)) return MOD_SUPER;
413 return MOD_META; 413 if (EQ (sym, Qhyper)) return MOD_HYPER;
414 else if (EQ (sym, Qsuper)) 414 if (EQ (sym, Qalt)) return MOD_ALT;
415 return MOD_SUPER; 415 if (EQ (sym, Qsymbol)) return MOD_ALT; /* #### - reverse compat */
416 else if (EQ (sym, Qhyper)) 416 if (EQ (sym, Qshift)) return MOD_SHIFT;
417 return MOD_HYPER; 417
418 else if (EQ (sym, Qalt) || EQ (sym, Qsymbol)) /* #### - reverse compat */ 418 return 0;
419 return MOD_ALT;
420 else if (EQ (sym, Qshift))
421 return MOD_SHIFT;
422 else
423 return 0;
424 } 419 }
425 420
426 static Lisp_Object 421 static Lisp_Object
427 control_meta_superify (Lisp_Object frob, unsigned int modifiers) 422 control_meta_superify (Lisp_Object frob, unsigned int modifiers)
428 { 423 {
543 } 538 }
544 539
545 540
546 static void 541 static void
547 keymap_delete_inverse_internal (Lisp_Object inverse_table, 542 keymap_delete_inverse_internal (Lisp_Object inverse_table,
548 Lisp_Object keysym, 543 Lisp_Object keysym,
549 Lisp_Object value) 544 Lisp_Object value)
550 { 545 {
551 Lisp_Object keys = Fgethash (value, inverse_table, Qunbound); 546 Lisp_Object keys = Fgethash (value, inverse_table, Qunbound);
552 Lisp_Object new_keys = keys; 547 Lisp_Object new_keys = keys;
553 Lisp_Object tail; 548 Lisp_Object tail;
590 Lisp_Object prev_value = Fgethash (keysym, keymap->table, Qnil); 585 Lisp_Object prev_value = Fgethash (keysym, keymap->table, Qnil);
591 586
592 if (EQ (prev_value, value)) 587 if (EQ (prev_value, value))
593 return; 588 return;
594 if (!NILP (prev_value)) 589 if (!NILP (prev_value))
595 keymap_delete_inverse_internal (keymap->inverse_table, 590 keymap_delete_inverse_internal (keymap->inverse_table,
596 keysym, prev_value); 591 keysym, prev_value);
597 if (NILP (value)) 592 if (NILP (value))
598 { 593 {
599 keymap->fullness--; 594 keymap->fullness--;
600 if (keymap->fullness < 0) abort (); 595 if (keymap->fullness < 0) abort ();
603 else 598 else
604 { 599 {
605 if (NILP (prev_value)) 600 if (NILP (prev_value))
606 keymap->fullness++; 601 keymap->fullness++;
607 Fputhash (keysym, value, keymap->table); 602 Fputhash (keysym, value, keymap->table);
608 keymap_store_inverse_internal (keymap->inverse_table, 603 keymap_store_inverse_internal (keymap->inverse_table,
609 keysym, value); 604 keysym, value);
610 } 605 }
611 keymap_tick++; 606 keymap_tick++;
612 } 607 }
613 608
681 { 676 {
682 Lisp_Object *result_locative; 677 Lisp_Object *result_locative;
683 }; 678 };
684 679
685 static void 680 static void
686 keymap_submaps_mapper_0 (CONST void *hash_key, void *hash_contents, 681 keymap_submaps_mapper_0 (CONST void *hash_key, void *hash_contents,
687 void *keymap_submaps_closure) 682 void *keymap_submaps_closure)
688 { 683 {
689 /* This function can GC */ 684 /* This function can GC */
690 Lisp_Object contents; 685 Lisp_Object contents;
691 VOID_TO_LISP (contents, hash_contents); 686 VOID_TO_LISP (contents, hash_contents);
692 /* Perform any autoloads, etc */ 687 /* Perform any autoloads, etc */
693 Fkeymapp (contents); 688 Fkeymapp (contents);
694 } 689 }
695 690
696 static void 691 static void
697 keymap_submaps_mapper (CONST void *hash_key, void *hash_contents, 692 keymap_submaps_mapper (CONST void *hash_key, void *hash_contents,
698 void *keymap_submaps_closure) 693 void *keymap_submaps_closure)
699 { 694 {
700 /* This function can GC */ 695 /* This function can GC */
701 Lisp_Object key, contents; 696 Lisp_Object key, contents;
702 Lisp_Object *result_locative; 697 Lisp_Object *result_locative;
703 struct keymap_submaps_closure *cl = keymap_submaps_closure; 698 struct keymap_submaps_closure *cl =
699 (struct keymap_submaps_closure *) keymap_submaps_closure;
704 CVOID_TO_LISP (key, hash_key); 700 CVOID_TO_LISP (key, hash_key);
705 VOID_TO_LISP (contents, hash_contents); 701 VOID_TO_LISP (contents, hash_contents);
706 result_locative = cl->result_locative; 702 result_locative = cl->result_locative;
707 703
708 if (!NILP (Fkeymapp (contents))) 704 if (!NILP (Fkeymapp (contents)))
709 *result_locative = Fcons (Fcons (key, contents), *result_locative); 705 *result_locative = Fcons (Fcons (key, contents), *result_locative);
710 } 706 }
711 707
712 static int map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2, 708 static int map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2,
713 Lisp_Object pred); 709 Lisp_Object pred);
714 710
715 static Lisp_Object 711 static Lisp_Object
716 keymap_submaps (Lisp_Object keymap) 712 keymap_submaps (Lisp_Object keymap)
717 { 713 {
731 &keymap_submaps_closure); 727 &keymap_submaps_closure);
732 result = Qnil; 728 result = Qnil;
733 elisp_maphash (keymap_submaps_mapper, k->table, 729 elisp_maphash (keymap_submaps_mapper, k->table,
734 &keymap_submaps_closure); 730 &keymap_submaps_closure);
735 /* keep it sorted so that the result of accessible-keymaps is ordered */ 731 /* keep it sorted so that the result of accessible-keymaps is ordered */
736 k->sub_maps_cache = list_sort (result, 732 k->sub_maps_cache = list_sort (result,
737 Qnil, 733 Qnil,
738 map_keymap_sort_predicate); 734 map_keymap_sort_predicate);
739 UNGCPRO; 735 UNGCPRO;
740 } 736 }
741 return k->sub_maps_cache; 737 return k->sub_maps_cache;
748 744
749 static Lisp_Object 745 static Lisp_Object
750 make_keymap (int size) 746 make_keymap (int size)
751 { 747 {
752 Lisp_Object result = Qnil; 748 Lisp_Object result = Qnil;
753 struct keymap *keymap = alloc_lcrecord (sizeof (struct keymap), 749 struct keymap *keymap = alloc_lcrecord_type (struct keymap, lrecord_keymap);
754 lrecord_keymap);
755 750
756 XSETKEYMAP (result, keymap); 751 XSETKEYMAP (result, keymap);
757 752
758 keymap->parents = Qnil; 753 keymap->parents = Qnil;
759 keymap->table = Qnil; 754 keymap->table = Qnil;
773 return result; 768 return result;
774 } 769 }
775 770
776 DEFUN ("make-keymap", Fmake_keymap, 0, 1, 0, /* 771 DEFUN ("make-keymap", Fmake_keymap, 0, 1, 0, /*
777 Construct and return a new keymap object. 772 Construct and return a new keymap object.
778 All entries in it are nil, meaning \"command undefined\". 773 All entries in it are nil, meaning "command undefined".
779 774
780 Optional argument NAME specifies a name to assign to the keymap, 775 Optional argument NAME specifies a name to assign to the keymap,
781 as in `set-keymap-name'. This name is only a debugging convenience; 776 as in `set-keymap-name'. This name is only a debugging convenience;
782 it is not used except when printing the keymap. 777 it is not used except when printing the keymap.
783 */ 778 */
789 return keymap; 784 return keymap;
790 } 785 }
791 786
792 DEFUN ("make-sparse-keymap", Fmake_sparse_keymap, 0, 1, 0, /* 787 DEFUN ("make-sparse-keymap", Fmake_sparse_keymap, 0, 1, 0, /*
793 Construct and return a new keymap object. 788 Construct and return a new keymap object.
794 All entries in it are nil, meaning \"command undefined\". The only 789 All entries in it are nil, meaning "command undefined". The only
795 difference between this function and make-keymap is that this function 790 difference between this function and make-keymap is that this function
796 returns a \"smaller\" keymap (one that is expected to contain fewer 791 returns a "smaller" keymap (one that is expected to contain fewer
797 entries). As keymaps dynamically resize, the distinction is not great. 792 entries). As keymaps dynamically resize, the distinction is not great.
798 793
799 Optional argument NAME specifies a name to assign to the keymap, 794 Optional argument NAME specifies a name to assign to the keymap,
800 as in `set-keymap-name'. This name is only a debugging convenience; 795 as in `set-keymap-name'. This name is only a debugging convenience;
801 it is not used except when printing the keymap. 796 it is not used except when printing the keymap.
818 { 813 {
819 keymap = get_keymap (keymap, 1, 1); 814 keymap = get_keymap (keymap, 1, 1);
820 return Fcopy_sequence (XKEYMAP (keymap)->parents); 815 return Fcopy_sequence (XKEYMAP (keymap)->parents);
821 } 816 }
822 817
823 818
824 819
825 static Lisp_Object 820 static Lisp_Object
826 traverse_keymaps_noop (Lisp_Object keymap, void *arg) 821 traverse_keymaps_noop (Lisp_Object keymap, void *arg)
827 { 822 {
828 return Qnil; 823 return Qnil;
829 } 824 }
899 when reading a key-sequence to be looked-up in this keymap. 894 when reading a key-sequence to be looked-up in this keymap.
900 */ 895 */
901 (keymap, new_prompt)) 896 (keymap, new_prompt))
902 { 897 {
903 keymap = get_keymap (keymap, 1, 1); 898 keymap = get_keymap (keymap, 1, 1);
904 899
905 if (!NILP (new_prompt)) 900 if (!NILP (new_prompt))
906 CHECK_STRING (new_prompt); 901 CHECK_STRING (new_prompt);
907 902
908 XKEYMAP (keymap)->prompt = new_prompt; 903 XKEYMAP (keymap)->prompt = new_prompt;
909 return new_prompt; 904 return new_prompt;
943 */ 938 */
944 (keymap, command)) 939 (keymap, command))
945 { 940 {
946 /* This function can GC */ 941 /* This function can GC */
947 keymap = get_keymap (keymap, 1, 1); 942 keymap = get_keymap (keymap, 1, 1);
948 943
949 XKEYMAP (keymap)->default_binding = command; 944 XKEYMAP (keymap)->default_binding = command;
950 return command; 945 return command;
951 } 946 }
952 947
953 DEFUN ("keymap-default-binding", Fkeymap_default_binding, 1, 1, 0, /* 948 DEFUN ("keymap-default-binding", Fkeymap_default_binding, 1, 1, 0, /*
969 The keymap may be autoloaded first if necessary. 964 The keymap may be autoloaded first if necessary.
970 */ 965 */
971 (object)) 966 (object))
972 { 967 {
973 /* This function can GC */ 968 /* This function can GC */
974 Lisp_Object tem = get_keymap (object, 0, 1); 969 return KEYMAPP (get_keymap (object, 0, 0)) ? Qt : Qnil;
975 return KEYMAPP (tem) ? Qt : Qnil;
976 } 970 }
977 971
978 /* Check that OBJECT is a keymap (after dereferencing through any 972 /* Check that OBJECT is a keymap (after dereferencing through any
979 symbols). If it is, return it. 973 symbols). If it is, return it.
980 974
981 If AUTOLOAD is non-zero and OBJECT is a symbol whose function value 975 If AUTOLOAD is non-zero and OBJECT is a symbol whose function value
982 is an autoload form, do the autoload and try again. 976 is an autoload form, do the autoload and try again.
977 If AUTOLOAD is nonzero, callers must assume GC is possible.
983 978
984 ERRORP controls how we respond if OBJECT isn't a keymap. 979 ERRORP controls how we respond if OBJECT isn't a keymap.
985 If ERRORP is non-zero, signal an error; otherwise, just return Qnil. 980 If ERRORP is non-zero, signal an error; otherwise, just return Qnil.
986 */ 981
982 Note that most of the time, we don't want to pursue autoloads.
983 Functions like Faccessible_keymaps which scan entire keymap trees
984 shouldn't load every autoloaded keymap. I'm not sure about this,
985 but it seems to me that only read_key_sequence, Flookup_key, and
986 Fdefine_key should cause keymaps to be autoloaded. */
987
987 Lisp_Object 988 Lisp_Object
988 get_keymap (Lisp_Object object, int errorp, int autoload) 989 get_keymap (Lisp_Object object, int errorp, int autoload)
989 { 990 {
990 /* This function can GC */ 991 /* This function can GC */
991 while (1) 992 while (1)
992 { 993 {
993 Lisp_Object tem = indirect_function (object, 0); 994 Lisp_Object tem = indirect_function (object, 0);
994 995
995 if (KEYMAPP (tem)) 996 if (KEYMAPP (tem))
996 return tem; 997 return tem;
997 /* Should we do an autoload? */ 998 /* Should we do an autoload? */
998 else if (autoload 999 else if (autoload
999 /* (autoload "filename" doc nil keymap) */ 1000 /* (autoload "filename" doc nil keymap) */
1104 { 1105 {
1105 Lisp_Object inverse_table; 1106 Lisp_Object inverse_table;
1106 }; 1107 };
1107 1108
1108 static void 1109 static void
1109 copy_keymap_inverse_mapper (CONST void *hash_key, void *hash_contents, 1110 copy_keymap_inverse_mapper (CONST void *hash_key, void *hash_contents,
1110 void *copy_keymap_inverse_closure) 1111 void *copy_keymap_inverse_closure)
1111 { 1112 {
1112 Lisp_Object key, inverse_table, inverse_contents; 1113 Lisp_Object key, inverse_table, inverse_contents;
1113 struct copy_keymap_inverse_closure *closure = copy_keymap_inverse_closure; 1114 struct copy_keymap_inverse_closure *closure =
1115 (struct copy_keymap_inverse_closure *) copy_keymap_inverse_closure;
1114 1116
1115 VOID_TO_LISP (inverse_table, closure); 1117 VOID_TO_LISP (inverse_table, closure);
1116 VOID_TO_LISP (inverse_contents, hash_contents); 1118 VOID_TO_LISP (inverse_contents, hash_contents);
1117 CVOID_TO_LISP (key, hash_key); 1119 CVOID_TO_LISP (key, hash_key);
1118 /* copy-sequence deals with dotted lists. */ 1120 /* copy-sequence deals with dotted lists. */
1150 { 1152 {
1151 struct keymap *self; 1153 struct keymap *self;
1152 }; 1154 };
1153 1155
1154 static void 1156 static void
1155 copy_keymap_mapper (CONST void *hash_key, void *hash_contents, 1157 copy_keymap_mapper (CONST void *hash_key, void *hash_contents,
1156 void *copy_keymap_closure) 1158 void *copy_keymap_closure)
1157 { 1159 {
1158 /* This function can GC */ 1160 /* This function can GC */
1159 Lisp_Object key, contents; 1161 Lisp_Object key, contents;
1160 struct copy_keymap_closure *closure = copy_keymap_closure; 1162 struct copy_keymap_closure *closure =
1163 (struct copy_keymap_closure *) copy_keymap_closure;
1161 1164
1162 CVOID_TO_LISP (key, hash_key); 1165 CVOID_TO_LISP (key, hash_key);
1163 VOID_TO_LISP (contents, hash_contents); 1166 VOID_TO_LISP (contents, hash_contents);
1164 /* When we encounter a keymap which is indirected through a 1167 /* When we encounter a keymap which is indirected through a
1165 symbol, we need to copy the sub-map. In v18, the form 1168 symbol, we need to copy the sub-map. In v18, the form
1305 /* Ok, this is a bit more dubious - prevent people from doing things 1308 /* Ok, this is a bit more dubious - prevent people from doing things
1306 like (global-set-key 'RET 'something) because that will have the 1309 like (global-set-key 'RET 'something) because that will have the
1307 same problem as above. (Gag!) Maybe we should just silently 1310 same problem as above. (Gag!) Maybe we should just silently
1308 accept these as aliases for the "real" names? 1311 accept these as aliases for the "real" names?
1309 */ 1312 */
1310 (string_length (XSYMBOL (*keysym)->name) < 4 && 1313 (string_length (XSYMBOL (*keysym)->name) <= 3 &&
1311 (!strcmp (name, "LFD") || 1314 (!strcmp (name, "LFD") ||
1312 !strcmp (name, "TAB") || 1315 !strcmp (name, "TAB") ||
1313 !strcmp (name, "RET") || 1316 !strcmp (name, "RET") ||
1314 !strcmp (name, "ESC") || 1317 !strcmp (name, "ESC") ||
1315 !strcmp (name, "DEL") || 1318 !strcmp (name, "DEL") ||
1379 { 1382 {
1380 struct Lisp_Event event; 1383 struct Lisp_Event event;
1381 event.event_type = empty_event; 1384 event.event_type = empty_event;
1382 character_to_event (XCHAR_OR_CHAR_INT (spec), &event, 1385 character_to_event (XCHAR_OR_CHAR_INT (spec), &event,
1383 XCONSOLE (Vselected_console), 0); 1386 XCONSOLE (Vselected_console), 0);
1384 returned_value->keysym = event.event.key.keysym; 1387 returned_value->keysym = event.event.key.keysym;
1385 returned_value->modifiers = event.event.key.modifiers; 1388 returned_value->modifiers = event.event.key.modifiers;
1386 } 1389 }
1387 else if (EVENTP (spec)) 1390 else if (EVENTP (spec))
1388 { 1391 {
1389 switch (XEVENT (spec)->event_type) 1392 switch (XEVENT (spec)->event_type)
1390 { 1393 {
1391 case key_press_event: 1394 case key_press_event:
1392 { 1395 {
1393 returned_value->keysym = XEVENT (spec)->event.key.keysym; 1396 returned_value->keysym = XEVENT (spec)->event.key.keysym;
1394 returned_value->modifiers = XEVENT (spec)->event.key.modifiers; 1397 returned_value->modifiers = XEVENT (spec)->event.key.modifiers;
1395 break; 1398 break;
1396 } 1399 }
1397 case button_press_event: 1400 case button_press_event:
1398 case button_release_event: 1401 case button_release_event:
1413 case 6: 1416 case 6:
1414 returned_value->keysym = (down ? Qbutton6 : Qbutton6up); break; 1417 returned_value->keysym = (down ? Qbutton6 : Qbutton6up); break;
1415 case 7: 1418 case 7:
1416 returned_value->keysym = (down ? Qbutton7 : Qbutton7up); break; 1419 returned_value->keysym = (down ? Qbutton7 : Qbutton7up); break;
1417 default: 1420 default:
1418 returned_value->keysym =(down ? Qbutton0 : Qbutton0up); break; 1421 returned_value->keysym = (down ? Qbutton0 : Qbutton0up); break;
1419 } 1422 }
1420 returned_value->modifiers = XEVENT (spec)->event.button.modifiers; 1423 returned_value->modifiers = XEVENT (spec)->event.button.modifiers;
1421 break; 1424 break;
1422 } 1425 }
1423 default: 1426 default:
1599 return (event_matches_key_specifier_p (XEVENT (event), key_specifier) 1602 return (event_matches_key_specifier_p (XEVENT (event), key_specifier)
1600 ? Qt : Qnil); 1603 ? Qt : Qnil);
1601 } 1604 }
1602 1605
1603 /* ASCII grunge. 1606 /* ASCII grunge.
1604 Given a keysym, return another keysym/modifier pair which could be 1607 Given a keysym, return another keysym/modifier pair which could be
1605 considered the same key in an ASCII world. Backspace returns ^H, for 1608 considered the same key in an ASCII world. Backspace returns ^H, for
1606 example. 1609 example.
1607 */ 1610 */
1608 static void 1611 static void
1609 define_key_alternate_name (struct key_data *key, 1612 define_key_alternate_name (struct key_data *key,
1610 struct key_data *returned_value) 1613 struct key_data *returned_value)
1760 A key sequence is a vector of keystrokes. As a degenerate case, elements 1763 A key sequence is a vector of keystrokes. As a degenerate case, elements
1761 of this vector may also be keysyms if they have no modifiers. That is, 1764 of this vector may also be keysyms if they have no modifiers. That is,
1762 the `A' keystroke is represented by all of these forms: 1765 the `A' keystroke is represented by all of these forms:
1763 A ?A 65 (A) (?A) (65) 1766 A ?A 65 (A) (?A) (65)
1764 [A] [?A] [65] [(A)] [(?A)] [(65)] 1767 [A] [?A] [65] [(A)] [(?A)] [(65)]
1765 1768
1766 the `control-a' keystroke is represented by these forms: 1769 the `control-a' keystroke is represented by these forms:
1767 (control A) (control ?A) (control 65) 1770 (control A) (control ?A) (control 65)
1768 [(control A)] [(control ?A)] [(control 65)] 1771 [(control A)] [(control ?A)] [(control 65)]
1769 the key sequence `control-c control-a' is represented by these forms: 1772 the key sequence `control-c control-a' is represented by these forms:
1770 [(control c) (control a)] [(control ?c) (control ?a)] 1773 [(control c) (control a)] [(control ?c) (control ?a)]
1780 though that is probably not what you want, so be careful. 1783 though that is probably not what you want, so be careful.
1781 1784
1782 For backward compatibility, a key sequence may also be represented by a 1785 For backward compatibility, a key sequence may also be represented by a
1783 string. In this case, it represents the key sequence(s) that would 1786 string. In this case, it represents the key sequence(s) that would
1784 produce that sequence of ASCII characters in a purely ASCII world. For 1787 produce that sequence of ASCII characters in a purely ASCII world. For
1785 example, a string containing the ASCII backspace character, \"\\^H\", would 1788 example, a string containing the ASCII backspace character, "\\^H", would
1786 represent two key sequences: `(control h)' and `backspace'. Binding a 1789 represent two key sequences: `(control h)' and `backspace'. Binding a
1787 command to this will actually bind both of those key sequences. Likewise 1790 command to this will actually bind both of those key sequences. Likewise
1788 for the following pairs: 1791 for the following pairs:
1789 1792
1790 control h backspace 1793 control h backspace
1794 control [ escape 1797 control [ escape
1795 control @ control space 1798 control @ control space
1796 1799
1797 After binding a command to two key sequences with a form like 1800 After binding a command to two key sequences with a form like
1798 1801
1799 (define-key global-map \"\\^X\\^I\" \'command-1) 1802 (define-key global-map "\\^X\\^I" \'command-1)
1800 1803
1801 it is possible to redefine only one of those sequences like so: 1804 it is possible to redefine only one of those sequences like so:
1802 1805
1803 (define-key global-map [(control x) (control i)] \'command-2) 1806 (define-key global-map [(control x) (control i)] \'command-2)
1804 (define-key global-map [(control x) tab] \'command-3) 1807 (define-key global-map [(control x) tab] \'command-3)
1910 else 1913 else
1911 { 1914 {
1912 raw_key2.keysym = Qnil; 1915 raw_key2.keysym = Qnil;
1913 raw_key2.modifiers = 0; 1916 raw_key2.modifiers = 0;
1914 } 1917 }
1915 1918
1916 if (metized) 1919 if (metized)
1917 { 1920 {
1918 raw_key1.modifiers |= MOD_META; 1921 raw_key1.modifiers |= MOD_META;
1919 raw_key2.modifiers |= MOD_META; 1922 raw_key2.modifiers |= MOD_META;
1920 metized = 0; 1923 metized = 0;
1931 if (ascii_hack && !NILP (raw_key2.keysym)) 1934 if (ascii_hack && !NILP (raw_key2.keysym))
1932 keymap_store (keymap, &raw_key2, def); 1935 keymap_store (keymap, &raw_key2, def);
1933 UNGCPRO; 1936 UNGCPRO;
1934 return def; 1937 return def;
1935 } 1938 }
1936 1939
1937 { 1940 {
1938 Lisp_Object cmd; 1941 Lisp_Object cmd;
1939 struct gcpro ngcpro1; 1942 struct gcpro ngcpro1;
1940 NGCPRO1 (c); 1943 NGCPRO1 (c);
1941 1944
1964 1967
1965 /************************************************************************/ 1968 /************************************************************************/
1966 /* Looking up keys in keymaps */ 1969 /* Looking up keys in keymaps */
1967 /************************************************************************/ 1970 /************************************************************************/
1968 1971
1969 /* We need a very fast (i.e., non-consing) version of lookup-key in order 1972 /* We need a very fast (i.e., non-consing) version of lookup-key in order
1970 to make where-is-internal really fly. */ 1973 to make where-is-internal really fly. */
1971 1974
1972 struct raw_lookup_key_mapper_closure 1975 struct raw_lookup_key_mapper_closure
1973 { 1976 {
1974 int remaining; 1977 int remaining;
1999 2002
2000 static Lisp_Object 2003 static Lisp_Object
2001 raw_lookup_key_mapper (Lisp_Object k, void *arg) 2004 raw_lookup_key_mapper (Lisp_Object k, void *arg)
2002 { 2005 {
2003 /* This function can GC */ 2006 /* This function can GC */
2004 struct raw_lookup_key_mapper_closure *c = arg; 2007 struct raw_lookup_key_mapper_closure *c =
2008 (struct raw_lookup_key_mapper_closure *) arg;
2005 int accept_default = c->accept_default; 2009 int accept_default = c->accept_default;
2006 int remaining = c->remaining; 2010 int remaining = c->remaining;
2007 int keys_so_far = c->keys_so_far; 2011 int keys_so_far = c->keys_so_far;
2008 CONST struct key_data *raw_keys = c->raw_keys; 2012 CONST struct key_data *raw_keys = c->raw_keys;
2009 Lisp_Object cmd; 2013 Lisp_Object cmd;
2010 2014
2011 if (! meta_prefix_char_p (&(raw_keys[0]))) 2015 if (! meta_prefix_char_p (&(raw_keys[0])))
2012 { 2016 {
2013 /* Normal case: every case except the meta-hack (see below). */ 2017 /* Normal case: every case except the meta-hack (see below). */
2014 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default); 2018 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default);
2015 2019
2016 if (remaining == 0) 2020 if (remaining == 0)
2017 /* Return whatever we found if we're out of keys */ 2021 /* Return whatever we found if we're out of keys */
2018 ; 2022 ;
2019 else if (NILP (cmd)) 2023 else if (NILP (cmd))
2020 /* Found nothing (though perhaps parent map may have binding) */ 2024 /* Found nothing (though perhaps parent map may have binding) */
2023 /* Didn't find a keymap, and we have more keys. 2027 /* Didn't find a keymap, and we have more keys.
2024 * Return a fixnum to indicate that keys were too long. 2028 * Return a fixnum to indicate that keys were too long.
2025 */ 2029 */
2026 cmd = make_int (keys_so_far + 1); 2030 cmd = make_int (keys_so_far + 1);
2027 else 2031 else
2028 cmd = raw_lookup_key (cmd, raw_keys + 1, remaining, 2032 cmd = raw_lookup_key (cmd, raw_keys + 1, remaining,
2029 keys_so_far + 1, accept_default); 2033 keys_so_far + 1, accept_default);
2030 } 2034 }
2031 else 2035 else
2032 { 2036 {
2033 /* This is a hack so that looking up a key-sequence whose last 2037 /* This is a hack so that looking up a key-sequence whose last
2041 { 2045 {
2042 /* First look for the prefix-char directly */ 2046 /* First look for the prefix-char directly */
2043 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default); 2047 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default);
2044 if (NILP (cmd)) 2048 if (NILP (cmd))
2045 { 2049 {
2046 /* Do kludgy return of the meta-map */ 2050 /* Do kludgy return of the meta-map */
2047 cmd = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META), 2051 cmd = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META),
2048 XKEYMAP (k)->table, Qnil); 2052 XKEYMAP (k)->table, Qnil);
2049 } 2053 }
2050 } 2054 }
2051 else 2055 else
2052 { 2056 {
2053 /* Search for the prefix-char-prefixed sequence directly */ 2057 /* Search for the prefix-char-prefixed sequence directly */
2054 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default); 2058 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default);
2055 cmd = get_keymap (cmd, 0, 1); 2059 cmd = get_keymap (cmd, 0, 1);
2056 if (!NILP (cmd)) 2060 if (!NILP (cmd))
2057 cmd = raw_lookup_key (cmd, raw_keys + 1, remaining, 2061 cmd = raw_lookup_key (cmd, raw_keys + 1, remaining,
2058 keys_so_far + 1, accept_default); 2062 keys_so_far + 1, accept_default);
2059 else if ((raw_keys[1].modifiers & MOD_META) == 0) 2063 else if ((raw_keys[1].modifiers & MOD_META) == 0)
2060 { 2064 {
2061 struct key_data metified; 2065 struct key_data metified;
2062 metified.keysym = raw_keys[1].keysym; 2066 metified.keysym = raw_keys[1].keysym;
2097 return Qnil; 2101 return Qnil;
2098 2102
2099 if (nkeys < (countof (kkk))) 2103 if (nkeys < (countof (kkk)))
2100 raw_keys = kkk; 2104 raw_keys = kkk;
2101 else 2105 else
2102 raw_keys = (struct key_data *) alloca (sizeof (struct key_data) * nkeys); 2106 raw_keys = alloca_array (struct key_data, nkeys);
2103 2107
2104 for (i = 0; i < nkeys; i++) 2108 for (i = 0; i < nkeys; i++)
2105 { 2109 {
2106 define_key_parser (keys[i], &(raw_keys[i])); 2110 define_key_parser (keys[i], &(raw_keys[i]));
2107 } 2111 }
2127 nkeys = event_chain_count (event_head); 2131 nkeys = event_chain_count (event_head);
2128 2132
2129 if (nkeys < (countof (kkk))) 2133 if (nkeys < (countof (kkk)))
2130 raw_keys = kkk; 2134 raw_keys = kkk;
2131 else 2135 else
2132 raw_keys = (struct key_data *) alloca (sizeof (struct key_data) * nkeys); 2136 raw_keys = alloca_array (struct key_data, nkeys);
2133 2137
2134 nkeys = 0; 2138 nkeys = 0;
2135 EVENT_CHAIN_LOOP (event, event_head) 2139 EVENT_CHAIN_LOOP (event, event_head)
2136 define_key_parser (event, &(raw_keys[nkeys++])); 2140 define_key_parser (event, &(raw_keys[nkeys++]));
2137 GCPRO2 (keymaps[0], event_head); 2141 GCPRO2 (keymaps[0], event_head);
2157 2161
2158 DEFUN ("lookup-key", Flookup_key, 2, 3, 0, /* 2162 DEFUN ("lookup-key", Flookup_key, 2, 3, 0, /*
2159 In keymap KEYMAP, look up key-sequence KEYS. Return the definition. 2163 In keymap KEYMAP, look up key-sequence KEYS. Return the definition.
2160 Nil is returned if KEYS is unbound. See documentation of `define-key' 2164 Nil is returned if KEYS is unbound. See documentation of `define-key'
2161 for valid key definitions and key-sequence specifications. 2165 for valid key definitions and key-sequence specifications.
2162 A number is returned if KEYS is \"too long\"; that is, the leading 2166 A number is returned if KEYS is "too long"; that is, the leading
2163 characters fail to be a valid sequence of prefix characters in KEYMAP. 2167 characters fail to be a valid sequence of prefix characters in KEYMAP.
2164 The number is how many characters at the front of KEYS 2168 The number is how many characters at the front of KEYS
2165 it takes to reach a non-prefix command. 2169 it takes to reach a non-prefix command.
2166 */ 2170 */
2167 (keymap, keys, accept_default)) 2171 (keymap, keys, accept_default))
2186 } 2190 }
2187 else /* STRINGP (keys) */ 2191 else /* STRINGP (keys) */
2188 { 2192 {
2189 int length = string_char_length (XSTRING (keys)); 2193 int length = string_char_length (XSTRING (keys));
2190 int i; 2194 int i;
2191 struct key_data *raw_keys 2195 struct key_data *raw_keys = alloca_array (struct key_data, length);
2192 = (struct key_data *) alloca (sizeof (struct key_data) * length);
2193 if (length == 0) 2196 if (length == 0)
2194 return Qnil; 2197 return Qnil;
2195 2198
2196 for (i = 0; i < length; i++) 2199 for (i = 0; i < length; i++)
2197 { 2200 {
2210 2213
2211 It would be kind of nice if this were in Lisp so that this semi-hairy 2214 It would be kind of nice if this were in Lisp so that this semi-hairy
2212 semi-heuristic command-lookup behaviour could be readily understood and 2215 semi-heuristic command-lookup behaviour could be readily understood and
2213 customised. However, this needs to be pretty fast, or performance of 2216 customised. However, this needs to be pretty fast, or performance of
2214 keyboard macros goes to shit; putting this in lisp slows macros down 2217 keyboard macros goes to shit; putting this in lisp slows macros down
2215 2-3x. And they're already slower than v18 by 5-6x. 2218 2-3x. And they're already slower than v18 by 5-6x.
2216 */ 2219 */
2217 2220
2218 struct relevant_maps 2221 struct relevant_maps
2219 { 2222 {
2220 int nmaps; 2223 int nmaps;
2230 static void get_relevant_minor_maps (Lisp_Object buffer, 2233 static void get_relevant_minor_maps (Lisp_Object buffer,
2231 struct relevant_maps *closure); 2234 struct relevant_maps *closure);
2232 2235
2233 static void 2236 static void
2234 relevant_map_push (Lisp_Object map, struct relevant_maps *closure) 2237 relevant_map_push (Lisp_Object map, struct relevant_maps *closure)
2235 { 2238 {
2236 unsigned int nmaps = closure->nmaps; 2239 unsigned int nmaps = closure->nmaps;
2237 2240
2238 if (!KEYMAPP (map)) 2241 if (!KEYMAPP (map))
2239 return; 2242 return;
2240 closure->nmaps = nmaps + 1; 2243 closure->nmaps = nmaps + 1;
2276 CHECK_LIVE_EVENT (terminal); 2279 CHECK_LIVE_EVENT (terminal);
2277 con = event_console_or_selected (terminal); 2280 con = event_console_or_selected (terminal);
2278 } 2281 }
2279 else 2282 else
2280 con = XCONSOLE (Vselected_console); 2283 con = XCONSOLE (Vselected_console);
2281 2284
2282 if (KEYMAPP (con->overriding_terminal_local_map) 2285 if (KEYMAPP (con->overriding_terminal_local_map)
2283 || KEYMAPP (Voverriding_local_map)) 2286 || KEYMAPP (Voverriding_local_map))
2284 { 2287 {
2285 if (KEYMAPP (con->overriding_terminal_local_map)) 2288 if (KEYMAPP (con->overriding_terminal_local_map))
2286 relevant_map_push (con->overriding_terminal_local_map, &closure); 2289 relevant_map_push (con->overriding_terminal_local_map, &closure);
2287 if (KEYMAPP (Voverriding_local_map)) 2290 if (KEYMAPP (Voverriding_local_map))
2288 relevant_map_push (Voverriding_local_map, &closure); 2291 relevant_map_push (Voverriding_local_map, &closure);
2289 } 2292 }
2290 else if (!EVENTP (terminal) 2293 else if (!EVENTP (terminal)
2291 || (XEVENT (terminal)->event_type != button_press_event 2294 || (XEVENT (terminal)->event_type != button_press_event
2292 && XEVENT (terminal)->event_type != button_release_event)) 2295 && XEVENT (terminal)->event_type != button_release_event))
2293 { 2296 {
2294 Lisp_Object tem; 2297 Lisp_Object tem;
2295 XSETBUFFER (tem, current_buffer); 2298 XSETBUFFER (tem, current_buffer);
2296 /* It's not a mouse event; order of keymaps searched is: 2299 /* It's not a mouse event; order of keymaps searched is:
2418 { 2421 {
2419 Lisp_Object keymap = Fextent_property (glyph, Qkeymap, Qnil); 2422 Lisp_Object keymap = Fextent_property (glyph, Qkeymap, Qnil);
2420 if (!NILP (keymap)) 2423 if (!NILP (keymap))
2421 relevant_map_push (get_keymap (keymap, 1, 1), closure); 2424 relevant_map_push (get_keymap (keymap, 1, 1), closure);
2422 } 2425 }
2423 2426
2424 /* Next check the extents at the text position, if any */ 2427 /* Next check the extents at the text position, if any */
2425 if (!NILP (pos)) 2428 if (!NILP (pos))
2426 { 2429 {
2427 Lisp_Object extent; 2430 Lisp_Object extent;
2428 for (extent = Fextent_at (pos, buffer_or_string, Qkeymap, Qnil, Qat); 2431 for (extent = Fextent_at (pos, buffer_or_string, Qkeymap, Qnil, Qat);
2499 GCPRO1 (event_or_keys); 2502 GCPRO1 (event_or_keys);
2500 nmaps = get_relevant_keymaps (event_or_keys, countof (maps), 2503 nmaps = get_relevant_keymaps (event_or_keys, countof (maps),
2501 gubbish); 2504 gubbish);
2502 if (nmaps > countof (maps)) 2505 if (nmaps > countof (maps))
2503 { 2506 {
2504 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); 2507 gubbish = alloca_array (Lisp_Object, nmaps);
2505 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish); 2508 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish);
2506 } 2509 }
2507 UNGCPRO; 2510 UNGCPRO;
2508 return Flist (nmaps, gubbish); 2511 return Flist (nmaps, gubbish);
2509 } 2512 }
2622 2625
2623 Lisp_Object 2626 Lisp_Object
2624 event_binding_in (Lisp_Object event0, Lisp_Object keymap, int accept_default) 2627 event_binding_in (Lisp_Object event0, Lisp_Object keymap, int accept_default)
2625 { 2628 {
2626 /* This function can GC */ 2629 /* This function can GC */
2627 Lisp_Object maps[1];
2628
2629 if (!KEYMAPP (keymap)) 2630 if (!KEYMAPP (keymap))
2630 return Qnil; 2631 return Qnil;
2631 2632
2632 maps[0] = keymap; 2633 return process_event_binding_result (lookup_events (event0, 1, &keymap,
2633 return process_event_binding_result (lookup_events (event0, 1, maps,
2634 accept_default)); 2634 accept_default));
2635 } 2635 }
2636 2636
2637 /* Attempts to find a function key mapping corresponding to the 2637 /* Attempts to find a function key mapping corresponding to the
2638 event-sequence whose head is event0 (sequence is threaded through 2638 event-sequence whose head is event0 (sequence is threaded through
2639 event_next). The return value will be the same as for event_binding(). */ 2639 event_next). The return value will be the same as for event_binding(). */
2640 Lisp_Object 2640 Lisp_Object
2641 munging_key_map_event_binding (Lisp_Object event0, 2641 munging_key_map_event_binding (Lisp_Object event0,
2642 enum munge_me_out_the_door munge) 2642 enum munge_me_out_the_door munge)
2643 { 2643 {
2644 Lisp_Object the_map; 2644 Lisp_Object keymap = (munge == MUNGE_ME_FUNCTION_KEY) ?
2645 Lisp_Object maps[1]; 2645 CONSOLE_FUNCTION_KEY_MAP (event_console_or_selected (event0)) :
2646 2646 Vkey_translation_map;
2647 if (munge == MUNGE_ME_FUNCTION_KEY) 2647
2648 { 2648 if (NILP (keymap))
2649 struct console *c = event_console_or_selected (event0);
2650
2651 the_map = CONSOLE_FUNCTION_KEY_MAP (c);
2652 }
2653 else
2654 the_map = Vkey_translation_map;
2655
2656 if (NILP (the_map))
2657 return Qnil; 2649 return Qnil;
2658 2650
2659 maps[0] = the_map; 2651 return process_event_binding_result (lookup_events (event0, 1, &keymap, 1));
2660 return process_event_binding_result (lookup_events (event0, 1, maps, 1));
2661 } 2652 }
2662 2653
2663 2654
2664 /************************************************************************/ 2655 /************************************************************************/
2665 /* Setting/querying the global and local maps */ 2656 /* Setting/querying the global and local maps */
2715 /************************************************************************/ 2706 /************************************************************************/
2716 /* Mapping over keymap elements */ 2707 /* Mapping over keymap elements */
2717 /************************************************************************/ 2708 /************************************************************************/
2718 2709
2719 /* Since keymaps are arranged in a hierarchy, one keymap per bucky bit or 2710 /* Since keymaps are arranged in a hierarchy, one keymap per bucky bit or
2720 prefix key, it's not entirely objvious what map-keymap should do, but 2711 prefix key, it's not entirely obvious what map-keymap should do, but
2721 what it does is: map over all keys in this map; then recursively map 2712 what it does is: map over all keys in this map; then recursively map
2722 over all submaps of this map that are "bucky" submaps. This means that, 2713 over all submaps of this map that are "bucky" submaps. This means that,
2723 when mapping over a keymap, it appears that "x" and "C-x" are in the 2714 when mapping over a keymap, it appears that "x" and "C-x" are in the
2724 same map, although "C-x" is really in the "control" submap of this one. 2715 same map, although "C-x" is really in the "control" submap of this one.
2725 However, since we don't recursively descend the submaps that are bound 2716 However, since we don't recursively descend the submaps that are bound
2739 unsigned int modifiers; 2730 unsigned int modifiers;
2740 }; 2731 };
2741 2732
2742 /* used by map_keymap() */ 2733 /* used by map_keymap() */
2743 static void 2734 static void
2744 map_keymap_unsorted_mapper (CONST void *hash_key, void *hash_contents, 2735 map_keymap_unsorted_mapper (CONST void *hash_key, void *hash_contents,
2745 void *map_keymap_unsorted_closure) 2736 void *map_keymap_unsorted_closure)
2746 { 2737 {
2747 /* This function can GC */ 2738 /* This function can GC */
2748 Lisp_Object keysym; 2739 Lisp_Object keysym;
2749 Lisp_Object contents; 2740 Lisp_Object contents;
2750 struct map_keymap_unsorted_closure *closure = map_keymap_unsorted_closure; 2741 struct map_keymap_unsorted_closure *closure =
2742 (struct map_keymap_unsorted_closure *) map_keymap_unsorted_closure;
2751 unsigned int modifiers = closure->modifiers; 2743 unsigned int modifiers = closure->modifiers;
2752 unsigned int mod_bit; 2744 unsigned int mod_bit;
2753 CVOID_TO_LISP (keysym, hash_key); 2745 CVOID_TO_LISP (keysym, hash_key);
2754 VOID_TO_LISP (contents, hash_contents); 2746 VOID_TO_LISP (contents, hash_contents);
2755 mod_bit = MODIFIER_HASH_KEY_BITS (keysym); 2747 mod_bit = MODIFIER_HASH_KEY_BITS (keysym);
2756 if (mod_bit != 0) 2748 if (mod_bit != 0)
2757 { 2749 {
2758 int omod = modifiers; 2750 int omod = modifiers;
2759 closure->modifiers = (modifiers | mod_bit); 2751 closure->modifiers = (modifiers | mod_bit);
2760 contents = get_keymap (contents, 1, 1); 2752 contents = get_keymap (contents, 1, 0);
2761 elisp_maphash (map_keymap_unsorted_mapper, 2753 elisp_maphash (map_keymap_unsorted_mapper,
2762 XKEYMAP (contents)->table, 2754 XKEYMAP (contents)->table,
2763 map_keymap_unsorted_closure); 2755 map_keymap_unsorted_closure);
2764 closure->modifiers = omod; 2756 closure->modifiers = omod;
2765 } 2757 }
2778 Lisp_Object *result_locative; 2770 Lisp_Object *result_locative;
2779 }; 2771 };
2780 2772
2781 /* used by map_keymap_sorted() */ 2773 /* used by map_keymap_sorted() */
2782 static void 2774 static void
2783 map_keymap_sorted_mapper (CONST void *hash_key, void *hash_contents, 2775 map_keymap_sorted_mapper (CONST void *hash_key, void *hash_contents,
2784 void *map_keymap_sorted_closure) 2776 void *map_keymap_sorted_closure)
2785 { 2777 {
2786 struct map_keymap_sorted_closure *cl = map_keymap_sorted_closure; 2778 struct map_keymap_sorted_closure *cl =
2779 (struct map_keymap_sorted_closure *) map_keymap_sorted_closure;
2787 Lisp_Object key, contents; 2780 Lisp_Object key, contents;
2788 Lisp_Object *list = cl->result_locative; 2781 Lisp_Object *list = cl->result_locative;
2789 CVOID_TO_LISP (key, hash_key); 2782 CVOID_TO_LISP (key, hash_key);
2790 VOID_TO_LISP (contents, hash_contents); 2783 VOID_TO_LISP (contents, hash_contents);
2791 *list = Fcons (Fcons (key, contents), *list); 2784 *list = Fcons (Fcons (key, contents), *list);
2794 2787
2795 /* used by map_keymap_sorted(), describe_map_sort_predicate(), 2788 /* used by map_keymap_sorted(), describe_map_sort_predicate(),
2796 and keymap_submaps(). 2789 and keymap_submaps().
2797 */ 2790 */
2798 static int 2791 static int
2799 map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2, 2792 map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2,
2800 Lisp_Object pred) 2793 Lisp_Object pred)
2801 { 2794 {
2802 /* obj1 and obj2 are conses with keysyms in their cars. Cdrs are ignored. 2795 /* obj1 and obj2 are conses with keysyms in their cars. Cdrs are ignored.
2803 */ 2796 */
2804 unsigned int bit1, bit2; 2797 unsigned int bit1, bit2;
2809 2802
2810 if (EQ (obj1, obj2)) 2803 if (EQ (obj1, obj2))
2811 return -1; 2804 return -1;
2812 bit1 = MODIFIER_HASH_KEY_BITS (obj1); 2805 bit1 = MODIFIER_HASH_KEY_BITS (obj1);
2813 bit2 = MODIFIER_HASH_KEY_BITS (obj2); 2806 bit2 = MODIFIER_HASH_KEY_BITS (obj2);
2814 2807
2815 /* If either is a symbol with a character-set-property, then sort it by 2808 /* If either is a symbol with a character-set-property, then sort it by
2816 that code instead of alphabetically. 2809 that code instead of alphabetically.
2817 */ 2810 */
2818 if (! bit1 && SYMBOLP (obj1)) 2811 if (! bit1 && SYMBOLP (obj1))
2819 { 2812 {
2852 } 2845 }
2853 2846
2854 /* else they're both symbols. If they're both buckys, then order them. */ 2847 /* else they're both symbols. If they're both buckys, then order them. */
2855 if (bit1 && bit2) 2848 if (bit1 && bit2)
2856 return bit1 < bit2 ? 1 : -1; 2849 return bit1 < bit2 ? 1 : -1;
2857 2850
2858 /* if only one is a bucky, then it comes later */ 2851 /* if only one is a bucky, then it comes later */
2859 if (bit1 || bit2) 2852 if (bit1 || bit2)
2860 return bit2 ? 1 : -1; 2853 return bit2 ? 1 : -1;
2861 2854
2862 /* otherwise, string-sort them. */ 2855 /* otherwise, string-sort them. */
2873 2866
2874 2867
2875 /* used by map_keymap() */ 2868 /* used by map_keymap() */
2876 static void 2869 static void
2877 map_keymap_sorted (Lisp_Object keymap_table, 2870 map_keymap_sorted (Lisp_Object keymap_table,
2878 unsigned int modifiers, 2871 unsigned int modifiers,
2879 void (*function) (CONST struct key_data *key, 2872 void (*function) (CONST struct key_data *key,
2880 Lisp_Object binding, 2873 Lisp_Object binding,
2881 void *map_keymap_sorted_closure), 2874 void *map_keymap_sorted_closure),
2882 void *map_keymap_sorted_closure) 2875 void *map_keymap_sorted_closure)
2883 { 2876 {
2884 /* This function can GC */ 2877 /* This function can GC */
2885 struct gcpro gcpro1; 2878 struct gcpro gcpro1;
2920 2913
2921 2914
2922 /* used by Fmap_keymap() */ 2915 /* used by Fmap_keymap() */
2923 static void 2916 static void
2924 map_keymap_mapper (CONST struct key_data *key, 2917 map_keymap_mapper (CONST struct key_data *key,
2925 Lisp_Object binding, 2918 Lisp_Object binding,
2926 void *function) 2919 void *function)
2927 { 2920 {
2928 /* This function can GC */ 2921 /* This function can GC */
2929 Lisp_Object fn; 2922 Lisp_Object fn;
2930 VOID_TO_LISP (fn, function); 2923 VOID_TO_LISP (fn, function);
2962 the keymap will ever be passed to the function more than once. 2955 the keymap will ever be passed to the function more than once.
2963 2956
2964 The function will not be called on elements of this keymap's parents 2957 The function will not be called on elements of this keymap's parents
2965 (see the function `keymap-parents') or upon keymaps which are contained 2958 (see the function `keymap-parents') or upon keymaps which are contained
2966 within this keymap (multi-character definitions). 2959 within this keymap (multi-character definitions).
2967 It will be called on \"meta\" characters since they are not really 2960 It will be called on "meta" characters since they are not really
2968 two-character sequences. 2961 two-character sequences.
2969 2962
2970 If the optional third argument SORT-FIRST is non-nil, then the elements of 2963 If the optional third argument SORT-FIRST is non-nil, then the elements of
2971 the keymap will be passed to the mapper function in a canonical order. 2964 the keymap will be passed to the mapper function in a canonical order.
2972 Otherwise, they will be passed in hash (that is, random) order, which is 2965 Otherwise, they will be passed in hash (that is, random) order, which is
3056 3049
3057 static Lisp_Object 3050 static Lisp_Object
3058 accessible_keymaps_keymap_mapper (Lisp_Object thismap, void *arg) 3051 accessible_keymaps_keymap_mapper (Lisp_Object thismap, void *arg)
3059 { 3052 {
3060 /* This function can GC */ 3053 /* This function can GC */
3061 struct accessible_keymaps_closure *closure = arg; 3054 struct accessible_keymaps_closure *closure =
3055 (struct accessible_keymaps_closure *) arg;
3062 Lisp_Object submaps = keymap_submaps (thismap); 3056 Lisp_Object submaps = keymap_submaps (thismap);
3063 3057
3064 for (; !NILP (submaps); submaps = XCDR (submaps)) 3058 for (; !NILP (submaps); submaps = XCDR (submaps))
3065 { 3059 {
3066 accessible_keymaps_mapper_1 (XCAR (XCAR (submaps)), 3060 accessible_keymaps_mapper_1 (XCAR (XCAR (submaps)),
3071 return Qnil; 3065 return Qnil;
3072 } 3066 }
3073 3067
3074 3068
3075 DEFUN ("accessible-keymaps", Faccessible_keymaps, 1, 2, 0, /* 3069 DEFUN ("accessible-keymaps", Faccessible_keymaps, 1, 2, 0, /*
3076 Find all keymaps accessible via prefix characters from STARTMAP. 3070 Find all keymaps accessible via prefix characters from KEYMAP.
3077 Returns a list of elements of the form (KEYS . MAP), where the sequence 3071 Returns a list of elements of the form (KEYS . MAP), where the sequence
3078 KEYS starting from STARTMAP gets you to MAP. These elements are ordered 3072 KEYS starting from KEYMAP gets you to MAP. These elements are ordered
3079 so that the KEYS increase in length. The first element is ([] . STARTMAP). 3073 so that the KEYS increase in length. The first element is ([] . KEYMAP).
3080 An optional argument PREFIX, if non-nil, should be a key sequence; 3074 An optional argument PREFIX, if non-nil, should be a key sequence;
3081 then the value includes only maps for prefixes that start with PREFIX. 3075 then the value includes only maps for prefixes that start with PREFIX.
3082 */ 3076 */
3083 (startmap, prefix)) 3077 (keymap, prefix))
3084 { 3078 {
3085 /* This function can GC */ 3079 /* This function can GC */
3086 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 3080 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
3087 Lisp_Object accessible_keymaps = Qnil; 3081 Lisp_Object accessible_keymaps = Qnil;
3088 struct accessible_keymaps_closure c; 3082 struct accessible_keymaps_closure c;
3089 c.tail = Qnil; 3083 c.tail = Qnil;
3090 GCPRO4 (accessible_keymaps, c.tail, prefix, startmap); 3084 GCPRO4 (accessible_keymaps, c.tail, prefix, keymap);
3091 3085
3092 retry: 3086 retry:
3093 startmap = get_keymap (startmap, 1, 1); 3087 keymap = get_keymap (keymap, 1, 1);
3094 if (NILP (prefix)) 3088 if (NILP (prefix))
3095 prefix = make_vector (0, Qnil); 3089 prefix = make_vector (0, Qnil);
3096 else if (!VECTORP (prefix) || STRINGP (prefix)) 3090 else if (!VECTORP (prefix) || STRINGP (prefix))
3097 { 3091 {
3098 prefix = wrong_type_argument (Qarrayp, prefix); 3092 prefix = wrong_type_argument (Qarrayp, prefix);
3099 goto retry; 3093 goto retry;
3100 } 3094 }
3101 else 3095 else
3102 { 3096 {
3103 int len = XINT (Flength (prefix)); 3097 int len = XINT (Flength (prefix));
3104 Lisp_Object def = Flookup_key (startmap, prefix, Qnil); 3098 Lisp_Object def = Flookup_key (keymap, prefix, Qnil);
3105 Lisp_Object p; 3099 Lisp_Object p;
3106 int iii; 3100 int iii;
3107 struct gcpro ngcpro1; 3101 struct gcpro ngcpro1;
3108 3102
3109 def = get_keymap (def, 0, 1); 3103 def = get_keymap (def, 0, 1);
3110 if (!KEYMAPP (def)) 3104 if (!KEYMAPP (def))
3111 goto RETURN; 3105 goto RETURN;
3112 3106
3113 startmap = def; 3107 keymap = def;
3114 p = make_vector (len, Qnil); 3108 p = make_vector (len, Qnil);
3115 NGCPRO1 (p); 3109 NGCPRO1 (p);
3116 for (iii = 0; iii < len; iii++) 3110 for (iii = 0; iii < len; iii++)
3117 { 3111 {
3118 struct key_data key; 3112 struct key_data key;
3120 XVECTOR_DATA (p)[iii] = make_key_description (&key, 1); 3114 XVECTOR_DATA (p)[iii] = make_key_description (&key, 1);
3121 } 3115 }
3122 NUNGCPRO; 3116 NUNGCPRO;
3123 prefix = p; 3117 prefix = p;
3124 } 3118 }
3125 3119
3126 accessible_keymaps = list1 (Fcons (prefix, startmap)); 3120 accessible_keymaps = list1 (Fcons (prefix, keymap));
3127 3121
3128 /* For each map in the list maps, 3122 /* For each map in the list maps,
3129 look at any other maps it points to 3123 look at any other maps it points to
3130 and stick them at the end if they are not already in the list */ 3124 and stick them at the end if they are not already in the list */
3131 3125
3149 /* Pretty descriptions of key sequences */ 3143 /* Pretty descriptions of key sequences */
3150 /************************************************************************/ 3144 /************************************************************************/
3151 3145
3152 DEFUN ("key-description", Fkey_description, 1, 1, 0, /* 3146 DEFUN ("key-description", Fkey_description, 1, 1, 0, /*
3153 Return a pretty description of key-sequence KEYS. 3147 Return a pretty description of key-sequence KEYS.
3154 Control characters turn into \"C-foo\" sequences, meta into \"M-foo\" 3148 Control characters turn into "C-foo" sequences, meta into "M-foo",
3155 spaces are put between sequence elements, etc. 3149 spaces are put between sequence elements, etc...
3156 */ 3150 */
3157 (keys)) 3151 (keys))
3158 { 3152 {
3159 if (CHAR_OR_CHAR_INTP (keys) || CONSP (keys) || SYMBOLP (keys) 3153 if (CHAR_OR_CHAR_INTP (keys) || CONSP (keys) || SYMBOLP (keys)
3160 || EVENTP (keys)) 3154 || EVENTP (keys))
3241 } 3235 }
3242 else 3236 else
3243 { 3237 {
3244 CHECK_SYMBOL (keysym); 3238 CHECK_SYMBOL (keysym);
3245 #if 0 /* This is bogus */ 3239 #if 0 /* This is bogus */
3246 if (EQ (keysym, QKlinefeed)) strcpy (bufp, "LFD"); 3240 if (EQ (keysym, QKlinefeed)) strcpy (bufp, "LFD");
3247 else if (EQ (keysym, QKtab)) strcpy (bufp, "TAB"); 3241 else if (EQ (keysym, QKtab)) strcpy (bufp, "TAB");
3248 else if (EQ (keysym, QKreturn)) strcpy (bufp, "RET"); 3242 else if (EQ (keysym, QKreturn)) strcpy (bufp, "RET");
3249 else if (EQ (keysym, QKescape)) strcpy (bufp, "ESC"); 3243 else if (EQ (keysym, QKescape)) strcpy (bufp, "ESC");
3250 else if (EQ (keysym, QKdelete)) strcpy (bufp, "DEL"); 3244 else if (EQ (keysym, QKdelete)) strcpy (bufp, "DEL");
3251 else if (EQ (keysym, QKspace)) strcpy (bufp, "SPC"); 3245 else if (EQ (keysym, QKspace)) strcpy (bufp, "SPC");
3252 else if (EQ (keysym, QKbackspace)) strcpy (bufp, "BS"); 3246 else if (EQ (keysym, QKbackspace)) strcpy (bufp, "BS");
3253 else 3247 else
3254 #endif 3248 #endif
3255 strcpy (bufp, (char *) string_data (XSYMBOL (keysym)->name)); 3249 strcpy (bufp, (char *) string_data (XSYMBOL (keysym)->name));
3256 if (!NILP (XCDR (rest))) 3250 if (!NILP (XCDR (rest)))
3257 signal_simple_error ("invalid key description", 3251 signal_simple_error ("invalid key description",
3264 (wrong_type_argument (intern ("char-or-event-p"), key)); 3258 (wrong_type_argument (intern ("char-or-event-p"), key));
3265 } 3259 }
3266 3260
3267 DEFUN ("text-char-description", Ftext_char_description, 1, 1, 0, /* 3261 DEFUN ("text-char-description", Ftext_char_description, 1, 1, 0, /*
3268 Return a pretty description of file-character CHR. 3262 Return a pretty description of file-character CHR.
3269 Unprintable characters turn into \"^char\" or \\NNN, depending on the value 3263 Unprintable characters turn into "^char" or \\NNN, depending on the value
3270 of the `ctl-arrow' variable. 3264 of the `ctl-arrow' variable.
3271 This differs from `single-key-description' in that it returns a description 3265 This differs from `single-key-description' in that it returns a description
3272 of a character from a buffer rather than a key read from the user. 3266 of a character from a buffer rather than a key read from the user.
3273 */ 3267 */
3274 (chr)) 3268 (chr))
3377 { 3371 {
3378 nmaps = get_relevant_keymaps (event_or_keys, countof (maps), 3372 nmaps = get_relevant_keymaps (event_or_keys, countof (maps),
3379 gubbish); 3373 gubbish);
3380 if (nmaps > countof (maps)) 3374 if (nmaps > countof (maps))
3381 { 3375 {
3382 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); 3376 gubbish = alloca_array (Lisp_Object, nmaps);
3383 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish); 3377 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish);
3384 } 3378 }
3385 } 3379 }
3386 else if (CONSP (keymaps)) 3380 else if (CONSP (keymaps))
3387 { 3381 {
3389 int i; 3383 int i;
3390 3384
3391 nmaps = XINT (Flength (keymaps)); 3385 nmaps = XINT (Flength (keymaps));
3392 if (nmaps > countof (maps)) 3386 if (nmaps > countof (maps))
3393 { 3387 {
3394 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); 3388 gubbish = alloca_array (Lisp_Object, nmaps);
3395 } 3389 }
3396 for (rest = keymaps, i = 0; !NILP (rest); 3390 for (rest = keymaps, i = 0; !NILP (rest);
3397 rest = XCDR (keymaps), i++) 3391 rest = XCDR (keymaps), i++)
3398 { 3392 {
3399 gubbish[i] = get_keymap (XCAR (keymaps), 1, 1); 3393 gubbish[i] = get_keymap (XCAR (keymaps), 1, 1);
3407 { 3401 {
3408 gubbish[1] = Vcurrent_global_map; 3402 gubbish[1] = Vcurrent_global_map;
3409 nmaps++; 3403 nmaps++;
3410 } 3404 }
3411 } 3405 }
3412 3406
3413 return where_is_internal (definition, gubbish, nmaps, firstonly, 0); 3407 return where_is_internal (definition, gubbish, nmaps, firstonly, 0);
3414 } 3408 }
3415 3409
3416 /* This function is like 3410 /* This function is like
3417 (key-description (where-is-internal definition nil t)) 3411 (key-description (where-is-internal definition nil t))
3418 except that it writes its output into a (char *) buffer that you 3412 except that it writes its output into a (char *) buffer that you
3419 provide; it doesn't cons (or allocate memory) at all, so it's 3413 provide; it doesn't cons (or allocate memory) at all, so it's
3420 very fast. This is used by menubar.c. 3414 very fast. This is used by menubar.c.
3421 */ 3415 */
3422 void 3416 void
3423 where_is_to_char (Lisp_Object definition, char *buffer) 3417 where_is_to_char (Lisp_Object definition, char *buffer)
3429 3423
3430 /* Get keymaps as an array */ 3424 /* Get keymaps as an array */
3431 nmaps = get_relevant_keymaps (Qnil, countof (maps), gubbish); 3425 nmaps = get_relevant_keymaps (Qnil, countof (maps), gubbish);
3432 if (nmaps > countof (maps)) 3426 if (nmaps > countof (maps))
3433 { 3427 {
3434 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); 3428 gubbish = alloca_array (Lisp_Object, nmaps);
3435 nmaps = get_relevant_keymaps (Qnil, nmaps, gubbish); 3429 nmaps = get_relevant_keymaps (Qnil, nmaps, gubbish);
3436 } 3430 }
3437 3431
3438 buffer[0] = 0; 3432 buffer[0] = 0;
3439 where_is_internal (definition, maps, nmaps, Qt, buffer); 3433 where_is_internal (definition, maps, nmaps, Qt, buffer);
3440 } 3434 }
3441 3435
3442 3436
3443 static Lisp_Object 3437 static Lisp_Object
3444 raw_keys_to_keys (struct key_data *keys, int count) 3438 raw_keys_to_keys (struct key_data *keys, int count)
3445 { 3439 {
3446 Lisp_Object result = make_vector (count, Qnil); 3440 Lisp_Object result = make_vector (count, Qnil);
3447 while (count--) 3441 while (count--)
3448 XVECTOR_DATA (result) [count] = make_key_description (&(keys[count]), 1); 3442 XVECTOR_DATA (result) [count] = make_key_description (&(keys[count]), 1);
3479 If we're in the "meta" submap of the map that "C-x 4" is bound to, 3473 If we're in the "meta" submap of the map that "C-x 4" is bound to,
3480 then keys_so_far will be {(control x), \4}, and modifiers_so_far 3474 then keys_so_far will be {(control x), \4}, and modifiers_so_far
3481 will be MOD_META. That is, keys_so_far is the chain of keys that we 3475 will be MOD_META. That is, keys_so_far is the chain of keys that we
3482 have followed, and modifiers_so_far_so_far is the bits (partial keys) 3476 have followed, and modifiers_so_far_so_far is the bits (partial keys)
3483 beyond that. 3477 beyond that.
3484 3478
3485 (keys_so_far is a global buffer and the keys_count arg says how much 3479 (keys_so_far is a global buffer and the keys_count arg says how much
3486 of it we're currently interested in.) 3480 of it we're currently interested in.)
3487 3481
3488 If target_buffer is provided, then we write a key-description into it, 3482 If target_buffer is provided, then we write a key-description into it,
3489 to avoid consing a string. This only works with firstonly on. 3483 to avoid consing a string. This only works with firstonly on.
3490 */ 3484 */
3491 3485
3492 struct where_is_closure 3486 struct where_is_closure
3507 3501
3508 static Lisp_Object 3502 static Lisp_Object
3509 where_is_recursive_mapper (Lisp_Object map, void *arg) 3503 where_is_recursive_mapper (Lisp_Object map, void *arg)
3510 { 3504 {
3511 /* This function can GC */ 3505 /* This function can GC */
3512 struct where_is_closure *c = arg; 3506 struct where_is_closure *c = (struct where_is_closure *) arg;
3513 Lisp_Object definition = c->definition; 3507 Lisp_Object definition = c->definition;
3514 CONST int firstonly = c->firstonly; 3508 CONST int firstonly = c->firstonly;
3515 CONST unsigned int keys_count = c->keys_count; 3509 CONST unsigned int keys_count = c->keys_count;
3516 CONST unsigned int modifiers_so_far = c->modifiers_so_far; 3510 CONST unsigned int modifiers_so_far = c->modifiers_so_far;
3517 char *target_buffer = c->target_buffer; 3511 char *target_buffer = c->target_buffer;
3521 Lisp_Object submaps; 3515 Lisp_Object submaps;
3522 Lisp_Object result = Qnil; 3516 Lisp_Object result = Qnil;
3523 3517
3524 if (!NILP (keys)) 3518 if (!NILP (keys))
3525 { 3519 {
3526 /* One or more keys in this map match the definition we're looking 3520 /* One or more keys in this map match the definition we're looking for.
3527 for. Verify that these bindings aren't shadowed by other bindings 3521 Verify that these bindings aren't shadowed by other bindings
3528 in the shadow maps. Either nil or number as value from 3522 in the shadow maps. Either nil or number as value from
3529 raw_lookup_key() means undefined. 3523 raw_lookup_key() means undefined. */
3530 */
3531 struct key_data *so_far = c->keys_so_far; 3524 struct key_data *so_far = c->keys_so_far;
3532 3525
3533 for (;;) /* loop over all keys that match */ 3526 for (;;) /* loop over all keys that match */
3534 { 3527 {
3535 Lisp_Object k = ((CONSP (keys)) ? XCAR (keys) : keys); 3528 Lisp_Object k = ((CONSP (keys)) ? XCAR (keys) : keys);
3536 int i; 3529 int i;
3537 3530
3538 so_far [keys_count].keysym = k; 3531 so_far [keys_count].keysym = k;
3539 so_far [keys_count].modifiers = modifiers_so_far; 3532 so_far [keys_count].modifiers = modifiers_so_far;
3540 3533
3541 /* now loop over all shadow maps */ 3534 /* now loop over all shadow maps */
3542 for (i = 0; i < c->shadow_count; i++) 3535 for (i = 0; i < c->shadow_count; i++)
3543 { 3536 {
3544 Lisp_Object shadowed = raw_lookup_key (c->shadow[i], 3537 Lisp_Object shadowed = raw_lookup_key (c->shadow[i],
3545 so_far, 3538 so_far,
3546 keys_count + 1, 3539 keys_count + 1,
3547 0, 1); 3540 0, 1);
3548 3541
3549 if (NILP (shadowed) || CHARP (shadowed) || 3542 if (NILP (shadowed) || CHARP (shadowed) ||
3550 EQ (shadowed, definition)) 3543 EQ (shadowed, definition))
3551 continue; /* we passed this test; it's not shadowed here. */ 3544 continue; /* we passed this test; it's not shadowed here. */
3574 keys = XCDR (keys); 3567 keys = XCDR (keys);
3575 } 3568 }
3576 } 3569 }
3577 3570
3578 /* Now search the sub-keymaps of this map. 3571 /* Now search the sub-keymaps of this map.
3579 If we're in "firstonly" mode and have already found one, this 3572 If we're in "firstonly" mode and have already found one, this
3580 point is not reached. If we get one from lower down, either 3573 point is not reached. If we get one from lower down, either
3581 return it immediately (in firstonly mode) or tack it onto the 3574 return it immediately (in firstonly mode) or tack it onto the
3582 end of the ones we've gotten so far. 3575 end of the ones we've gotten so far.
3583 */ 3576 */
3584 for (submaps = keymap_submaps (map); 3577 for (submaps = keymap_submaps (map);
3589 Lisp_Object submap = XCDR (XCAR (submaps)); 3582 Lisp_Object submap = XCDR (XCAR (submaps));
3590 unsigned int lower_modifiers; 3583 unsigned int lower_modifiers;
3591 int lower_keys_count = keys_count; 3584 int lower_keys_count = keys_count;
3592 unsigned int bucky; 3585 unsigned int bucky;
3593 3586
3594 submap = get_keymap (submap, 0, 1); 3587 submap = get_keymap (submap, 0, 0);
3595 3588
3596 if (EQ (submap, map)) 3589 if (EQ (submap, map))
3597 /* Arrgh! Some loser has introduced a loop... */ 3590 /* Arrgh! Some loser has introduced a loop... */
3598 continue; 3591 continue;
3599 3592
3627 if (lower_keys_count >= c->keys_so_far_total_size) 3620 if (lower_keys_count >= c->keys_so_far_total_size)
3628 { 3621 {
3629 int size = lower_keys_count + 50; 3622 int size = lower_keys_count + 50;
3630 if (! c->keys_so_far_malloced) 3623 if (! c->keys_so_far_malloced)
3631 { 3624 {
3632 struct key_data *new = xmalloc (size * sizeof (struct key_data)); 3625 struct key_data *new = xnew_array (struct key_data, size);
3633 memcpy ((void *)new, (const void *)c->keys_so_far, 3626 memcpy ((void *)new, (const void *)c->keys_so_far,
3634 c->keys_so_far_total_size * sizeof (struct key_data)); 3627 c->keys_so_far_total_size * sizeof (struct key_data));
3635 } 3628 }
3636 else 3629 else
3637 c->keys_so_far = xrealloc (c->keys_so_far, 3630 XREALLOC_ARRAY (c->keys_so_far, struct key_data, size);
3638 size * sizeof (struct key_data));
3639 3631
3640 c->keys_so_far_total_size = size; 3632 c->keys_so_far_total_size = size;
3641 c->keys_so_far_malloced = 1; 3633 c->keys_so_far_malloced = 1;
3642 } 3634 }
3643 3635
3645 Lisp_Object lower; 3637 Lisp_Object lower;
3646 3638
3647 c->keys_count = lower_keys_count; 3639 c->keys_count = lower_keys_count;
3648 c->modifiers_so_far = lower_modifiers; 3640 c->modifiers_so_far = lower_modifiers;
3649 3641
3650 lower = traverse_keymaps (submap, Qnil, where_is_recursive_mapper, 3642 lower = traverse_keymaps (submap, Qnil, where_is_recursive_mapper, c);
3651 c); 3643
3652 c->keys_count = keys_count; 3644 c->keys_count = keys_count;
3653 c->modifiers_so_far = modifiers_so_far; 3645 c->modifiers_so_far = modifiers_so_far;
3654 3646
3655 if (!firstonly) 3647 if (!firstonly)
3656 result = nconc2 (lower, result); 3648 result = nconc2 (lower, result);
3716 /* Describing keymaps */ 3708 /* Describing keymaps */
3717 /************************************************************************/ 3709 /************************************************************************/
3718 3710
3719 DEFUN ("describe-bindings-internal", Fdescribe_bindings_internal, 1, 5, 0, /* 3711 DEFUN ("describe-bindings-internal", Fdescribe_bindings_internal, 1, 5, 0, /*
3720 Insert a list of all defined keys and their definitions in MAP. 3712 Insert a list of all defined keys and their definitions in MAP.
3721 Optional second argument ALL says whether to include even \"uninteresting\" 3713 Optional second argument ALL says whether to include even "uninteresting"
3722 definitions (ie symbols with a non-nil `suppress-keymap' property. 3714 definitions (ie symbols with a non-nil `suppress-keymap' property.
3723 Third argument SHADOW is a list of keymaps whose bindings shadow those 3715 Third argument SHADOW is a list of keymaps whose bindings shadow those
3724 of map; if a binding is present in any shadowing map, it is not printed. 3716 of map; if a binding is present in any shadowing map, it is not printed.
3725 Fourth argument PREFIX, if non-nil, should be a key sequence; 3717 Fourth argument PREFIX, if non-nil, should be a key sequence;
3726 only bindings which start with that key sequence will be printed. 3718 only bindings which start with that key sequence will be printed.
3739 followed by those of all maps reachable through STARTMAP. 3731 followed by those of all maps reachable through STARTMAP.
3740 If PARTIAL is nonzero, omit certain "uninteresting" commands 3732 If PARTIAL is nonzero, omit certain "uninteresting" commands
3741 (such as `undefined'). 3733 (such as `undefined').
3742 If SHADOW is non-nil, it is a list of other maps; 3734 If SHADOW is non-nil, it is a list of other maps;
3743 don't mention keys which would be shadowed by any of them 3735 don't mention keys which would be shadowed by any of them
3744 If PREFIX is non-nil, only list bindings which start with those keys 3736 If PREFIX is non-nil, only list bindings which start with those keys.
3745 */ 3737 */
3746 3738
3747 void 3739 void
3748 describe_map_tree (Lisp_Object startmap, int partial, Lisp_Object shadow, 3740 describe_map_tree (Lisp_Object startmap, int partial, Lisp_Object shadow,
3749 Lisp_Object prefix, int mice_only_p) 3741 Lisp_Object prefix, int mice_only_p)
3757 3749
3758 for (; !NILP (maps); maps = Fcdr (maps)) 3750 for (; !NILP (maps); maps = Fcdr (maps))
3759 { 3751 {
3760 Lisp_Object sub_shadow = Qnil; 3752 Lisp_Object sub_shadow = Qnil;
3761 Lisp_Object elt = Fcar (maps); 3753 Lisp_Object elt = Fcar (maps);
3762 Lisp_Object tail = shadow; 3754 Lisp_Object tail;
3763 int no_prefix = (VECTORP (Fcar (elt)) 3755 int no_prefix = (VECTORP (Fcar (elt))
3764 && XINT (Flength (Fcar (elt))) == 0); 3756 && XINT (Flength (Fcar (elt))) == 0);
3765 struct gcpro ngcpro1, ngcpro2, ngcpro3; 3757 struct gcpro ngcpro1, ngcpro2, ngcpro3;
3766 NGCPRO3 (sub_shadow, elt, tail); 3758 NGCPRO3 (sub_shadow, elt, tail);
3767 3759
3768 for (; CONSP (tail); tail = XCDR (tail)) 3760 for (tail = shadow; CONSP (tail); tail = XCDR (tail))
3769 { 3761 {
3770 Lisp_Object sh = XCAR (tail); 3762 Lisp_Object shmap = XCAR (tail);
3771 3763
3772 /* If the sequence by which we reach this keymap is zero-length, 3764 /* If the sequence by which we reach this keymap is zero-length,
3773 then the shadow maps for this keymap are just SHADOW. */ 3765 then the shadow maps for this keymap are just SHADOW. */
3774 if (no_prefix) 3766 if (no_prefix)
3775 ; 3767 ;
3776 /* If the sequence by which we reach this keymap actually has 3768 /* If the sequence by which we reach this keymap actually has
3777 some elements, then the sequence's definition in SHADOW is 3769 some elements, then the sequence's definition in SHADOW is
3778 what we should use. */ 3770 what we should use. */
3779 else 3771 else
3780 { 3772 {
3781 sh = Flookup_key (sh, Fcar (elt), Qt); 3773 shmap = Flookup_key (shmap, Fcar (elt), Qt);
3782 if (CHARP (sh)) 3774 if (CHARP (shmap))
3783 sh = Qnil; 3775 shmap = Qnil;
3784 } 3776 }
3785 3777
3786 if (!NILP (sh)) 3778 if (!NILP (shmap))
3787 { 3779 {
3788 Lisp_Object shm = get_keymap (sh, 0, 1); 3780 Lisp_Object shm = get_keymap (shmap, 0, 1);
3781 /* If shmap is not nil and not a keymap, it completely
3782 shadows this map, so don't describe this map at all. */
3789 if (!KEYMAPP (shm)) 3783 if (!KEYMAPP (shm))
3790 /* If sh is not nil and not a keymap, it completely shadows
3791 this map, so don't describe this map at all. */
3792 goto SKIP; 3784 goto SKIP;
3793 sub_shadow = Fcons (shm, sub_shadow); 3785 sub_shadow = Fcons (shm, sub_shadow);
3794 } 3786 }
3795 } 3787 }
3796 3788
3846 { 3838 {
3847 Lisp_Object name = XKEYMAP (definition)->name; 3839 Lisp_Object name = XKEYMAP (definition)->name;
3848 if (STRINGP (name) || (SYMBOLP (name) && !NILP (name))) 3840 if (STRINGP (name) || (SYMBOLP (name) && !NILP (name)))
3849 { 3841 {
3850 buffer_insert_c_string (XBUFFER (buffer), "Prefix command "); 3842 buffer_insert_c_string (XBUFFER (buffer), "Prefix command ");
3851 if (SYMBOLP (name) 3843 if (SYMBOLP (name)
3852 && EQ (find_symbol_value (name), definition)) 3844 && EQ (find_symbol_value (name), definition))
3853 buffer_insert1 (XBUFFER (buffer), Fsymbol_name (name)); 3845 buffer_insert1 (XBUFFER (buffer), Fsymbol_name (name));
3854 else 3846 else
3855 { 3847 {
3856 buffer_insert1 (XBUFFER (buffer), Fprin1_to_string (name, Qnil)); 3848 buffer_insert1 (XBUFFER (buffer), Fprin1_to_string (name, Qnil));
3886 }; 3878 };
3887 3879
3888 static Lisp_Object 3880 static Lisp_Object
3889 describe_map_mapper_shadow_search (Lisp_Object map, void *arg) 3881 describe_map_mapper_shadow_search (Lisp_Object map, void *arg)
3890 { 3882 {
3891 struct describe_map_shadow_closure *c = arg; 3883 struct describe_map_shadow_closure *c =
3884 (struct describe_map_shadow_closure *) arg;
3892 3885
3893 if (EQ (map, c->self)) 3886 if (EQ (map, c->self))
3894 return Qzero; /* Not shadowed; terminate search */ 3887 return Qzero; /* Not shadowed; terminate search */
3895 if (!NILP (keymap_lookup_directly (map, 3888
3896 c->raw_key->keysym, 3889 return (!NILP (keymap_lookup_directly (map,
3897 c->raw_key->modifiers))) 3890 c->raw_key->keysym,
3898 return Qt; 3891 c->raw_key->modifiers)))
3899 else 3892 ? Qt : Qnil;
3900 return Qnil; 3893 }
3901 } 3894
3902
3903 3895
3904 static Lisp_Object 3896 static Lisp_Object
3905 keymap_lookup_inherited_mapper (Lisp_Object km, void *arg) 3897 keymap_lookup_inherited_mapper (Lisp_Object km, void *arg)
3906 { 3898 {
3907 struct key_data *k = arg; 3899 struct key_data *k = (struct key_data *) arg;
3908 return keymap_lookup_directly (km, k->keysym, k->modifiers); 3900 return keymap_lookup_directly (km, k->keysym, k->modifiers);
3909 } 3901 }
3910 3902
3911 3903
3912 static void 3904 static void
3913 describe_map_mapper (CONST struct key_data *key, 3905 describe_map_mapper (CONST struct key_data *key,
3914 Lisp_Object binding, 3906 Lisp_Object binding,
3915 void *describe_map_closure) 3907 void *describe_map_closure)
3916 { 3908 {
3917 /* This function can GC */ 3909 /* This function can GC */
3918 struct describe_map_closure *closure = describe_map_closure; 3910 struct describe_map_closure *closure =
3911 (struct describe_map_closure *) describe_map_closure;
3919 Lisp_Object keysym = key->keysym; 3912 Lisp_Object keysym = key->keysym;
3920 unsigned int modifiers = key->modifiers; 3913 unsigned int modifiers = key->modifiers;
3921 3914
3922 /* Dont mention suppressed commands. */ 3915 /* Dont mention suppressed commands. */
3923 if (SYMBOLP (binding) 3916 if (SYMBOLP (binding)
3924 && !NILP (closure->partial) 3917 && !NILP (closure->partial)
3925 && !NILP (Fget (binding, closure->partial, Qnil))) 3918 && !NILP (Fget (binding, closure->partial, Qnil)))
3926 return; 3919 return;
3927 3920
3928 /* If we're only supposed to display mouse bindings and this isn't one, 3921 /* If we're only supposed to display mouse bindings and this isn't one,
3929 then bug out. */ 3922 then bug out. */
3930 if (closure->mice_only_p && 3923 if (closure->mice_only_p &&
3931 (! (EQ (keysym, Qbutton0) || EQ (keysym, Qbutton1) 3924 (! (EQ (keysym, Qbutton0) ||
3932 || EQ (keysym, Qbutton2) || EQ (keysym, Qbutton3) 3925 EQ (keysym, Qbutton1) ||
3933 || EQ (keysym, Qbutton4) || EQ (keysym, Qbutton5) 3926 EQ (keysym, Qbutton2) ||
3934 || EQ (keysym, Qbutton6) || EQ (keysym, Qbutton7)))) 3927 EQ (keysym, Qbutton3) ||
3928 EQ (keysym, Qbutton4) ||
3929 EQ (keysym, Qbutton5) ||
3930 EQ (keysym, Qbutton6) ||
3931 EQ (keysym, Qbutton7))))
3935 return; 3932 return;
3936 3933
3937 /* If this command in this map is shadowed by some other map, ignore it. */ 3934 /* If this command in this map is shadowed by some other map, ignore it. */
3938 { 3935 {
3939 Lisp_Object tail; 3936 Lisp_Object tail;
3970 *(closure->list)); 3967 *(closure->list));
3971 } 3968 }
3972 3969
3973 3970
3974 static int 3971 static int
3975 describe_map_sort_predicate (Lisp_Object obj1, Lisp_Object obj2, 3972 describe_map_sort_predicate (Lisp_Object obj1, Lisp_Object obj2,
3976 Lisp_Object pred) 3973 Lisp_Object pred)
3977 { 3974 {
3978 /* obj1 and obj2 are conses of the form 3975 /* obj1 and obj2 are conses of the form
3979 ( ( <keysym> . <modifiers> ) . <binding> ) 3976 ( ( <keysym> . <modifiers> ) . <binding> )
3980 keysym and modifiers are used, binding is ignored. 3977 keysym and modifiers are used, binding is ignored.
4034 CHECK_CHAR_COERCE_INT (s2); 4031 CHECK_CHAR_COERCE_INT (s2);
4035 } 4032 }
4036 else return 0; 4033 else return 0;
4037 } 4034 }
4038 4035
4039 if (XCHAR (s1) == XCHAR (s2) || 4036 return (XCHAR (s1) == XCHAR (s2) ||
4040 XCHAR (s1) + 1 == XCHAR (s2)) 4037 XCHAR (s1) + 1 == XCHAR (s2));
4041 return 1;
4042 return 0;
4043 } 4038 }
4044 4039
4045 4040
4046 static Lisp_Object 4041 static Lisp_Object
4047 describe_map_parent_mapper (Lisp_Object keymap, void *arg) 4042 describe_map_parent_mapper (Lisp_Object keymap, void *arg)
4048 { 4043 {
4049 /* This function can GC */ 4044 /* This function can GC */
4050 struct describe_map_closure *describe_map_closure = arg; 4045 struct describe_map_closure *describe_map_closure =
4046 (struct describe_map_closure *) arg;
4051 describe_map_closure->self = keymap; 4047 describe_map_closure->self = keymap;
4052 map_keymap (XKEYMAP (keymap)->table, 4048 map_keymap (XKEYMAP (keymap)->table,
4053 0, /* don't sort: we'll do it later */ 4049 0, /* don't sort: we'll do it later */
4054 describe_map_mapper, describe_map_closure); 4050 describe_map_mapper, describe_map_closure);
4055 return Qnil; 4051 return Qnil;
4056 } 4052 }
4057 4053
4058 4054
4055 /* Describe the contents of map MAP, assuming that this map itself is
4056 reached by the sequence of prefix keys KEYS (a string or vector).
4057 PARTIAL, SHADOW, NOMENU are as in `describe_map_tree' above. */
4058
4059 static void 4059 static void
4060 describe_map (Lisp_Object keymap, Lisp_Object elt_prefix, 4060 describe_map (Lisp_Object keymap, Lisp_Object elt_prefix,
4061 void (*elt_describer) (Lisp_Object), 4061 void (*elt_describer) (Lisp_Object),
4062 int partial, 4062 int partial,
4063 Lisp_Object shadow, 4063 Lisp_Object shadow,
4064 int mice_only_p) 4064 int mice_only_p)
4065 { 4065 {
4066 /* This function can GC */ 4066 /* This function can GC */
4067 struct describe_map_closure describe_map_closure; 4067 struct describe_map_closure describe_map_closure;
4125 buffer_insert_c_string (buf, "DEL"); 4125 buffer_insert_c_string (buf, "DEL");
4126 else if (EQ (keysym, QKspace)) 4126 else if (EQ (keysym, QKspace))
4127 buffer_insert_c_string (buf, "SPC"); 4127 buffer_insert_c_string (buf, "SPC");
4128 else if (EQ (keysym, QKbackspace)) 4128 else if (EQ (keysym, QKbackspace))
4129 buffer_insert_c_string (buf, "BS"); 4129 buffer_insert_c_string (buf, "BS");
4130 else 4130 else
4131 #endif 4131 #endif
4132 if (c >= printable_min) 4132 if (c >= printable_min)
4133 buffer_insert_emacs_char (buf, c); 4133 buffer_insert_emacs_char (buf, c);
4134 else buffer_insert1 (buf, Fsymbol_name (keysym)); 4134 else buffer_insert1 (buf, Fsymbol_name (keysym));
4135 } 4135 }
4214 4214
4215 DEFSUBR (Ftext_char_description); 4215 DEFSUBR (Ftext_char_description);
4216 4216
4217 defsymbol (&Qcontrol, "control"); 4217 defsymbol (&Qcontrol, "control");
4218 defsymbol (&Qctrl, "ctrl"); 4218 defsymbol (&Qctrl, "ctrl");
4219 defsymbol (&Qmeta, "meta"); 4219 defsymbol (&Qmeta, "meta");
4220 defsymbol (&Qsuper, "super"); 4220 defsymbol (&Qsuper, "super");
4221 defsymbol (&Qhyper, "hyper"); 4221 defsymbol (&Qhyper, "hyper");
4222 defsymbol (&Qalt, "alt"); 4222 defsymbol (&Qalt, "alt");
4223 defsymbol (&Qshift, "shift"); 4223 defsymbol (&Qshift, "shift");
4224 defsymbol (&Qbutton0, "button0"); 4224 defsymbol (&Qbutton0, "button0");
4225 defsymbol (&Qbutton1, "button1"); 4225 defsymbol (&Qbutton1, "button1");
4226 defsymbol (&Qbutton2, "button2"); 4226 defsymbol (&Qbutton2, "button2");