comparison src/keymap.c @ 173:8eaf7971accc r20-3b13

Import from CVS: tag r20-3b13
author cvs
date Mon, 13 Aug 2007 09:49:09 +0200
parents 28f395d8dc7a
children 2d532a89d707
comparison
equal deleted inserted replaced
172:a38aed19690b 173:8eaf7971accc
265 ((markobj) (keymap->prompt)); 265 ((markobj) (keymap->prompt));
266 ((markobj) (keymap->inverse_table)); 266 ((markobj) (keymap->inverse_table));
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 {
328 struct Lisp_Cons *victim = XCONS (malloc_bites); 328 struct Lisp_Cons *victim = XCONS (malloc_bites);
329 malloc_bites = victim->cdr; 329 malloc_bites = victim->cdr;
330 free_cons (victim); 330 free_cons (victim);
331 } 331 }
332 UNGCPRO; 332 UNGCPRO;
333 return (result); 333 return result;
334 } 334 }
335 if (NILP (tail)) 335 if (NILP (tail))
336 { 336 {
337 if (stack_depth == 0) 337 if (stack_depth == 0)
338 { 338 {
339 UNGCPRO; 339 UNGCPRO;
340 return (Qnil); /* Nothing found */ 340 return Qnil; /* Nothing found */
341 } 341 }
342 stack_depth--; 342 stack_depth--;
343 if (CONSP (malloc_bites)) 343 if (CONSP (malloc_bites))
344 { 344 {
345 struct Lisp_Cons *victim = XCONS (malloc_bites); 345 struct Lisp_Cons *victim = XCONS (malloc_bites);
427 control_meta_superify (Lisp_Object frob, unsigned int modifiers) 427 control_meta_superify (Lisp_Object frob, unsigned int modifiers)
428 { 428 {
429 if (modifiers == 0) 429 if (modifiers == 0)
430 return frob; 430 return frob;
431 frob = Fcons (frob, Qnil); 431 frob = Fcons (frob, Qnil);
432 if (modifiers & MOD_SHIFT) 432 if (modifiers & MOD_SHIFT) frob = Fcons (Qshift, frob);
433 frob = Fcons (Qshift, frob); 433 if (modifiers & MOD_ALT) frob = Fcons (Qalt, frob);
434 if (modifiers & MOD_ALT) 434 if (modifiers & MOD_HYPER) frob = Fcons (Qhyper, frob);
435 frob = Fcons (Qalt, frob); 435 if (modifiers & MOD_SUPER) frob = Fcons (Qsuper, frob);
436 if (modifiers & MOD_HYPER) 436 if (modifiers & MOD_CONTROL) frob = Fcons (Qcontrol, frob);
437 frob = Fcons (Qhyper, frob); 437 if (modifiers & MOD_META) frob = Fcons (Qmeta, frob);
438 if (modifiers & MOD_SUPER) 438 return frob;
439 frob = Fcons (Qsuper, frob);
440 if (modifiers & MOD_CONTROL)
441 frob = Fcons (Qcontrol, frob);
442 if (modifiers & MOD_META)
443 frob = Fcons (Qmeta, frob);
444 return (frob);
445 } 439 }
446 440
447 static Lisp_Object 441 static Lisp_Object
448 make_key_description (CONST struct key_data *key, int prettify) 442 make_key_description (CONST struct key_data *key, int prettify)
449 { 443 {
461 Bufbyte str [1 + MAX_EMCHAR_LEN]; 455 Bufbyte str [1 + MAX_EMCHAR_LEN];
462 Bytecount count = set_charptr_emchar (str, XCHAR (keysym)); 456 Bytecount count = set_charptr_emchar (str, XCHAR (keysym));
463 str[count] = 0; 457 str[count] = 0;
464 keysym = intern ((char *) str); 458 keysym = intern ((char *) str);
465 } 459 }
466 return (control_meta_superify (keysym, modifiers)); 460 return control_meta_superify (keysym, modifiers);
467 } 461 }
468 462
469 463
470 /************************************************************************/ 464 /************************************************************************/
471 /* Low-level keymap-store functions */ 465 /* Low-level keymap-store functions */
500 if (modifiers & MOD_META) /* Utterly hateful ESC lossage */ 494 if (modifiers & MOD_META) /* Utterly hateful ESC lossage */
501 { 495 {
502 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META), 496 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META),
503 k->table, Qnil); 497 k->table, Qnil);
504 if (NILP (submap)) 498 if (NILP (submap))
505 return (Qnil); 499 return Qnil;
506 k = XKEYMAP (submap); 500 k = XKEYMAP (submap);
507 modifiers &= ~MOD_META; 501 modifiers &= ~MOD_META;
508 } 502 }
509 503
510 if (modifiers != 0) 504 if (modifiers != 0)
511 { 505 {
512 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (modifiers), 506 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (modifiers),
513 k->table, Qnil); 507 k->table, Qnil);
514 if (NILP (submap)) 508 if (NILP (submap))
515 return (Qnil); 509 return Qnil;
516 k = XKEYMAP (submap); 510 k = XKEYMAP (submap);
517 } 511 }
518 return (Fgethash (keysym, k->table, Qnil)); 512 return Fgethash (keysym, k->table, Qnil);
519 } 513 }
520 514
521 static void 515 static void
522 keymap_store_inverse_internal (Lisp_Object inverse_table, 516 keymap_store_inverse_internal (Lisp_Object inverse_table,
523 Lisp_Object keysym, 517 Lisp_Object keysym,
627 XKEYMAP (submap)->name 621 XKEYMAP (submap)->name
628 = control_meta_superify (parent_for_debugging_info, modifiers); 622 = control_meta_superify (parent_for_debugging_info, modifiers);
629 /* Invalidate cache */ 623 /* Invalidate cache */
630 k->sub_maps_cache = Qt; 624 k->sub_maps_cache = Qt;
631 keymap_store_internal (MAKE_MODIFIER_HASH_KEY (modifiers), k, submap); 625 keymap_store_internal (MAKE_MODIFIER_HASH_KEY (modifiers), k, submap);
632 return (submap); 626 return submap;
633 } 627 }
634 628
635 629
636 /* Relies on caller to gc-protect keymap, keysym, value */ 630 /* Relies on caller to gc-protect keymap, keysym, value */
637 static void 631 static void
742 k->sub_maps_cache = list_sort (result, 736 k->sub_maps_cache = list_sort (result,
743 Qnil, 737 Qnil,
744 map_keymap_sort_predicate); 738 map_keymap_sort_predicate);
745 UNGCPRO; 739 UNGCPRO;
746 } 740 }
747 return (k->sub_maps_cache); 741 return k->sub_maps_cache;
748 } 742 }
749 743
750 744
751 /************************************************************************/ 745 /************************************************************************/
752 /* Basic operations on keymaps */ 746 /* Basic operations on keymaps */
774 /* Inverse table is often less dense because of duplicate key-bindings. 768 /* Inverse table is often less dense because of duplicate key-bindings.
775 If not, it will grow anyway. */ 769 If not, it will grow anyway. */
776 keymap->inverse_table = Fmake_hashtable (make_int (size * 3 / 4), Qnil); 770 keymap->inverse_table = Fmake_hashtable (make_int (size * 3 / 4), Qnil);
777 } 771 }
778 keymap->name = Qnil; 772 keymap->name = Qnil;
779 return (result); 773 return result;
780 } 774 }
781 775
782 DEFUN ("make-keymap", Fmake_keymap, 0, 1, 0, /* 776 DEFUN ("make-keymap", Fmake_keymap, 0, 1, 0, /*
783 Construct and return a new keymap object. 777 Construct and return a new keymap object.
784 All entries in it are nil, meaning \"command undefined\". 778 All entries in it are nil, meaning \"command undefined\".
821 of all keymaps. 815 of all keymaps.
822 */ 816 */
823 (keymap)) 817 (keymap))
824 { 818 {
825 keymap = get_keymap (keymap, 1, 1); 819 keymap = get_keymap (keymap, 1, 1);
826 return (Fcopy_sequence (XKEYMAP (keymap)->parents)); 820 return Fcopy_sequence (XKEYMAP (keymap)->parents);
827 } 821 }
828 822
829 823
830 824
831 static Lisp_Object 825 static Lisp_Object
832 traverse_keymaps_noop (Lisp_Object keymap, void *arg) 826 traverse_keymaps_noop (Lisp_Object keymap, void *arg)
833 { 827 {
834 return (Qnil); 828 return Qnil;
835 } 829 }
836 830
837 DEFUN ("set-keymap-parents", Fset_keymap_parents, 2, 2, 0, /* 831 DEFUN ("set-keymap-parents", Fset_keymap_parents, 2, 2, 0, /*
838 Sets the `parent' keymaps of the given keymap. 832 Sets the `parent' keymaps of the given keymap.
839 The parents of a keymap are searched for keybindings when a key sequence 833 The parents of a keymap are searched for keybindings when a key sequence
869 /* Check for circularities */ 863 /* Check for circularities */
870 traverse_keymaps (keymap, parents, traverse_keymaps_noop, 0); 864 traverse_keymaps (keymap, parents, traverse_keymaps_noop, 0);
871 keymap_tick++; 865 keymap_tick++;
872 XKEYMAP (keymap)->parents = Fcopy_sequence (parents); 866 XKEYMAP (keymap)->parents = Fcopy_sequence (parents);
873 UNGCPRO; 867 UNGCPRO;
874 return (parents); 868 return parents;
875 } 869 }
876 870
877 DEFUN ("set-keymap-name", Fset_keymap_name, 2, 2, 0, /* 871 DEFUN ("set-keymap-name", Fset_keymap_name, 2, 2, 0, /*
878 Set the `name' of the KEYMAP to NEW-NAME. 872 Set the `name' of the KEYMAP to NEW-NAME.
879 The name is only a debugging convenience; it is not used except 873 The name is only a debugging convenience; it is not used except
882 (keymap, new_name)) 876 (keymap, new_name))
883 { 877 {
884 keymap = get_keymap (keymap, 1, 1); 878 keymap = get_keymap (keymap, 1, 1);
885 879
886 XKEYMAP (keymap)->name = new_name; 880 XKEYMAP (keymap)->name = new_name;
887 return (new_name); 881 return new_name;
888 } 882 }
889 883
890 DEFUN ("keymap-name", Fkeymap_name, 1, 1, 0, /* 884 DEFUN ("keymap-name", Fkeymap_name, 1, 1, 0, /*
891 Return the `name' of KEYMAP. 885 Return the `name' of KEYMAP.
892 The name is only a debugging convenience; it is not used except 886 The name is only a debugging convenience; it is not used except
894 */ 888 */
895 (keymap)) 889 (keymap))
896 { 890 {
897 keymap = get_keymap (keymap, 1, 1); 891 keymap = get_keymap (keymap, 1, 1);
898 892
899 return (XKEYMAP (keymap)->name); 893 return XKEYMAP (keymap)->name;
900 } 894 }
901 895
902 DEFUN ("set-keymap-prompt", Fset_keymap_prompt, 2, 2, 0, /* 896 DEFUN ("set-keymap-prompt", Fset_keymap_prompt, 2, 2, 0, /*
903 Sets the `prompt' of KEYMAP to string NEW-PROMPT, or `nil' 897 Sets the `prompt' of KEYMAP to string NEW-PROMPT, or `nil'
904 if no prompt is desired. The prompt is shown in the echo-area 898 if no prompt is desired. The prompt is shown in the echo-area
910 904
911 if (!NILP (new_prompt)) 905 if (!NILP (new_prompt))
912 CHECK_STRING (new_prompt); 906 CHECK_STRING (new_prompt);
913 907
914 XKEYMAP (keymap)->prompt = new_prompt; 908 XKEYMAP (keymap)->prompt = new_prompt;
915 return (new_prompt); 909 return new_prompt;
916 } 910 }
917 911
918 static Lisp_Object 912 static Lisp_Object
919 keymap_prompt_mapper (Lisp_Object keymap, void *arg) 913 keymap_prompt_mapper (Lisp_Object keymap, void *arg)
920 { 914 {
921 return (XKEYMAP (keymap)->prompt); 915 return XKEYMAP (keymap)->prompt;
922 } 916 }
923 917
924 918
925 DEFUN ("keymap-prompt", Fkeymap_prompt, 1, 2, 0, /* 919 DEFUN ("keymap-prompt", Fkeymap_prompt, 1, 2, 0, /*
926 Return the `prompt' of the given keymap. 920 Return the `prompt' of the given keymap.
933 Lisp_Object prompt; 927 Lisp_Object prompt;
934 928
935 keymap = get_keymap (keymap, 1, 1); 929 keymap = get_keymap (keymap, 1, 1);
936 prompt = XKEYMAP (keymap)->prompt; 930 prompt = XKEYMAP (keymap)->prompt;
937 if (!NILP (prompt) || NILP (use_inherited)) 931 if (!NILP (prompt) || NILP (use_inherited))
938 return (prompt); 932 return prompt;
939 else 933 else
940 return (traverse_keymaps (keymap, Qnil, 934 return traverse_keymaps (keymap, Qnil, keymap_prompt_mapper, 0);
941 keymap_prompt_mapper, 0));
942 } 935 }
943 936
944 DEFUN ("set-keymap-default-binding", Fset_keymap_default_binding, 2, 2, 0, /* 937 DEFUN ("set-keymap-default-binding", Fset_keymap_default_binding, 2, 2, 0, /*
945 Sets the default binding of KEYMAP to COMMAND, or `nil' 938 Sets the default binding of KEYMAP to COMMAND, or `nil'
946 if no default is desired. The default-binding is returned when 939 if no default is desired. The default-binding is returned when
952 { 945 {
953 /* This function can GC */ 946 /* This function can GC */
954 keymap = get_keymap (keymap, 1, 1); 947 keymap = get_keymap (keymap, 1, 1);
955 948
956 XKEYMAP (keymap)->default_binding = command; 949 XKEYMAP (keymap)->default_binding = command;
957 return (command); 950 return command;
958 } 951 }
959 952
960 DEFUN ("keymap-default-binding", Fkeymap_default_binding, 1, 1, 0, /* 953 DEFUN ("keymap-default-binding", Fkeymap_default_binding, 1, 1, 0, /*
961 Return the default binding of KEYMAP, or `nil' if it has none. 954 Return the default binding of KEYMAP, or `nil' if it has none.
962 The default-binding is returned when no other binding for a key-sequence 955 The default-binding is returned when no other binding for a key-sequence
966 */ 959 */
967 (keymap)) 960 (keymap))
968 { 961 {
969 /* This function can GC */ 962 /* This function can GC */
970 keymap = get_keymap (keymap, 1, 1); 963 keymap = get_keymap (keymap, 1, 1);
971 return (XKEYMAP (keymap)->default_binding); 964 return XKEYMAP (keymap)->default_binding;
972 } 965 }
973 966
974 DEFUN ("keymapp", Fkeymapp, 1, 1, 0, /* 967 DEFUN ("keymapp", Fkeymapp, 1, 1, 0, /*
975 Return t if ARG is a keymap object. 968 Return t if ARG is a keymap object.
976 The keymap may be autoloaded first if necessary. 969 The keymap may be autoloaded first if necessary.
977 */ 970 */
978 (object)) 971 (object))
979 { 972 {
980 /* This function can GC */ 973 /* This function can GC */
981 Lisp_Object tem = get_keymap (object, 0, 1); 974 Lisp_Object tem = get_keymap (object, 0, 1);
982 return ((KEYMAPP (tem)) ? Qt : Qnil); 975 return KEYMAPP (tem) ? Qt : Qnil;
983 } 976 }
984 977
985 /* Check that OBJECT is a keymap (after dereferencing through any 978 /* Check that OBJECT is a keymap (after dereferencing through any
986 symbols). If it is, return it. 979 symbols). If it is, return it.
987 980
1033 /* This function can GC */ 1026 /* This function can GC */
1034 Lisp_Object map; 1027 Lisp_Object map;
1035 1028
1036 tail_recurse: 1029 tail_recurse:
1037 if (!CONSP (object)) 1030 if (!CONSP (object))
1038 return (object); 1031 return object;
1039 1032
1040 { 1033 {
1041 struct gcpro gcpro1; 1034 struct gcpro gcpro1;
1042 GCPRO1 (object); 1035 GCPRO1 (object);
1043 map = XCAR (object); 1036 map = XCAR (object);
1058 indirection = event.event.key; 1051 indirection = event.event.key;
1059 } 1052 }
1060 else if (CONSP (idx)) 1053 else if (CONSP (idx))
1061 { 1054 {
1062 if (!INTP (XCDR (idx))) 1055 if (!INTP (XCDR (idx)))
1063 return (Qnil); 1056 return Qnil;
1064 indirection.keysym = XCAR (idx); 1057 indirection.keysym = XCAR (idx);
1065 indirection.modifiers = XINT (XCDR (idx)); 1058 indirection.modifiers = XINT (XCDR (idx));
1066 } 1059 }
1067 else if (SYMBOLP (idx)) 1060 else if (SYMBOLP (idx))
1068 { 1061 {
1070 indirection.modifiers = 0; 1063 indirection.modifiers = 0;
1071 } 1064 }
1072 else 1065 else
1073 { 1066 {
1074 /* Random junk */ 1067 /* Random junk */
1075 return (Qnil); 1068 return Qnil;
1076 } 1069 }
1077 return (raw_lookup_key (map, &indirection, 1, 0, 1070 return raw_lookup_key (map, &indirection, 1, 0, accept_default);
1078 accept_default));
1079 } 1071 }
1080 else if (STRINGP (XCAR (object))) 1072 else if (STRINGP (XCAR (object)))
1081 { 1073 {
1082 /* If the keymap contents looks like (STRING . DEFN), 1074 /* If the keymap contents looks like (STRING . DEFN),
1083 use DEFN. 1075 use DEFN.
1087 goto tail_recurse; 1079 goto tail_recurse;
1088 } 1080 }
1089 else 1081 else
1090 { 1082 {
1091 /* Anything else is really the value. */ 1083 /* Anything else is really the value. */
1092 return (object); 1084 return object;
1093 } 1085 }
1094 } 1086 }
1095 1087
1096 static Lisp_Object 1088 static Lisp_Object
1097 keymap_lookup_1 (Lisp_Object keymap, CONST struct key_data *key, 1089 keymap_lookup_1 (Lisp_Object keymap, CONST struct key_data *key,
1098 int accept_default) 1090 int accept_default)
1099 { 1091 {
1100 /* This function can GC */ 1092 /* This function can GC */
1101 return (get_keyelt (keymap_lookup_directly (keymap, 1093 return get_keyelt (keymap_lookup_directly (keymap,
1102 key->keysym, key->modifiers), 1094 key->keysym, key->modifiers),
1103 accept_default)); 1095 accept_default);
1104 } 1096 }
1105 1097
1106 1098
1107 /************************************************************************/ 1099 /************************************************************************/
1108 /* Copying keymaps */ 1100 /* Copying keymaps */
1229 fullness--; /* don't count bucky maps */ 1221 fullness--; /* don't count bucky maps */
1230 fullness += keymap_fullness (sub_map); 1222 fullness += keymap_fullness (sub_map);
1231 } 1223 }
1232 } 1224 }
1233 UNGCPRO; 1225 UNGCPRO;
1234 return (fullness); 1226 return fullness;
1235 } 1227 }
1236 1228
1237 DEFUN ("keymap-fullness", Fkeymap_fullness, 1, 1, 0, /* 1229 DEFUN ("keymap-fullness", Fkeymap_fullness, 1, 1, 0, /*
1238 Return the number of bindings in the keymap. 1230 Return the number of bindings in the keymap.
1239 */ 1231 */
1240 (keymap)) 1232 (keymap))
1241 { 1233 {
1242 /* This function can GC */ 1234 /* This function can GC */
1243 return (make_int (keymap_fullness 1235 return make_int (keymap_fullness (get_keymap (keymap, 1, 1)));
1244 (get_keymap (keymap, 1, 1))));
1245 } 1236 }
1246 1237
1247 1238
1248 /************************************************************************/ 1239 /************************************************************************/
1249 /* Defining keys in keymaps */ 1240 /* Defining keys in keymaps */
1695 new_keys = Fsubstring (keys, Qzero, make_int (indx)); 1686 new_keys = Fsubstring (keys, Qzero, make_int (indx));
1696 else if (VECTORP (keys)) 1687 else if (VECTORP (keys))
1697 { 1688 {
1698 new_keys = make_vector (indx, Qnil); 1689 new_keys = make_vector (indx, Qnil);
1699 for (i = 0; i < indx; i++) 1690 for (i = 0; i < indx; i++)
1700 vector_data (XVECTOR (new_keys)) [i] = 1691 XVECTOR_DATA (new_keys) [i] = XVECTOR_DATA (keys) [i];
1701 vector_data (XVECTOR (keys)) [i];
1702 } 1692 }
1703 else 1693 else
1704 abort (); 1694 abort ();
1705 if (EQ (keys, new_keys)) 1695 if (EQ (keys, new_keys))
1706 sprintf (buf, GETTEXT ("can't bind %s: %s has a non-keymap binding"), 1696 sprintf (buf, GETTEXT ("can't bind %s: %s has a non-keymap binding"),
1820 (keymap, keys, def)) 1810 (keymap, keys, def))
1821 { 1811 {
1822 /* This function can GC */ 1812 /* This function can GC */
1823 int idx; 1813 int idx;
1824 int metized = 0; 1814 int metized = 0;
1825 int size; 1815 int len;
1826 int ascii_hack; 1816 int ascii_hack;
1827 struct gcpro gcpro1, gcpro2, gcpro3; 1817 struct gcpro gcpro1, gcpro2, gcpro3;
1828 1818
1829 if (VECTORP (keys)) 1819 if (VECTORP (keys))
1830 size = vector_length (XVECTOR (keys)); 1820 len = XVECTOR_LENGTH (keys);
1831 else if (STRINGP (keys)) 1821 else if (STRINGP (keys))
1832 size = string_char_length (XSTRING (keys)); 1822 len = string_char_length (XSTRING (keys));
1833 else if (CHAR_OR_CHAR_INTP (keys) || SYMBOLP (keys) || CONSP (keys)) 1823 else if (CHAR_OR_CHAR_INTP (keys) || SYMBOLP (keys) || CONSP (keys))
1834 { 1824 {
1835 if (!CONSP (keys)) keys = list1 (keys); 1825 if (!CONSP (keys)) keys = list1 (keys);
1836 size = 1; 1826 len = 1;
1837 keys = make_vector (1, keys); /* this is kinda sleazy. */ 1827 keys = make_vector (1, keys); /* this is kinda sleazy. */
1838 } 1828 }
1839 else 1829 else
1840 { 1830 {
1841 keys = wrong_type_argument (Qsequencep, keys); 1831 keys = wrong_type_argument (Qsequencep, keys);
1842 size = XINT (Flength (keys)); 1832 len = XINT (Flength (keys));
1843 } 1833 }
1844 if (size == 0) 1834 if (len == 0)
1845 return (Qnil); 1835 return Qnil;
1846 1836
1847 GCPRO3 (keymap, keys, def); 1837 GCPRO3 (keymap, keys, def);
1848 1838
1849 /* ASCII grunge. 1839 /* ASCII grunge.
1850 When the user defines a key which, in a strictly ASCII world, would be 1840 When the user defines a key which, in a strictly ASCII world, would be
1867 struct key_data raw_key2; 1857 struct key_data raw_key2;
1868 1858
1869 if (STRINGP (keys)) 1859 if (STRINGP (keys))
1870 c = make_char (string_char (XSTRING (keys), idx)); 1860 c = make_char (string_char (XSTRING (keys), idx));
1871 else 1861 else
1872 c = vector_data (XVECTOR (keys)) [idx]; 1862 c = XVECTOR_DATA (keys) [idx];
1873 1863
1874 define_key_parser (c, &raw_key1); 1864 define_key_parser (c, &raw_key1);
1875 1865
1876 if (!metized && ascii_hack && meta_prefix_char_p (&raw_key1)) 1866 if (!metized && ascii_hack && meta_prefix_char_p (&raw_key1))
1877 { 1867 {
1878 if (idx == (size - 1)) 1868 if (idx == (len - 1))
1879 { 1869 {
1880 /* This is a hack to prevent a binding for the meta-prefix-char 1870 /* This is a hack to prevent a binding for the meta-prefix-char
1881 from being made in a map which already has a non-empty "meta" 1871 from being made in a map which already has a non-empty "meta"
1882 submap. That is, we can't let both "escape" and "meta" have 1872 submap. That is, we can't let both "escape" and "meta" have
1883 a binding in the same keymap. This implies that the idiom 1873 a binding in the same keymap. This implies that the idiom
1933 /* This crap is to make sure that someone doesn't bind something like 1923 /* This crap is to make sure that someone doesn't bind something like
1934 "C-x M-a" while "C-x ESC" has a non-keymap binding. */ 1924 "C-x M-a" while "C-x ESC" has a non-keymap binding. */
1935 if (raw_key1.modifiers & MOD_META) 1925 if (raw_key1.modifiers & MOD_META)
1936 ensure_meta_prefix_char_keymapp (keys, idx, keymap); 1926 ensure_meta_prefix_char_keymapp (keys, idx, keymap);
1937 1927
1938 if (++idx == size) 1928 if (++idx == len)
1939 { 1929 {
1940 keymap_store (keymap, &raw_key1, def); 1930 keymap_store (keymap, &raw_key1, def);
1941 if (ascii_hack && !NILP (raw_key2.keysym)) 1931 if (ascii_hack && !NILP (raw_key2.keysym))
1942 keymap_store (keymap, &raw_key2, def); 1932 keymap_store (keymap, &raw_key2, def);
1943 UNGCPRO; 1933 UNGCPRO;
2002 c.raw_keys = raw_keys; 1992 c.raw_keys = raw_keys;
2003 c.raw_keys_count = raw_keys_count; 1993 c.raw_keys_count = raw_keys_count;
2004 c.keys_so_far = keys_so_far; 1994 c.keys_so_far = keys_so_far;
2005 c.accept_default = accept_default; 1995 c.accept_default = accept_default;
2006 1996
2007 return (traverse_keymaps (keymap, Qnil, raw_lookup_key_mapper, 1997 return traverse_keymaps (keymap, Qnil, raw_lookup_key_mapper, &c);
2008 &c));
2009 } 1998 }
2010 1999
2011 static Lisp_Object 2000 static Lisp_Object
2012 raw_lookup_key_mapper (Lisp_Object k, void *arg) 2001 raw_lookup_key_mapper (Lisp_Object k, void *arg)
2013 { 2002 {
2088 } 2077 }
2089 } 2078 }
2090 } 2079 }
2091 if (accept_default && NILP (cmd)) 2080 if (accept_default && NILP (cmd))
2092 cmd = XKEYMAP (k)->default_binding; 2081 cmd = XKEYMAP (k)->default_binding;
2093 return (cmd); 2082 return cmd;
2094 } 2083 }
2095 2084
2096 /* Value is number if `keys' is too long; NIL if valid but has no definition.*/ 2085 /* Value is number if `keys' is too long; NIL if valid but has no definition.*/
2097 /* Caller should gc-protect arguments */ 2086 /* Caller should gc-protect arguments */
2098 static Lisp_Object 2087 static Lisp_Object
2114 2103
2115 for (i = 0; i < nkeys; i++) 2104 for (i = 0; i < nkeys; i++)
2116 { 2105 {
2117 define_key_parser (keys[i], &(raw_keys[i])); 2106 define_key_parser (keys[i], &(raw_keys[i]));
2118 } 2107 }
2119 return (raw_lookup_key (keymap, raw_keys, nkeys, 0, 2108 return raw_lookup_key (keymap, raw_keys, nkeys, 0, accept_default);
2120 accept_default));
2121 } 2109 }
2122 2110
2123 static Lisp_Object 2111 static Lisp_Object
2124 lookup_events (Lisp_Object event_head, int nmaps, Lisp_Object keymaps[], 2112 lookup_events (Lisp_Object event_head, int nmaps, Lisp_Object keymaps[],
2125 int accept_default) 2113 int accept_default)
2162 } 2150 }
2163 else if (!NILP (tem)) 2151 else if (!NILP (tem))
2164 break; 2152 break;
2165 } 2153 }
2166 UNGCPRO; 2154 UNGCPRO;
2167 return (tem); 2155 return tem;
2168 } 2156 }
2169 2157
2170 DEFUN ("lookup-key", Flookup_key, 2, 3, 0, /* 2158 DEFUN ("lookup-key", Flookup_key, 2, 3, 0, /*
2171 In keymap KEYMAP, look up key-sequence KEYS. Return the definition. 2159 In keymap KEYMAP, look up key-sequence KEYS. Return the definition.
2172 Nil is returned if KEYS is unbound. See documentation of `define-key' 2160 Nil is returned if KEYS is unbound. See documentation of `define-key'
2180 { 2168 {
2181 /* This function can GC */ 2169 /* This function can GC */
2182 if (VECTORP (keys)) 2170 if (VECTORP (keys))
2183 { 2171 {
2184 return lookup_keys (keymap, 2172 return lookup_keys (keymap,
2185 vector_length (XVECTOR (keys)), 2173 XVECTOR_LENGTH (keys),
2186 vector_data (XVECTOR (keys)), 2174 XVECTOR_DATA (keys),
2187 !NILP (accept_default)); 2175 !NILP (accept_default));
2188 } 2176 }
2189 else if (SYMBOLP (keys) || CHAR_OR_CHAR_INTP (keys) || CONSP (keys)) 2177 else if (SYMBOLP (keys) || CHAR_OR_CHAR_INTP (keys) || CONSP (keys))
2190 { 2178 {
2191 return lookup_keys (keymap, 1, &keys, 2179 return lookup_keys (keymap, 1, &keys,
2208 for (i = 0; i < length; i++) 2196 for (i = 0; i < length; i++)
2209 { 2197 {
2210 Emchar n = string_char (XSTRING (keys), i); 2198 Emchar n = string_char (XSTRING (keys), i);
2211 define_key_parser (make_char (n), &(raw_keys[i])); 2199 define_key_parser (make_char (n), &(raw_keys[i]));
2212 } 2200 }
2213 return (raw_lookup_key (keymap, raw_keys, length, 0, 2201 return raw_lookup_key (keymap, raw_keys, length, 0,
2214 !NILP (accept_default))); 2202 !NILP (accept_default));
2215 } 2203 }
2216 } 2204 }
2217 2205
2218 /* Given a key sequence, returns a list of keymaps to search for bindings. 2206 /* Given a key sequence, returns a list of keymaps to search for bindings.
2219 Does all manner of semi-hairy heuristics, like looking in the current 2207 Does all manner of semi-hairy heuristics, like looking in the current
2276 2264
2277 if (EVENTP (keys)) 2265 if (EVENTP (keys))
2278 terminal = event_chain_tail (keys); 2266 terminal = event_chain_tail (keys);
2279 else if (VECTORP (keys)) 2267 else if (VECTORP (keys))
2280 { 2268 {
2281 int len = vector_length (XVECTOR (keys)); 2269 int len = XVECTOR_LENGTH (keys);
2282 if (len > 0) 2270 if (len > 0)
2283 terminal = vector_data (XVECTOR (keys))[len - 1]; 2271 terminal = XVECTOR_DATA (keys)[len - 1];
2284 } 2272 }
2285 2273
2286 if (EVENTP (terminal)) 2274 if (EVENTP (terminal))
2287 { 2275 {
2288 CHECK_LIVE_EVENT (terminal); 2276 CHECK_LIVE_EVENT (terminal);
2402 if (nmaps >= max_maps && max_maps > 0) 2390 if (nmaps >= max_maps && max_maps > 0)
2403 maps[max_maps - 1] = Vcurrent_global_map; 2391 maps[max_maps - 1] = Vcurrent_global_map;
2404 else 2392 else
2405 maps[nmaps] = Vcurrent_global_map; 2393 maps[nmaps] = Vcurrent_global_map;
2406 UNGCPRO; 2394 UNGCPRO;
2407 return (nmaps + 1); 2395 return nmaps + 1;
2408 } 2396 }
2409 } 2397 }
2410 2398
2411 /* Returns a set of keymaps extracted from the extents at POS in 2399 /* Returns a set of keymaps extracted from the extents at POS in
2412 BUFFER_OR_STRING. The GLYPH arg, if specified, is one more extent 2400 BUFFER_OR_STRING. The GLYPH arg, if specified, is one more extent
2463 { 2451 {
2464 Lisp_Object val = symbol_value_in_buffer (sym, buffer); 2452 Lisp_Object val = symbol_value_in_buffer (sym, buffer);
2465 if (!NILP (val) && !UNBOUNDP (val)) 2453 if (!NILP (val) && !UNBOUNDP (val))
2466 { 2454 {
2467 Lisp_Object map = get_keymap (XCDR (assoc), 0, 1); 2455 Lisp_Object map = get_keymap (XCDR (assoc), 0, 1);
2468 return (map); 2456 return map;
2469 } 2457 }
2470 } 2458 }
2471 } 2459 }
2472 return (Qnil); 2460 return Qnil;
2473 } 2461 }
2474 2462
2475 static void 2463 static void
2476 get_relevant_minor_maps (Lisp_Object buffer, struct relevant_maps *closure) 2464 get_relevant_minor_maps (Lisp_Object buffer, struct relevant_maps *closure)
2477 { 2465 {
2515 { 2503 {
2516 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); 2504 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
2517 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish); 2505 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish);
2518 } 2506 }
2519 UNGCPRO; 2507 UNGCPRO;
2520 return (Flist (nmaps, gubbish)); 2508 return Flist (nmaps, gubbish);
2521 } 2509 }
2522 2510
2523 DEFUN ("key-binding", Fkey_binding, 1, 2, 0, /* 2511 DEFUN ("key-binding", Fkey_binding, 1, 2, 0, /*
2524 Return the binding for command KEYS in current keymaps. 2512 Return the binding for command KEYS in current keymaps.
2525 KEYS is a string, a vector of events, or a vector of key-description lists 2513 KEYS is a string, a vector of events, or a vector of key-description lists
2561 nmaps = get_relevant_keymaps (keys, countof (maps), maps); 2549 nmaps = get_relevant_keymaps (keys, countof (maps), maps);
2562 2550
2563 UNGCPRO; 2551 UNGCPRO;
2564 2552
2565 if (EVENTP (keys)) /* unadvertised "feature" for the future */ 2553 if (EVENTP (keys)) /* unadvertised "feature" for the future */
2566 return (lookup_events (keys, nmaps, maps, 2554 return lookup_events (keys, nmaps, maps, !NILP (accept_default));
2567 !NILP (accept_default)));
2568 2555
2569 for (i = 0; i < nmaps; i++) 2556 for (i = 0; i < nmaps; i++)
2570 { 2557 {
2571 Lisp_Object tem = Flookup_key (maps[i], keys, 2558 Lisp_Object tem = Flookup_key (maps[i], keys,
2572 accept_default); 2559 accept_default);
2573 if (INTP (tem)) 2560 if (INTP (tem))
2574 { 2561 {
2575 /* Too long in some local map means don't look at global map */ 2562 /* Too long in some local map means don't look at global map */
2576 return (Qnil); 2563 return Qnil;
2577 } 2564 }
2578 else if (!NILP (tem)) 2565 else if (!NILP (tem))
2579 return (tem); 2566 return tem;
2580 } 2567 }
2581 return (Qnil); 2568 return Qnil;
2582 } 2569 }
2583 2570
2584 static Lisp_Object 2571 static Lisp_Object
2585 process_event_binding_result (Lisp_Object result) 2572 process_event_binding_result (Lisp_Object result)
2586 { 2573 {
2625 assert (EVENTP (event0)); 2612 assert (EVENTP (event0));
2626 2613
2627 nmaps = get_relevant_keymaps (event0, countof (maps), maps); 2614 nmaps = get_relevant_keymaps (event0, countof (maps), maps);
2628 if (nmaps > countof (maps)) 2615 if (nmaps > countof (maps))
2629 nmaps = countof (maps); 2616 nmaps = countof (maps);
2630 return (process_event_binding_result 2617 return process_event_binding_result (lookup_events (event0, nmaps, maps,
2631 (lookup_events (event0, nmaps, maps, accept_default))); 2618 accept_default));
2632 } 2619 }
2633 2620
2634 /* Attempts to find a function key mapping corresponding to the 2621 /* Attempts to find a function key mapping corresponding to the
2635 event-sequence whose head is event0 (sequence is threaded through 2622 event-sequence whose head is event0 (sequence is threaded through
2636 event_next). The return value will be the same as for event_binding(). */ 2623 event_next). The return value will be the same as for event_binding(). */
2703 DEFUN ("current-global-map", Fcurrent_global_map, 0, 0, 0, /* 2690 DEFUN ("current-global-map", Fcurrent_global_map, 0, 0, 0, /*
2704 Return the current global keymap. 2691 Return the current global keymap.
2705 */ 2692 */
2706 ()) 2693 ())
2707 { 2694 {
2708 return (Vcurrent_global_map); 2695 return Vcurrent_global_map;
2709 } 2696 }
2710 2697
2711 2698
2712 /************************************************************************/ 2699 /************************************************************************/
2713 /* Mapping over keymap elements */ 2700 /* Mapping over keymap elements */
2833 } 2820 }
2834 } 2821 }
2835 2822
2836 /* all symbols (non-ASCIIs) come after characters (ASCIIs) */ 2823 /* all symbols (non-ASCIIs) come after characters (ASCIIs) */
2837 if (XTYPE (obj1) != XTYPE (obj2)) 2824 if (XTYPE (obj1) != XTYPE (obj2))
2838 return (SYMBOLP (obj2) ? 1 : -1); 2825 return SYMBOLP (obj2) ? 1 : -1;
2839 2826
2840 if (! bit1 && CHARP (obj1)) /* they're both ASCII */ 2827 if (! bit1 && CHARP (obj1)) /* they're both ASCII */
2841 { 2828 {
2842 int o1 = XCHAR (obj1); 2829 int o1 = XCHAR (obj1);
2843 int o2 = XCHAR (obj2); 2830 int o2 = XCHAR (obj2);
2844 if (o1 == o2 && /* If one started out as a symbol and the */ 2831 if (o1 == o2 && /* If one started out as a symbol and the */
2845 sym1_p != sym2_p) /* other didn't, the symbol comes last. */ 2832 sym1_p != sym2_p) /* other didn't, the symbol comes last. */
2846 return (sym2_p ? 1 : -1); 2833 return sym2_p ? 1 : -1;
2847 2834
2848 return ((o1 < o2) ? 1 : -1); /* else just compare them */ 2835 return o1 < o2 ? 1 : -1; /* else just compare them */
2849 } 2836 }
2850 2837
2851 /* else they're both symbols. If they're both buckys, then order them. */ 2838 /* else they're both symbols. If they're both buckys, then order them. */
2852 if (bit1 && bit2) 2839 if (bit1 && bit2)
2853 return ((bit1 < bit2) ? 1 : -1); 2840 return bit1 < bit2 ? 1 : -1;
2854 2841
2855 /* if only one is a bucky, then it comes later */ 2842 /* if only one is a bucky, then it comes later */
2856 if (bit1 || bit2) 2843 if (bit1 || bit2)
2857 return (bit2 ? 1 : -1); 2844 return bit2 ? 1 : -1;
2858 2845
2859 /* otherwise, string-sort them. */ 2846 /* otherwise, string-sort them. */
2860 { 2847 {
2861 char *s1 = (char *) string_data (XSYMBOL (obj1)->name); 2848 char *s1 = (char *) string_data (XSYMBOL (obj1)->name);
2862 char *s2 = (char *) string_data (XSYMBOL (obj2)->name); 2849 char *s2 = (char *) string_data (XSYMBOL (obj2)->name);
2863 return (
2864 #ifdef I18N2 2850 #ifdef I18N2
2865 (0 > strcoll (s1, s2)) 2851 return 0 > strcoll (s1, s2) ? 1 : -1;
2866 #else 2852 #else
2867 (0 > strcmp (s1, s2)) 2853 return 0 > strcmp (s1, s2) ? 1 : -1;
2868 #endif 2854 #endif
2869 ? 1 : -1);
2870 } 2855 }
2871 } 2856 }
2872 2857
2873 2858
2874 /* used by map_keymap() */ 2859 /* used by map_keymap() */
3029 { 3014 {
3030 Lisp_Object thisseq = Fcar (Fcar (closure->tail)); 3015 Lisp_Object thisseq = Fcar (Fcar (closure->tail));
3031 Lisp_Object cmd = get_keyelt (contents, 1); 3016 Lisp_Object cmd = get_keyelt (contents, 1);
3032 Lisp_Object vec; 3017 Lisp_Object vec;
3033 int j; 3018 int j;
3019 int len;
3034 struct key_data key; 3020 struct key_data key;
3035 key.keysym = keysym; 3021 key.keysym = keysym;
3036 key.modifiers = modifiers; 3022 key.modifiers = modifiers;
3037 3023
3038 if (NILP (cmd)) 3024 if (NILP (cmd))
3039 abort (); 3025 abort ();
3040 cmd = get_keymap (cmd, 0, 1); 3026 cmd = get_keymap (cmd, 0, 1);
3041 if (!KEYMAPP (cmd)) 3027 if (!KEYMAPP (cmd))
3042 abort (); 3028 abort ();
3043 3029
3044 vec = make_vector (vector_length (XVECTOR (thisseq)) + 1, Qnil); 3030 vec = make_vector (XVECTOR_LENGTH (thisseq) + 1, Qnil);
3045 for (j = 0; j < vector_length (XVECTOR (thisseq)); j++) 3031 len = XVECTOR_LENGTH (thisseq);
3046 vector_data (XVECTOR (vec)) [j] = vector_data (XVECTOR (thisseq)) [j]; 3032 for (j = 0; j < len; j++)
3047 vector_data (XVECTOR (vec)) [j] = make_key_description (&key, 1); 3033 XVECTOR_DATA (vec) [j] = XVECTOR_DATA (thisseq) [j];
3034 XVECTOR_DATA (vec) [j] = make_key_description (&key, 1);
3048 3035
3049 nconc2 (closure->tail, list1 (Fcons (vec, cmd))); 3036 nconc2 (closure->tail, list1 (Fcons (vec, cmd)));
3050 } 3037 }
3051 } 3038 }
3052 3039
3063 accessible_keymaps_mapper_1 (XCAR (XCAR (submaps)), 3050 accessible_keymaps_mapper_1 (XCAR (XCAR (submaps)),
3064 XCDR (XCAR (submaps)), 3051 XCDR (XCAR (submaps)),
3065 0, 3052 0,
3066 closure); 3053 closure);
3067 } 3054 }
3068 return (Qnil); 3055 return Qnil;
3069 } 3056 }
3070 3057
3071 3058
3072 DEFUN ("accessible-keymaps", Faccessible_keymaps, 1, 2, 0, /* 3059 DEFUN ("accessible-keymaps", Faccessible_keymaps, 1, 2, 0, /*
3073 Find all keymaps accessible via prefix characters from STARTMAP. 3060 Find all keymaps accessible via prefix characters from STARTMAP.
3112 NGCPRO1 (p); 3099 NGCPRO1 (p);
3113 for (iii = 0; iii < len; iii++) 3100 for (iii = 0; iii < len; iii++)
3114 { 3101 {
3115 struct key_data key; 3102 struct key_data key;
3116 define_key_parser (Faref (prefix, make_int (iii)), &key); 3103 define_key_parser (Faref (prefix, make_int (iii)), &key);
3117 vector_data (XVECTOR (p))[iii] = make_key_description (&key, 1); 3104 XVECTOR_DATA (p)[iii] = make_key_description (&key, 1);
3118 } 3105 }
3119 NUNGCPRO; 3106 NUNGCPRO;
3120 prefix = p; 3107 prefix = p;
3121 } 3108 }
3122 3109
3135 traverse_keymaps (thismap, Qnil, 3122 traverse_keymaps (thismap, Qnil,
3136 accessible_keymaps_keymap_mapper, &c); 3123 accessible_keymaps_keymap_mapper, &c);
3137 } 3124 }
3138 RETURN: 3125 RETURN:
3139 UNGCPRO; 3126 UNGCPRO;
3140 return (accessible_keymaps); 3127 return accessible_keymaps;
3141 } 3128 }
3142 3129
3143 3130
3144 3131
3145 /************************************************************************/ 3132 /************************************************************************/
3169 for (i = 0; i < size; i++) 3156 for (i = 0; i < size; i++)
3170 { 3157 {
3171 Lisp_Object s2 = Fsingle_key_description 3158 Lisp_Object s2 = Fsingle_key_description
3172 (((STRINGP (keys)) 3159 (((STRINGP (keys))
3173 ? make_char (string_char (XSTRING (keys), i)) 3160 ? make_char (string_char (XSTRING (keys), i))
3174 : vector_data (XVECTOR (keys))[i])); 3161 : XVECTOR_DATA (keys)[i]));
3175 3162
3176 if (i == 0) 3163 if (i == 0)
3177 string = s2; 3164 string = s2;
3178 else 3165 else
3179 { 3166 {
3180 /* if (NILP (sep)) Lisp_Object sep = build_string (" ") */; 3167 /* if (NILP (sep)) Lisp_Object sep = build_string (" ") */;
3181 string = concat2 (string, concat2 (Vsingle_space_string, s2)); 3168 string = concat2 (string, concat2 (Vsingle_space_string, s2));
3182 } 3169 }
3183 } 3170 }
3184 return (string); 3171 return string;
3185 } 3172 }
3186 return Fkey_description (wrong_type_argument (Qsequencep, keys)); 3173 return Fkey_description (wrong_type_argument (Qsequencep, keys));
3187 } 3174 }
3188 3175
3189 DEFUN ("single-key-description", Fsingle_key_description, 1, 1, 0, /* 3176 DEFUN ("single-key-description", Fsingle_key_description, 1, 1, 0, /*
3209 XCONSOLE (Vselected_console), 0); 3196 XCONSOLE (Vselected_console), 0);
3210 format_event_object (buf, &event, 1); 3197 format_event_object (buf, &event, 1);
3211 } 3198 }
3212 else 3199 else
3213 format_event_object (buf, XEVENT (key), 1); 3200 format_event_object (buf, XEVENT (key), 1);
3214 return (build_string (buf)); 3201 return build_string (buf);
3215 } 3202 }
3216 3203
3217 if (CONSP (key)) 3204 if (CONSP (key))
3218 { 3205 {
3219 char buf[255]; 3206 char buf[255];
3440 static Lisp_Object 3427 static Lisp_Object
3441 raw_keys_to_keys (struct key_data *keys, int count) 3428 raw_keys_to_keys (struct key_data *keys, int count)
3442 { 3429 {
3443 Lisp_Object result = make_vector (count, Qnil); 3430 Lisp_Object result = make_vector (count, Qnil);
3444 while (count--) 3431 while (count--)
3445 vector_data (XVECTOR (result)) [count] = 3432 XVECTOR_DATA (result) [count] = make_key_description (&(keys[count]), 1);
3446 make_key_description (&(keys[count]), 1); 3433 return result;
3447 return (result);
3448 } 3434 }
3449 3435
3450 3436
3451 static void 3437 static void
3452 format_raw_keys (struct key_data *keys, int count, char *buf) 3438 format_raw_keys (struct key_data *keys, int count, char *buf)
3556 /* OK, the key is for real */ 3542 /* OK, the key is for real */
3557 if (target_buffer) 3543 if (target_buffer)
3558 { 3544 {
3559 if (!firstonly) abort (); 3545 if (!firstonly) abort ();
3560 format_raw_keys (so_far, keys_count + 1, target_buffer); 3546 format_raw_keys (so_far, keys_count + 1, target_buffer);
3561 return (make_int (1)); 3547 return make_int (1);
3562 } 3548 }
3563 else if (firstonly) 3549 else if (firstonly)
3564 return raw_keys_to_keys (so_far, keys_count + 1); 3550 return raw_keys_to_keys (so_far, keys_count + 1);
3565 else 3551 else
3566 result = Fcons (raw_keys_to_keys (so_far, keys_count + 1), 3552 result = Fcons (raw_keys_to_keys (so_far, keys_count + 1),
3651 c->modifiers_so_far = modifiers_so_far; 3637 c->modifiers_so_far = modifiers_so_far;
3652 3638
3653 if (!firstonly) 3639 if (!firstonly)
3654 result = nconc2 (lower, result); 3640 result = nconc2 (lower, result);
3655 else if (!NILP (lower)) 3641 else if (!NILP (lower))
3656 return (lower); 3642 return lower;
3657 } 3643 }
3658 } 3644 }
3659 return (result); 3645 return result;
3660 } 3646 }
3661 3647
3662 3648
3663 static Lisp_Object 3649 static Lisp_Object
3664 where_is_internal (Lisp_Object definition, Lisp_Object *maps, int nmaps, 3650 where_is_internal (Lisp_Object definition, Lisp_Object *maps, int nmaps,
3704 if (NILP (firstonly)) 3690 if (NILP (firstonly))
3705 result = Fnreverse (result); 3691 result = Fnreverse (result);
3706 3692
3707 if (c.keys_so_far_malloced) 3693 if (c.keys_so_far_malloced)
3708 xfree (c.keys_so_far); 3694 xfree (c.keys_so_far);
3709 return (result); 3695 return result;
3710 } 3696 }
3711 3697
3712 3698
3713 /************************************************************************/ 3699 /************************************************************************/
3714 /* Describing keymaps */ 3700 /* Describing keymaps */
3727 (map, all, shadow, prefix, mouse_only_p)) 3713 (map, all, shadow, prefix, mouse_only_p))
3728 { 3714 {
3729 /* This function can GC */ 3715 /* This function can GC */
3730 describe_map_tree (map, NILP (all), shadow, prefix, 3716 describe_map_tree (map, NILP (all), shadow, prefix,
3731 !NILP (mouse_only_p)); 3717 !NILP (mouse_only_p));
3732 return (Qnil); 3718 return Qnil;
3733 } 3719 }
3734 3720
3735 3721
3736 /* Insert a desription of the key bindings in STARTMAP, 3722 /* Insert a desription of the key bindings in STARTMAP,
3737 followed by those of all maps reachable through STARTMAP. 3723 followed by those of all maps reachable through STARTMAP.
3887 describe_map_mapper_shadow_search (Lisp_Object map, void *arg) 3873 describe_map_mapper_shadow_search (Lisp_Object map, void *arg)
3888 { 3874 {
3889 struct describe_map_shadow_closure *c = arg; 3875 struct describe_map_shadow_closure *c = arg;
3890 3876
3891 if (EQ (map, c->self)) 3877 if (EQ (map, c->self))
3892 return (Qzero); /* Not shadowed; terminate search */ 3878 return Qzero; /* Not shadowed; terminate search */
3893 else if (!NILP (keymap_lookup_directly (map, 3879 if (!NILP (keymap_lookup_directly (map,
3894 c->raw_key->keysym, 3880 c->raw_key->keysym,
3895 c->raw_key->modifiers))) 3881 c->raw_key->modifiers)))
3896 return (Qt); 3882 return Qt;
3897 else 3883 else
3898 return (Qnil); 3884 return Qnil;
3899 } 3885 }
3900 3886
3901 3887
3902 static Lisp_Object 3888 static Lisp_Object
3903 keymap_lookup_inherited_mapper (Lisp_Object km, void *arg) 3889 keymap_lookup_inherited_mapper (Lisp_Object km, void *arg)
3904 { 3890 {
3905 struct key_data *k = arg; 3891 struct key_data *k = arg;
3906 return (keymap_lookup_directly (km, k->keysym, k->modifiers)); 3892 return keymap_lookup_directly (km, k->keysym, k->modifiers);
3907 } 3893 }
3908 3894
3909 3895
3910 static void 3896 static void
3911 describe_map_mapper (CONST struct key_data *key, 3897 describe_map_mapper (CONST struct key_data *key,
3981 obj1 = XCAR (obj1); 3967 obj1 = XCAR (obj1);
3982 obj2 = XCAR (obj2); 3968 obj2 = XCAR (obj2);
3983 bit1 = XINT (XCDR (obj1)); 3969 bit1 = XINT (XCDR (obj1));
3984 bit2 = XINT (XCDR (obj2)); 3970 bit2 = XINT (XCDR (obj2));
3985 if (bit1 != bit2) 3971 if (bit1 != bit2)
3986 return ((bit1 < bit2) ? 1 : -1); 3972 return bit1 < bit2 ? 1 : -1;
3987 else 3973 else
3988 return map_keymap_sort_predicate (obj1, obj2, pred); 3974 return map_keymap_sort_predicate (obj1, obj2, pred);
3989 } 3975 }
3990 3976
3991 /* Elide 2 or more consecutive numeric keysyms bound to the same thing, 3977 /* Elide 2 or more consecutive numeric keysyms bound to the same thing,
4048 struct describe_map_closure *describe_map_closure = arg; 4034 struct describe_map_closure *describe_map_closure = arg;
4049 describe_map_closure->self = keymap; 4035 describe_map_closure->self = keymap;
4050 map_keymap (XKEYMAP (keymap)->table, 4036 map_keymap (XKEYMAP (keymap)->table,
4051 0, /* don't sort: we'll do it later */ 4037 0, /* don't sort: we'll do it later */
4052 describe_map_mapper, describe_map_closure); 4038 describe_map_mapper, describe_map_closure);
4053 return (Qnil); 4039 return Qnil;
4054 } 4040 }
4055 4041
4056 4042
4057 static void 4043 static void
4058 describe_map (Lisp_Object keymap, Lisp_Object elt_prefix, 4044 describe_map (Lisp_Object keymap, Lisp_Object elt_prefix,