Mercurial > emacs
comparison src/keymap.c @ 88155:d7ddb3e565de
sync with trunk
| author | Henrik Enberg <henrik.enberg@telia.com> |
|---|---|
| date | Mon, 16 Jan 2006 00:03:54 +0000 |
| parents | 9fe119b14379 |
| children |
comparison
equal
deleted
inserted
replaced
| 88154:8ce476d3ba36 | 88155:d7ddb3e565de |
|---|---|
| 1 /* Manipulation of keymaps | 1 /* Manipulation of keymaps |
| 2 Copyright (C) 1985, 86,87,88,93,94,95,98,99, 2000, 2001 | 2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, |
| 3 Free Software Foundation, Inc. | 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
| 4 2005 Free Software Foundation, Inc. | |
| 4 | 5 |
| 5 This file is part of GNU Emacs. | 6 This file is part of GNU Emacs. |
| 6 | 7 |
| 7 GNU Emacs is free software; you can redistribute it and/or modify | 8 GNU Emacs is free software; you can redistribute it and/or modify |
| 8 it under the terms of the GNU General Public License as published by | 9 it under the terms of the GNU General Public License as published by |
| 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 GNU General Public License for more details. | 16 GNU General Public License for more details. |
| 16 | 17 |
| 17 You should have received a copy of the GNU General Public License | 18 You should have received a copy of the GNU General Public License |
| 18 along with GNU Emacs; see the file COPYING. If not, write to | 19 along with GNU Emacs; see the file COPYING. If not, write to |
| 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 Boston, MA 02111-1307, USA. */ | 21 Boston, MA 02110-1301, USA. */ |
| 21 | 22 |
| 22 | 23 |
| 23 #include <config.h> | 24 #include <config.h> |
| 24 #include <stdio.h> | 25 #include <stdio.h> |
| 25 #include "lisp.h" | 26 #include "lisp.h" |
| 62 | 63 |
| 63 /* keymap used for minibuffers when doing completion */ | 64 /* keymap used for minibuffers when doing completion */ |
| 64 /* was MinibufLocalCompletionMap */ | 65 /* was MinibufLocalCompletionMap */ |
| 65 Lisp_Object Vminibuffer_local_completion_map; | 66 Lisp_Object Vminibuffer_local_completion_map; |
| 66 | 67 |
| 68 /* keymap used for minibuffers when doing completion in filenames */ | |
| 69 Lisp_Object Vminibuffer_local_filename_completion_map; | |
| 70 | |
| 71 /* keymap used for minibuffers when doing completion in filenames | |
| 72 with require-match*/ | |
| 73 Lisp_Object Vminibuffer_local_must_match_filename_map; | |
| 74 | |
| 67 /* keymap used for minibuffers when doing completion and require a match */ | 75 /* keymap used for minibuffers when doing completion and require a match */ |
| 68 /* was MinibufLocalMustMatchMap */ | 76 /* was MinibufLocalMustMatchMap */ |
| 69 Lisp_Object Vminibuffer_local_must_match_map; | 77 Lisp_Object Vminibuffer_local_must_match_map; |
| 70 | 78 |
| 71 /* Alist of minor mode variables and keymaps. */ | 79 /* Alist of minor mode variables and keymaps. */ |
| 118 static Lisp_Object define_as_prefix P_ ((Lisp_Object, Lisp_Object)); | 126 static Lisp_Object define_as_prefix P_ ((Lisp_Object, Lisp_Object)); |
| 119 static void describe_command P_ ((Lisp_Object, Lisp_Object)); | 127 static void describe_command P_ ((Lisp_Object, Lisp_Object)); |
| 120 static void describe_translation P_ ((Lisp_Object, Lisp_Object)); | 128 static void describe_translation P_ ((Lisp_Object, Lisp_Object)); |
| 121 static void describe_map P_ ((Lisp_Object, Lisp_Object, | 129 static void describe_map P_ ((Lisp_Object, Lisp_Object, |
| 122 void (*) P_ ((Lisp_Object, Lisp_Object)), | 130 void (*) P_ ((Lisp_Object, Lisp_Object)), |
| 123 int, Lisp_Object, Lisp_Object*, int)); | 131 int, Lisp_Object, Lisp_Object*, int, int)); |
| 132 static void describe_vector P_ ((Lisp_Object, Lisp_Object, Lisp_Object, | |
| 133 void (*) (Lisp_Object, Lisp_Object), int, | |
| 134 Lisp_Object, Lisp_Object, int *, | |
| 135 int, int, int)); | |
| 124 static void silly_event_symbol_error P_ ((Lisp_Object)); | 136 static void silly_event_symbol_error P_ ((Lisp_Object)); |
| 125 | 137 |
| 126 /* Keymap object support - constructors and predicates. */ | 138 /* Keymap object support - constructors and predicates. */ |
| 127 | 139 |
| 128 DEFUN ("make-keymap", Fmake_keymap, Smake_keymap, 0, 1, 0, | 140 DEFUN ("make-keymap", Fmake_keymap, Smake_keymap, 0, 1, 0, |
| 129 doc: /* Construct and return a new keymap, of the form (keymap CHARTABLE . ALIST). | 141 doc: /* Construct and return a new keymap, of the form (keymap CHARTABLE . ALIST). |
| 130 CHARTABLE is a char-table that holds the bindings for the ASCII | 142 CHARTABLE is a char-table that holds the bindings for all characters |
| 131 characters. ALIST is an assoc-list which holds bindings for function keys, | 143 without modifiers. All entries in it are initially nil, meaning |
| 132 mouse events, and any other things that appear in the input stream. | 144 "command undefined". ALIST is an assoc-list which holds bindings for |
| 133 All entries in it are initially nil, meaning "command undefined". | 145 function keys, mouse events, and any other things that appear in the |
| 146 input stream. Initially, ALIST is nil. | |
| 134 | 147 |
| 135 The optional arg STRING supplies a menu name for the keymap | 148 The optional arg STRING supplies a menu name for the keymap |
| 136 in case you use it as a menu with `x-popup-menu'. */) | 149 in case you use it as a menu with `x-popup-menu'. */) |
| 137 (string) | 150 (string) |
| 138 Lisp_Object string; | 151 Lisp_Object string; |
| 207 If non-nil, the prompt is shown in the echo-area | 220 If non-nil, the prompt is shown in the echo-area |
| 208 when reading a key-sequence to be looked-up in this keymap. */) | 221 when reading a key-sequence to be looked-up in this keymap. */) |
| 209 (map) | 222 (map) |
| 210 Lisp_Object map; | 223 Lisp_Object map; |
| 211 { | 224 { |
| 225 map = get_keymap (map, 0, 0); | |
| 212 while (CONSP (map)) | 226 while (CONSP (map)) |
| 213 { | 227 { |
| 214 register Lisp_Object tem; | 228 Lisp_Object tem = XCAR (map); |
| 215 tem = Fcar (map); | |
| 216 if (STRINGP (tem)) | 229 if (STRINGP (tem)) |
| 217 return tem; | 230 return tem; |
| 218 map = Fcdr (map); | 231 map = XCDR (map); |
| 219 } | 232 } |
| 220 return Qnil; | 233 return Qnil; |
| 221 } | 234 } |
| 222 | 235 |
| 223 /* Check that OBJECT is a keymap (after dereferencing through any | 236 /* Check that OBJECT is a keymap (after dereferencing through any |
| 261 if (EQ (XCAR (tem), Qkeymap)) | 274 if (EQ (XCAR (tem), Qkeymap)) |
| 262 return tem; | 275 return tem; |
| 263 | 276 |
| 264 /* Should we do an autoload? Autoload forms for keymaps have | 277 /* Should we do an autoload? Autoload forms for keymaps have |
| 265 Qkeymap as their fifth element. */ | 278 Qkeymap as their fifth element. */ |
| 266 if ((autoload || !error) && EQ (XCAR (tem), Qautoload)) | 279 if ((autoload || !error) && EQ (XCAR (tem), Qautoload) |
| 280 && SYMBOLP (object)) | |
| 267 { | 281 { |
| 268 Lisp_Object tail; | 282 Lisp_Object tail; |
| 269 | 283 |
| 270 tail = Fnth (make_number (4), tem); | 284 tail = Fnth (make_number (4), tem); |
| 271 if (EQ (tail, Qkeymap)) | 285 if (EQ (tail, Qkeymap)) |
| 337 | 351 |
| 338 /* Set the parent keymap of MAP to PARENT. */ | 352 /* Set the parent keymap of MAP to PARENT. */ |
| 339 | 353 |
| 340 DEFUN ("set-keymap-parent", Fset_keymap_parent, Sset_keymap_parent, 2, 2, 0, | 354 DEFUN ("set-keymap-parent", Fset_keymap_parent, Sset_keymap_parent, 2, 2, 0, |
| 341 doc: /* Modify KEYMAP to set its parent map to PARENT. | 355 doc: /* Modify KEYMAP to set its parent map to PARENT. |
| 342 PARENT should be nil or another keymap. */) | 356 Return PARENT. PARENT should be nil or another keymap. */) |
| 343 (keymap, parent) | 357 (keymap, parent) |
| 344 Lisp_Object keymap, parent; | 358 Lisp_Object keymap, parent; |
| 345 { | 359 { |
| 346 Lisp_Object list, prev; | 360 Lisp_Object list, prev; |
| 347 struct gcpro gcpro1, gcpro2; | 361 struct gcpro gcpro1, gcpro2; |
| 380 /* If we already have the right parent, return now | 394 /* If we already have the right parent, return now |
| 381 so that we avoid the loops below. */ | 395 so that we avoid the loops below. */ |
| 382 if (EQ (XCDR (prev), parent)) | 396 if (EQ (XCDR (prev), parent)) |
| 383 RETURN_UNGCPRO (parent); | 397 RETURN_UNGCPRO (parent); |
| 384 | 398 |
| 399 CHECK_IMPURE (prev); | |
| 385 XSETCDR (prev, parent); | 400 XSETCDR (prev, parent); |
| 386 break; | 401 break; |
| 387 } | 402 } |
| 388 prev = list; | 403 prev = list; |
| 389 } | 404 } |
| 410 | 425 |
| 411 if (CHAR_TABLE_P (XCAR (list))) | 426 if (CHAR_TABLE_P (XCAR (list))) |
| 412 { | 427 { |
| 413 Lisp_Object indices[3]; | 428 Lisp_Object indices[3]; |
| 414 | 429 |
| 415 map_char_table (fix_submap_inheritance, Qnil, XCAR (list), | 430 map_char_table (fix_submap_inheritance, Qnil, |
| 431 XCAR (list), XCAR (list), | |
| 416 keymap, 0, indices); | 432 keymap, 0, indices); |
| 417 } | 433 } |
| 418 } | 434 } |
| 419 | 435 |
| 420 RETURN_UNGCPRO (parent); | 436 RETURN_UNGCPRO (parent); |
| 520 /* See if there is a meta-map. If there's none, there is | 536 /* See if there is a meta-map. If there's none, there is |
| 521 no binding for IDX, unless a default binding exists in MAP. */ | 537 no binding for IDX, unless a default binding exists in MAP. */ |
| 522 struct gcpro gcpro1; | 538 struct gcpro gcpro1; |
| 523 Lisp_Object meta_map; | 539 Lisp_Object meta_map; |
| 524 GCPRO1 (map); | 540 GCPRO1 (map); |
| 541 /* A strange value in which Meta is set would cause | |
| 542 infinite recursion. Protect against that. */ | |
| 543 if (XINT (meta_prefix_char) & CHAR_META) | |
| 544 meta_prefix_char = make_number (27); | |
| 525 meta_map = get_keymap (access_keymap (map, meta_prefix_char, | 545 meta_map = get_keymap (access_keymap (map, meta_prefix_char, |
| 526 t_ok, noinherit, autoload), | 546 t_ok, noinherit, autoload), |
| 527 0, autoload); | 547 0, autoload); |
| 528 UNGCPRO; | 548 UNGCPRO; |
| 529 if (CONSP (meta_map)) | 549 if (CONSP (meta_map)) |
| 638 UNGCPRO; | 658 UNGCPRO; |
| 639 return get_keyelt (t_binding, autoload); | 659 return get_keyelt (t_binding, autoload); |
| 640 } | 660 } |
| 641 } | 661 } |
| 642 | 662 |
| 663 static void | |
| 664 map_keymap_item (fun, args, key, val, data) | |
| 665 map_keymap_function_t fun; | |
| 666 Lisp_Object args, key, val; | |
| 667 void *data; | |
| 668 { | |
| 669 /* We should maybe try to detect bindings shadowed by previous | |
| 670 ones and things like that. */ | |
| 671 if (EQ (val, Qt)) | |
| 672 val = Qnil; | |
| 673 (*fun) (key, val, args, data); | |
| 674 } | |
| 675 | |
| 676 static void | |
| 677 map_keymap_char_table_item (args, key, val) | |
| 678 Lisp_Object args, key, val; | |
| 679 { | |
| 680 if (!NILP (val)) | |
| 681 { | |
| 682 map_keymap_function_t fun = XSAVE_VALUE (XCAR (args))->pointer; | |
| 683 args = XCDR (args); | |
| 684 map_keymap_item (fun, XCDR (args), key, val, | |
| 685 XSAVE_VALUE (XCAR (args))->pointer); | |
| 686 } | |
| 687 } | |
| 688 | |
| 689 /* Call FUN for every binding in MAP. | |
| 690 FUN is called with 4 arguments: FUN (KEY, BINDING, ARGS, DATA). | |
| 691 AUTOLOAD if non-zero means that we can autoload keymaps if necessary. */ | |
| 692 void | |
| 693 map_keymap (map, fun, args, data, autoload) | |
| 694 map_keymap_function_t fun; | |
| 695 Lisp_Object map, args; | |
| 696 void *data; | |
| 697 int autoload; | |
| 698 { | |
| 699 struct gcpro gcpro1, gcpro2, gcpro3; | |
| 700 Lisp_Object tail; | |
| 701 | |
| 702 GCPRO3 (map, args, tail); | |
| 703 map = get_keymap (map, 1, autoload); | |
| 704 for (tail = (CONSP (map) && EQ (Qkeymap, XCAR (map))) ? XCDR (map) : map; | |
| 705 CONSP (tail) || (tail = get_keymap (tail, 0, autoload), CONSP (tail)); | |
| 706 tail = XCDR (tail)) | |
| 707 { | |
| 708 Lisp_Object binding = XCAR (tail); | |
| 709 | |
| 710 if (CONSP (binding)) | |
| 711 map_keymap_item (fun, args, XCAR (binding), XCDR (binding), data); | |
| 712 else if (VECTORP (binding)) | |
| 713 { | |
| 714 /* Loop over the char values represented in the vector. */ | |
| 715 int len = ASIZE (binding); | |
| 716 int c; | |
| 717 for (c = 0; c < len; c++) | |
| 718 { | |
| 719 Lisp_Object character; | |
| 720 XSETFASTINT (character, c); | |
| 721 map_keymap_item (fun, args, character, AREF (binding, c), data); | |
| 722 } | |
| 723 } | |
| 724 else if (CHAR_TABLE_P (binding)) | |
| 725 { | |
| 726 Lisp_Object indices[3]; | |
| 727 map_char_table (map_keymap_char_table_item, Qnil, binding, binding, | |
| 728 Fcons (make_save_value (fun, 0), | |
| 729 Fcons (make_save_value (data, 0), | |
| 730 args)), | |
| 731 0, indices); | |
| 732 } | |
| 733 } | |
| 734 UNGCPRO; | |
| 735 } | |
| 736 | |
| 737 static void | |
| 738 map_keymap_call (key, val, fun, dummy) | |
| 739 Lisp_Object key, val, fun; | |
| 740 void *dummy; | |
| 741 { | |
| 742 call2 (fun, key, val); | |
| 743 } | |
| 744 | |
| 745 DEFUN ("map-keymap", Fmap_keymap, Smap_keymap, 2, 3, 0, | |
| 746 doc: /* Call FUNCTION for every binding in KEYMAP. | |
| 747 FUNCTION is called with two arguments: the event and its binding. | |
| 748 If KEYMAP has a parent, the parent's bindings are included as well. | |
| 749 This works recursively: if the parent has itself a parent, then the | |
| 750 grandparent's bindings are also included and so on. | |
| 751 usage: (map-keymap FUNCTION KEYMAP) */) | |
| 752 (function, keymap, sort_first) | |
| 753 Lisp_Object function, keymap, sort_first; | |
| 754 { | |
| 755 if (INTEGERP (function)) | |
| 756 /* We have to stop integers early since map_keymap gives them special | |
| 757 significance. */ | |
| 758 Fsignal (Qinvalid_function, Fcons (function, Qnil)); | |
| 759 if (! NILP (sort_first)) | |
| 760 return call3 (intern ("map-keymap-internal"), function, keymap, Qt); | |
| 761 | |
| 762 map_keymap (keymap, map_keymap_call, function, NULL, 1); | |
| 763 return Qnil; | |
| 764 } | |
| 765 | |
| 643 /* Given OBJECT which was found in a slot in a keymap, | 766 /* Given OBJECT which was found in a slot in a keymap, |
| 644 trace indirect definitions to get the actual definition of that slot. | 767 trace indirect definitions to get the actual definition of that slot. |
| 645 An indirect definition is a list of the form | 768 An indirect definition is a list of the form |
| 646 (KEYMAP . INDEX), where KEYMAP is a keymap or a symbol defined as one | 769 (KEYMAP . INDEX), where KEYMAP is a keymap or a symbol defined as one |
| 647 and INDEX is the object to look up in KEYMAP to yield the definition. | 770 and INDEX is the object to look up in KEYMAP to yield the definition. |
| 648 | 771 |
| 649 Also if OBJECT has a menu string as the first element, | 772 Also if OBJECT has a menu string as the first element, |
| 650 remove that. Also remove a menu help string as second element. | 773 remove that. Also remove a menu help string as second element. |
| 651 | 774 |
| 652 If AUTOLOAD is nonzero, load autoloadable keymaps | 775 If AUTOLOAD is nonzero, load autoloadable keymaps |
| 653 that are referred to with indirection. */ | 776 that are referred to with indirection. |
| 777 | |
| 778 This can GC because menu_item_eval_property calls Feval. */ | |
| 654 | 779 |
| 655 Lisp_Object | 780 Lisp_Object |
| 656 get_keyelt (object, autoload) | 781 get_keyelt (object, autoload) |
| 657 Lisp_Object object; | 782 Lisp_Object object; |
| 658 int autoload; | 783 int autoload; |
| 787 elt = XCAR (tail); | 912 elt = XCAR (tail); |
| 788 if (VECTORP (elt)) | 913 if (VECTORP (elt)) |
| 789 { | 914 { |
| 790 if (NATNUMP (idx) && XFASTINT (idx) < ASIZE (elt)) | 915 if (NATNUMP (idx) && XFASTINT (idx) < ASIZE (elt)) |
| 791 { | 916 { |
| 917 CHECK_IMPURE (elt); | |
| 792 ASET (elt, XFASTINT (idx), def); | 918 ASET (elt, XFASTINT (idx), def); |
| 793 return def; | 919 return def; |
| 794 } | 920 } |
| 795 insertion_point = tail; | 921 insertion_point = tail; |
| 796 } | 922 } |
| 812 } | 938 } |
| 813 else if (CONSP (elt)) | 939 else if (CONSP (elt)) |
| 814 { | 940 { |
| 815 if (EQ (idx, XCAR (elt))) | 941 if (EQ (idx, XCAR (elt))) |
| 816 { | 942 { |
| 943 CHECK_IMPURE (elt); | |
| 817 XSETCDR (elt, def); | 944 XSETCDR (elt, def); |
| 818 return def; | 945 return def; |
| 819 } | 946 } |
| 820 } | 947 } |
| 821 else if (EQ (elt, Qkeymap)) | 948 else if (EQ (elt, Qkeymap)) |
| 829 } | 956 } |
| 830 | 957 |
| 831 keymap_end: | 958 keymap_end: |
| 832 /* We have scanned the entire keymap, and not found a binding for | 959 /* We have scanned the entire keymap, and not found a binding for |
| 833 IDX. Let's add one. */ | 960 IDX. Let's add one. */ |
| 961 CHECK_IMPURE (insertion_point); | |
| 834 XSETCDR (insertion_point, | 962 XSETCDR (insertion_point, |
| 835 Fcons (Fcons (idx, def), XCDR (insertion_point))); | 963 Fcons (Fcons (idx, def), XCDR (insertion_point))); |
| 836 } | 964 } |
| 837 | 965 |
| 838 return def; | 966 return def; |
| 912 res = Fcopy_keymap (elt); | 1040 res = Fcopy_keymap (elt); |
| 913 } | 1041 } |
| 914 return res; | 1042 return res; |
| 915 } | 1043 } |
| 916 | 1044 |
| 917 void | 1045 static void |
| 918 copy_keymap_1 (chartable, idx, elt) | 1046 copy_keymap_1 (chartable, idx, elt) |
| 919 Lisp_Object chartable, idx, elt; | 1047 Lisp_Object chartable, idx, elt; |
| 920 { | 1048 { |
| 921 Faset (chartable, idx, copy_keymap_item (elt)); | 1049 Faset (chartable, idx, copy_keymap_item (elt)); |
| 922 } | 1050 } |
| 941 Lisp_Object elt = XCAR (keymap); | 1069 Lisp_Object elt = XCAR (keymap); |
| 942 if (CHAR_TABLE_P (elt)) | 1070 if (CHAR_TABLE_P (elt)) |
| 943 { | 1071 { |
| 944 Lisp_Object indices[3]; | 1072 Lisp_Object indices[3]; |
| 945 elt = Fcopy_sequence (elt); | 1073 elt = Fcopy_sequence (elt); |
| 946 map_char_table (copy_keymap_1, Qnil, elt, elt, 0, indices); | 1074 map_char_table (copy_keymap_1, Qnil, elt, elt, elt, 0, indices); |
| 947 } | 1075 } |
| 948 else if (VECTORP (elt)) | 1076 else if (VECTORP (elt)) |
| 949 { | 1077 { |
| 950 int i; | 1078 int i; |
| 951 elt = Fcopy_sequence (elt); | 1079 elt = Fcopy_sequence (elt); |
| 965 /* Simple Keymap mutators and accessors. */ | 1093 /* Simple Keymap mutators and accessors. */ |
| 966 | 1094 |
| 967 /* GC is possible in this function if it autoloads a keymap. */ | 1095 /* GC is possible in this function if it autoloads a keymap. */ |
| 968 | 1096 |
| 969 DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0, | 1097 DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0, |
| 970 doc: /* Args KEYMAP, KEY, DEF. Define key sequence KEY, in KEYMAP, as DEF. | 1098 doc: /* In KEYMAP, define key sequence KEY as DEF. |
| 971 KEYMAP is a keymap. | 1099 KEYMAP is a keymap. |
| 972 | 1100 |
| 973 KEY is a string or a vector of symbols and characters meaning a | 1101 KEY is a string or a vector of symbols and characters meaning a |
| 974 sequence of keystrokes and events. Non-ASCII characters with codes | 1102 sequence of keystrokes and events. Non-ASCII characters with codes |
| 975 above 127 (such as ISO Latin-1) can be included if you use a vector. | 1103 above 127 (such as ISO Latin-1) can be included if you use a vector. |
| 976 Using [t] for KEY creates a default definition, which applies to any | 1104 Using [t] for KEY creates a default definition, which applies to any |
| 977 event type that has no other definition in thus keymap. | 1105 event type that has no other definition in this keymap. |
| 978 | 1106 |
| 979 DEF is anything that can be a key's definition: | 1107 DEF is anything that can be a key's definition: |
| 980 nil (means key is undefined in this keymap), | 1108 nil (means key is undefined in this keymap), |
| 981 a command (a Lisp function suitable for interactive calling) | 1109 a command (a Lisp function suitable for interactive calling), |
| 982 a string (treated as a keyboard macro), | 1110 a string (treated as a keyboard macro), |
| 983 a keymap (to define a prefix key), | 1111 a keymap (to define a prefix key), |
| 984 a symbol. When the key is looked up, the symbol will stand for its | 1112 a symbol (when the key is looked up, the symbol will stand for its |
| 985 function definition, which should at that time be one of the above, | 1113 function definition, which should at that time be one of the above, |
| 986 or another symbol whose function definition is used, etc. | 1114 or another symbol whose function definition is used, etc.), |
| 987 a cons (STRING . DEFN), meaning that DEFN is the definition | 1115 a cons (STRING . DEFN), meaning that DEFN is the definition |
| 988 (DEFN should be a valid definition in its own right), | 1116 (DEFN should be a valid definition in its own right), |
| 989 or a cons (KEYMAP . CHAR), meaning use definition of CHAR in map KEYMAP. | 1117 or a cons (MAP . CHAR), meaning use definition of CHAR in keymap MAP. |
| 990 | 1118 |
| 991 If KEYMAP is a sparse keymap, the pair binding KEY to DEF is added at | 1119 If KEYMAP is a sparse keymap with a binding for KEY, the existing |
| 992 the front of KEYMAP. */) | 1120 binding is altered. If there is no binding for KEY, the new pair |
| 1121 binding KEY to DEF is added at the front of KEYMAP. */) | |
| 993 (keymap, key, def) | 1122 (keymap, key, def) |
| 994 Lisp_Object keymap; | 1123 Lisp_Object keymap; |
| 995 Lisp_Object key; | 1124 Lisp_Object key; |
| 996 Lisp_Object def; | 1125 Lisp_Object def; |
| 997 { | 1126 { |
| 1060 keymap = get_keymap (cmd, 0, 1); | 1189 keymap = get_keymap (cmd, 0, 1); |
| 1061 if (!CONSP (keymap)) | 1190 if (!CONSP (keymap)) |
| 1062 /* We must use Fkey_description rather than just passing key to | 1191 /* We must use Fkey_description rather than just passing key to |
| 1063 error; key might be a vector, not a string. */ | 1192 error; key might be a vector, not a string. */ |
| 1064 error ("Key sequence %s uses invalid prefix characters", | 1193 error ("Key sequence %s uses invalid prefix characters", |
| 1065 SDATA (Fkey_description (key))); | 1194 SDATA (Fkey_description (key, Qnil))); |
| 1066 } | 1195 } |
| 1067 } | 1196 } |
| 1068 | 1197 |
| 1069 /* This function may GC (it calls Fkey_binding). */ | 1198 /* This function may GC (it calls Fkey_binding). */ |
| 1070 | 1199 |
| 1090 | 1219 |
| 1091 A number as value means KEY is "too long"; | 1220 A number as value means KEY is "too long"; |
| 1092 that is, characters or symbols in it except for the last one | 1221 that is, characters or symbols in it except for the last one |
| 1093 fail to be a valid sequence of prefix characters in KEYMAP. | 1222 fail to be a valid sequence of prefix characters in KEYMAP. |
| 1094 The number is how many characters at the front of KEY | 1223 The number is how many characters at the front of KEY |
| 1095 it takes to reach a non-prefix command. | 1224 it takes to reach a non-prefix key. |
| 1096 | 1225 |
| 1097 Normally, `lookup-key' ignores bindings for t, which act as default | 1226 Normally, `lookup-key' ignores bindings for t, which act as default |
| 1098 bindings, used when nothing else in the keymap applies; this makes it | 1227 bindings, used when nothing else in the keymap applies; this makes it |
| 1099 usable as a general function for probing keymaps. However, if the | 1228 usable as a general function for probing keymaps. However, if the |
| 1100 third optional argument ACCEPT-DEFAULT is non-nil, `lookup-key' will | 1229 third optional argument ACCEPT-DEFAULT is non-nil, `lookup-key' will |
| 1128 | 1257 |
| 1129 if (CONSP (c) && lucid_event_type_list_p (c)) | 1258 if (CONSP (c) && lucid_event_type_list_p (c)) |
| 1130 c = Fevent_convert_list (c); | 1259 c = Fevent_convert_list (c); |
| 1131 | 1260 |
| 1132 /* Turn the 8th bit of string chars into a meta modifier. */ | 1261 /* Turn the 8th bit of string chars into a meta modifier. */ |
| 1133 if (XINT (c) & 0x80 && STRINGP (key)) | 1262 if (INTEGERP (c) && XINT (c) & 0x80 && STRINGP (key)) |
| 1134 XSETINT (c, (XINT (c) | meta_modifier) & ~0x80); | 1263 XSETINT (c, (XINT (c) | meta_modifier) & ~0x80); |
| 1135 | 1264 |
| 1136 /* Allow string since binding for `menu-bar-select-buffer' | 1265 /* Allow string since binding for `menu-bar-select-buffer' |
| 1137 includes the buffer name in the key sequence. */ | 1266 includes the buffer name in the key sequence. */ |
| 1138 if (!INTEGERP (c) && !SYMBOLP (c) && !CONSP (c) && !STRINGP (c)) | 1267 if (!INTEGERP (c) && !SYMBOLP (c) && !CONSP (c) && !STRINGP (c)) |
| 1374 { | 1503 { |
| 1375 Lisp_Object keymaps = Fcons (current_global_map, Qnil); | 1504 Lisp_Object keymaps = Fcons (current_global_map, Qnil); |
| 1376 | 1505 |
| 1377 if (!NILP (olp)) | 1506 if (!NILP (olp)) |
| 1378 { | 1507 { |
| 1379 if (!NILP (Voverriding_local_map)) | |
| 1380 keymaps = Fcons (Voverriding_local_map, keymaps); | |
| 1381 if (!NILP (current_kboard->Voverriding_terminal_local_map)) | 1508 if (!NILP (current_kboard->Voverriding_terminal_local_map)) |
| 1382 keymaps = Fcons (current_kboard->Voverriding_terminal_local_map, keymaps); | 1509 keymaps = Fcons (current_kboard->Voverriding_terminal_local_map, keymaps); |
| 1510 /* The doc said that overriding-terminal-local-map should | |
| 1511 override overriding-local-map. The code used them both, | |
| 1512 but it seems clearer to use just one. rms, jan 2005. */ | |
| 1513 else if (!NILP (Voverriding_local_map)) | |
| 1514 keymaps = Fcons (Voverriding_local_map, keymaps); | |
| 1383 } | 1515 } |
| 1384 if (NILP (XCDR (keymaps))) | 1516 if (NILP (XCDR (keymaps))) |
| 1385 { | 1517 { |
| 1386 Lisp_Object local; | 1518 Lisp_Object local; |
| 1387 Lisp_Object *maps; | 1519 Lisp_Object *maps; |
| 1388 int nmaps, i; | 1520 int nmaps, i; |
| 1389 | 1521 |
| 1522 /* This usually returns the buffer's local map, | |
| 1523 but that can be overridden by a `local-map' property. */ | |
| 1390 local = get_local_map (PT, current_buffer, Qlocal_map); | 1524 local = get_local_map (PT, current_buffer, Qlocal_map); |
| 1391 if (!NILP (local)) | 1525 if (!NILP (local)) |
| 1392 keymaps = Fcons (local, keymaps); | 1526 keymaps = Fcons (local, keymaps); |
| 1393 | 1527 |
| 1528 /* Now put all the minor mode keymaps on the list. */ | |
| 1394 nmaps = current_minor_maps (0, &maps); | 1529 nmaps = current_minor_maps (0, &maps); |
| 1395 | 1530 |
| 1396 for (i = --nmaps; i >= 0; i--) | 1531 for (i = --nmaps; i >= 0; i--) |
| 1397 if (!NILP (maps[i])) | 1532 if (!NILP (maps[i])) |
| 1398 keymaps = Fcons (maps[i], keymaps); | 1533 keymaps = Fcons (maps[i], keymaps); |
| 1399 | 1534 |
| 1535 /* This returns nil unless there is a `keymap' property. */ | |
| 1400 local = get_local_map (PT, current_buffer, Qkeymap); | 1536 local = get_local_map (PT, current_buffer, Qkeymap); |
| 1401 if (!NILP (local)) | 1537 if (!NILP (local)) |
| 1402 keymaps = Fcons (local, keymaps); | 1538 keymaps = Fcons (local, keymaps); |
| 1403 } | 1539 } |
| 1404 | 1540 |
| 1499 | 1635 |
| 1500 /* GC is possible in this function if it autoloads a keymap. */ | 1636 /* GC is possible in this function if it autoloads a keymap. */ |
| 1501 | 1637 |
| 1502 DEFUN ("local-key-binding", Flocal_key_binding, Slocal_key_binding, 1, 2, 0, | 1638 DEFUN ("local-key-binding", Flocal_key_binding, Slocal_key_binding, 1, 2, 0, |
| 1503 doc: /* Return the binding for command KEYS in current local keymap only. | 1639 doc: /* Return the binding for command KEYS in current local keymap only. |
| 1504 KEYS is a string, a sequence of keystrokes. | 1640 KEYS is a string or vector, a sequence of keystrokes. |
| 1505 The binding is probably a symbol with a function definition. | 1641 The binding is probably a symbol with a function definition. |
| 1506 | 1642 |
| 1507 If optional argument ACCEPT-DEFAULT is non-nil, recognize default | 1643 If optional argument ACCEPT-DEFAULT is non-nil, recognize default |
| 1508 bindings; see the description of `lookup-key' for more details about this. */) | 1644 bindings; see the description of `lookup-key' for more details about this. */) |
| 1509 (keys, accept_default) | 1645 (keys, accept_default) |
| 1518 | 1654 |
| 1519 /* GC is possible in this function if it autoloads a keymap. */ | 1655 /* GC is possible in this function if it autoloads a keymap. */ |
| 1520 | 1656 |
| 1521 DEFUN ("global-key-binding", Fglobal_key_binding, Sglobal_key_binding, 1, 2, 0, | 1657 DEFUN ("global-key-binding", Fglobal_key_binding, Sglobal_key_binding, 1, 2, 0, |
| 1522 doc: /* Return the binding for command KEYS in current global keymap only. | 1658 doc: /* Return the binding for command KEYS in current global keymap only. |
| 1523 KEYS is a string, a sequence of keystrokes. | 1659 KEYS is a string or vector, a sequence of keystrokes. |
| 1524 The binding is probably a symbol with a function definition. | 1660 The binding is probably a symbol with a function definition. |
| 1525 This function's return values are the same as those of lookup-key | 1661 This function's return values are the same as those of `lookup-key' |
| 1526 \(which see). | 1662 \(which see). |
| 1527 | 1663 |
| 1528 If optional argument ACCEPT-DEFAULT is non-nil, recognize default | 1664 If optional argument ACCEPT-DEFAULT is non-nil, recognize default |
| 1529 bindings; see the description of `lookup-key' for more details about this. */) | 1665 bindings; see the description of `lookup-key' for more details about this. */) |
| 1530 (keys, accept_default) | 1666 (keys, accept_default) |
| 1535 | 1671 |
| 1536 /* GC is possible in this function if it autoloads a keymap. */ | 1672 /* GC is possible in this function if it autoloads a keymap. */ |
| 1537 | 1673 |
| 1538 DEFUN ("minor-mode-key-binding", Fminor_mode_key_binding, Sminor_mode_key_binding, 1, 2, 0, | 1674 DEFUN ("minor-mode-key-binding", Fminor_mode_key_binding, Sminor_mode_key_binding, 1, 2, 0, |
| 1539 doc: /* Find the visible minor mode bindings of KEY. | 1675 doc: /* Find the visible minor mode bindings of KEY. |
| 1540 Return an alist of pairs (MODENAME . BINDING), where MODENAME is the | 1676 Return an alist of pairs (MODENAME . BINDING), where MODENAME is |
| 1541 the symbol which names the minor mode binding KEY, and BINDING is | 1677 the symbol which names the minor mode binding KEY, and BINDING is |
| 1542 KEY's definition in that mode. In particular, if KEY has no | 1678 KEY's definition in that mode. In particular, if KEY has no |
| 1543 minor-mode bindings, return nil. If the first binding is a | 1679 minor-mode bindings, return nil. If the first binding is a |
| 1544 non-prefix, all subsequent bindings will be omitted, since they would | 1680 non-prefix, all subsequent bindings will be omitted, since they would |
| 1545 be ignored. Similarly, the list doesn't include non-prefix bindings | 1681 be ignored. Similarly, the list doesn't include non-prefix bindings |
| 1583 A new sparse keymap is stored as COMMAND's function definition and its value. | 1719 A new sparse keymap is stored as COMMAND's function definition and its value. |
| 1584 If a second optional argument MAPVAR is given, the map is stored as | 1720 If a second optional argument MAPVAR is given, the map is stored as |
| 1585 its value instead of as COMMAND's value; but COMMAND is still defined | 1721 its value instead of as COMMAND's value; but COMMAND is still defined |
| 1586 as a function. | 1722 as a function. |
| 1587 The third optional argument NAME, if given, supplies a menu name | 1723 The third optional argument NAME, if given, supplies a menu name |
| 1588 string for the map. This is required to use the keymap as a menu. */) | 1724 string for the map. This is required to use the keymap as a menu. |
| 1725 This function returns COMMAND. */) | |
| 1589 (command, mapvar, name) | 1726 (command, mapvar, name) |
| 1590 Lisp_Object command, mapvar, name; | 1727 Lisp_Object command, mapvar, name; |
| 1591 { | 1728 { |
| 1592 Lisp_Object map; | 1729 Lisp_Object map; |
| 1593 map = Fmake_sparse_keymap (name); | 1730 map = Fmake_sparse_keymap (name); |
| 1656 Lisp_Object maps, tail, thisseq, key, cmd; | 1793 Lisp_Object maps, tail, thisseq, key, cmd; |
| 1657 int is_metized; /* If 1, `key' is assumed to be INTEGERP. */ | 1794 int is_metized; /* If 1, `key' is assumed to be INTEGERP. */ |
| 1658 { | 1795 { |
| 1659 Lisp_Object tem; | 1796 Lisp_Object tem; |
| 1660 | 1797 |
| 1661 cmd = get_keyelt (cmd, 0); | 1798 cmd = get_keymap (get_keyelt (cmd, 0), 0, 0); |
| 1662 if (NILP (cmd)) | 1799 if (NILP (cmd)) |
| 1663 return; | 1800 return; |
| 1664 | 1801 |
| 1665 tem = get_keymap (cmd, 0, 0); | 1802 /* Look for and break cycles. */ |
| 1666 if (CONSP (tem)) | 1803 while (!NILP (tem = Frassq (cmd, maps))) |
| 1667 { | 1804 { |
| 1668 cmd = tem; | 1805 Lisp_Object prefix = XCAR (tem); |
| 1669 /* Ignore keymaps that are already added to maps. */ | 1806 int lim = XINT (Flength (XCAR (tem))); |
| 1670 tem = Frassq (cmd, maps); | 1807 if (lim <= XINT (Flength (thisseq))) |
| 1671 if (NILP (tem)) | 1808 { /* This keymap was already seen with a smaller prefix. */ |
| 1672 { | 1809 int i = 0; |
| 1673 /* If the last key in thisseq is meta-prefix-char, | 1810 while (i < lim && EQ (Faref (prefix, make_number (i)), |
| 1674 turn it into a meta-ized keystroke. We know | 1811 Faref (thisseq, make_number (i)))) |
| 1675 that the event we're about to append is an | 1812 i++; |
| 1676 ascii keystroke since we're processing a | 1813 if (i >= lim) |
| 1677 keymap table. */ | 1814 /* `prefix' is a prefix of `thisseq' => there's a cycle. */ |
| 1678 if (is_metized) | 1815 return; |
| 1679 { | 1816 } |
| 1680 int meta_bit = meta_modifier; | 1817 /* This occurrence of `cmd' in `maps' does not correspond to a cycle, |
| 1681 Lisp_Object last = make_number (XINT (Flength (thisseq)) - 1); | 1818 but maybe `cmd' occurs again further down in `maps', so keep |
| 1682 tem = Fcopy_sequence (thisseq); | 1819 looking. */ |
| 1683 | 1820 maps = XCDR (Fmemq (tem, maps)); |
| 1684 Faset (tem, last, make_number (XINT (key) | meta_bit)); | 1821 } |
| 1685 | 1822 |
| 1686 /* This new sequence is the same length as | 1823 /* If the last key in thisseq is meta-prefix-char, |
| 1687 thisseq, so stick it in the list right | 1824 turn it into a meta-ized keystroke. We know |
| 1688 after this one. */ | 1825 that the event we're about to append is an |
| 1689 XSETCDR (tail, | 1826 ascii keystroke since we're processing a |
| 1690 Fcons (Fcons (tem, cmd), XCDR (tail))); | 1827 keymap table. */ |
| 1691 } | 1828 if (is_metized) |
| 1692 else | 1829 { |
| 1693 { | 1830 int meta_bit = meta_modifier; |
| 1694 tem = append_key (thisseq, key); | 1831 Lisp_Object last = make_number (XINT (Flength (thisseq)) - 1); |
| 1695 nconc2 (tail, Fcons (Fcons (tem, cmd), Qnil)); | 1832 tem = Fcopy_sequence (thisseq); |
| 1696 } | 1833 |
| 1697 } | 1834 Faset (tem, last, make_number (XINT (key) | meta_bit)); |
| 1835 | |
| 1836 /* This new sequence is the same length as | |
| 1837 thisseq, so stick it in the list right | |
| 1838 after this one. */ | |
| 1839 XSETCDR (tail, | |
| 1840 Fcons (Fcons (tem, cmd), XCDR (tail))); | |
| 1841 } | |
| 1842 else | |
| 1843 { | |
| 1844 tem = append_key (thisseq, key); | |
| 1845 nconc2 (tail, Fcons (Fcons (tem, cmd), Qnil)); | |
| 1698 } | 1846 } |
| 1699 } | 1847 } |
| 1700 | 1848 |
| 1701 static void | 1849 static void |
| 1702 accessible_keymaps_char_table (args, index, cmd) | 1850 accessible_keymaps_char_table (args, index, cmd) |
| 1720 An optional argument PREFIX, if non-nil, should be a key sequence; | 1868 An optional argument PREFIX, if non-nil, should be a key sequence; |
| 1721 then the value includes only maps for prefixes that start with PREFIX. */) | 1869 then the value includes only maps for prefixes that start with PREFIX. */) |
| 1722 (keymap, prefix) | 1870 (keymap, prefix) |
| 1723 Lisp_Object keymap, prefix; | 1871 Lisp_Object keymap, prefix; |
| 1724 { | 1872 { |
| 1725 Lisp_Object maps, good_maps, tail; | 1873 Lisp_Object maps, tail; |
| 1726 int prefixlen = 0; | 1874 int prefixlen = 0; |
| 1727 | 1875 |
| 1728 /* no need for gcpro because we don't autoload any keymaps. */ | 1876 /* no need for gcpro because we don't autoload any keymaps. */ |
| 1729 | 1877 |
| 1730 if (!NILP (prefix)) | 1878 if (!NILP (prefix)) |
| 1803 | 1951 |
| 1804 if (CHAR_TABLE_P (elt)) | 1952 if (CHAR_TABLE_P (elt)) |
| 1805 { | 1953 { |
| 1806 Lisp_Object indices[3]; | 1954 Lisp_Object indices[3]; |
| 1807 | 1955 |
| 1808 map_char_table (accessible_keymaps_char_table, Qnil, | 1956 map_char_table (accessible_keymaps_char_table, Qnil, elt, |
| 1809 elt, Fcons (Fcons (maps, make_number (is_metized)), | 1957 elt, Fcons (Fcons (maps, make_number (is_metized)), |
| 1810 Fcons (tail, thisseq)), | 1958 Fcons (tail, thisseq)), |
| 1811 0, indices); | 1959 0, indices); |
| 1812 } | 1960 } |
| 1813 else if (VECTORP (elt)) | 1961 else if (VECTORP (elt)) |
| 1826 is_metized && INTEGERP (XCAR (elt))); | 1974 is_metized && INTEGERP (XCAR (elt))); |
| 1827 | 1975 |
| 1828 } | 1976 } |
| 1829 } | 1977 } |
| 1830 | 1978 |
| 1831 if (NILP (prefix)) | 1979 return maps; |
| 1832 return maps; | |
| 1833 | |
| 1834 /* Now find just the maps whose access prefixes start with PREFIX. */ | |
| 1835 | |
| 1836 good_maps = Qnil; | |
| 1837 for (; CONSP (maps); maps = XCDR (maps)) | |
| 1838 { | |
| 1839 Lisp_Object elt, thisseq; | |
| 1840 elt = XCAR (maps); | |
| 1841 thisseq = XCAR (elt); | |
| 1842 /* The access prefix must be at least as long as PREFIX, | |
| 1843 and the first elements must match those of PREFIX. */ | |
| 1844 if (XINT (Flength (thisseq)) >= prefixlen) | |
| 1845 { | |
| 1846 int i; | |
| 1847 for (i = 0; i < prefixlen; i++) | |
| 1848 { | |
| 1849 Lisp_Object i1; | |
| 1850 XSETFASTINT (i1, i); | |
| 1851 if (!EQ (Faref (thisseq, i1), Faref (prefix, i1))) | |
| 1852 break; | |
| 1853 } | |
| 1854 if (i == prefixlen) | |
| 1855 good_maps = Fcons (elt, good_maps); | |
| 1856 } | |
| 1857 } | |
| 1858 | |
| 1859 return Fnreverse (good_maps); | |
| 1860 } | 1980 } |
| 1861 | 1981 |
| 1862 Lisp_Object Qsingle_key_description, Qkey_description; | 1982 Lisp_Object Qsingle_key_description, Qkey_description; |
| 1863 | 1983 |
| 1864 /* This function cannot GC. */ | 1984 /* This function cannot GC. */ |
| 1865 | 1985 |
| 1866 DEFUN ("key-description", Fkey_description, Skey_description, 1, 1, 0, | 1986 DEFUN ("key-description", Fkey_description, Skey_description, 1, 2, 0, |
| 1867 doc: /* Return a pretty description of key-sequence KEYS. | 1987 doc: /* Return a pretty description of key-sequence KEYS. |
| 1868 Control characters turn into "C-foo" sequences, meta into "M-foo" | 1988 Optional arg PREFIX is the sequence of keys leading up to KEYS. |
| 1989 Control characters turn into "C-foo" sequences, meta into "M-foo", | |
| 1869 spaces are put between sequence elements, etc. */) | 1990 spaces are put between sequence elements, etc. */) |
| 1870 (keys) | 1991 (keys, prefix) |
| 1871 Lisp_Object keys; | 1992 Lisp_Object keys, prefix; |
| 1872 { | 1993 { |
| 1873 int len = 0; | 1994 int len = 0; |
| 1874 int i, i_byte; | 1995 int i, i_byte; |
| 1875 Lisp_Object sep; | 1996 Lisp_Object *args; |
| 1876 Lisp_Object *args = NULL; | 1997 int size = XINT (Flength (keys)); |
| 1877 | 1998 Lisp_Object list; |
| 1878 if (STRINGP (keys)) | 1999 Lisp_Object sep = build_string (" "); |
| 1879 { | 2000 Lisp_Object key; |
| 1880 Lisp_Object vector; | 2001 int add_meta = 0; |
| 1881 vector = Fmake_vector (Flength (keys), Qnil); | 2002 |
| 1882 for (i = 0, i_byte = 0; i < SCHARS (keys); ) | 2003 if (!NILP (prefix)) |
| 2004 size += XINT (Flength (prefix)); | |
| 2005 | |
| 2006 /* This has one extra element at the end that we don't pass to Fconcat. */ | |
| 2007 args = (Lisp_Object *) alloca (size * 4 * sizeof (Lisp_Object)); | |
| 2008 | |
| 2009 /* In effect, this computes | |
| 2010 (mapconcat 'single-key-description keys " ") | |
| 2011 but we shouldn't use mapconcat because it can do GC. */ | |
| 2012 | |
| 2013 next_list: | |
| 2014 if (!NILP (prefix)) | |
| 2015 list = prefix, prefix = Qnil; | |
| 2016 else if (!NILP (keys)) | |
| 2017 list = keys, keys = Qnil; | |
| 2018 else | |
| 2019 { | |
| 2020 if (add_meta) | |
| 2021 { | |
| 2022 args[len] = Fsingle_key_description (meta_prefix_char, Qnil); | |
| 2023 len += 2; | |
| 2024 } | |
| 2025 else if (len == 0) | |
| 2026 return empty_string; | |
| 2027 return Fconcat (len - 1, args); | |
| 2028 } | |
| 2029 | |
| 2030 if (STRINGP (list)) | |
| 2031 size = SCHARS (list); | |
| 2032 else if (VECTORP (list)) | |
| 2033 size = XVECTOR (list)->size; | |
| 2034 else if (CONSP (list)) | |
| 2035 size = XINT (Flength (list)); | |
| 2036 else | |
| 2037 wrong_type_argument (Qarrayp, list); | |
| 2038 | |
| 2039 i = i_byte = 0; | |
| 2040 | |
| 2041 while (i < size) | |
| 2042 { | |
| 2043 if (STRINGP (list)) | |
| 1883 { | 2044 { |
| 1884 int c; | 2045 int c; |
| 1885 int i_before = i; | 2046 FETCH_STRING_CHAR_ADVANCE (c, list, i, i_byte); |
| 1886 | |
| 1887 FETCH_STRING_CHAR_ADVANCE (c, keys, i, i_byte); | |
| 1888 if (SINGLE_BYTE_CHAR_P (c) && (c & 0200)) | 2047 if (SINGLE_BYTE_CHAR_P (c) && (c & 0200)) |
| 1889 c ^= 0200 | meta_modifier; | 2048 c ^= 0200 | meta_modifier; |
| 1890 XSETFASTINT (AREF (vector, i_before), c); | 2049 XSETFASTINT (key, c); |
| 1891 } | 2050 } |
| 1892 keys = vector; | 2051 else if (VECTORP (list)) |
| 1893 } | 2052 { |
| 1894 | 2053 key = AREF (list, i++); |
| 1895 if (VECTORP (keys)) | 2054 } |
| 1896 { | 2055 else |
| 1897 /* In effect, this computes | 2056 { |
| 1898 (mapconcat 'single-key-description keys " ") | 2057 key = XCAR (list); |
| 1899 but we shouldn't use mapconcat because it can do GC. */ | 2058 list = XCDR (list); |
| 1900 | 2059 i++; |
| 1901 len = XVECTOR (keys)->size; | 2060 } |
| 1902 sep = build_string (" "); | 2061 |
| 1903 /* This has one extra element at the end that we don't pass to Fconcat. */ | 2062 if (add_meta) |
| 1904 args = (Lisp_Object *) alloca (len * 2 * sizeof (Lisp_Object)); | 2063 { |
| 1905 | 2064 if (!INTEGERP (key) |
| 1906 for (i = 0; i < len; i++) | 2065 || EQ (key, meta_prefix_char) |
| 1907 { | 2066 || (XINT (key) & meta_modifier)) |
| 1908 args[i * 2] = Fsingle_key_description (AREF (keys, i), Qnil); | 2067 { |
| 1909 args[i * 2 + 1] = sep; | 2068 args[len++] = Fsingle_key_description (meta_prefix_char, Qnil); |
| 1910 } | 2069 args[len++] = sep; |
| 1911 } | 2070 if (EQ (key, meta_prefix_char)) |
| 1912 else if (CONSP (keys)) | 2071 continue; |
| 1913 { | 2072 } |
| 1914 /* In effect, this computes | 2073 else |
| 1915 (mapconcat 'single-key-description keys " ") | 2074 XSETINT (key, (XINT (key) | meta_modifier) & ~0x80); |
| 1916 but we shouldn't use mapconcat because it can do GC. */ | 2075 add_meta = 0; |
| 1917 | 2076 } |
| 1918 len = XFASTINT (Flength (keys)); | 2077 else if (EQ (key, meta_prefix_char)) |
| 1919 sep = build_string (" "); | 2078 { |
| 1920 /* This has one extra element at the end that we don't pass to Fconcat. */ | 2079 add_meta = 1; |
| 1921 args = (Lisp_Object *) alloca (len * 2 * sizeof (Lisp_Object)); | 2080 continue; |
| 1922 | 2081 } |
| 1923 for (i = 0; i < len; i++) | 2082 args[len++] = Fsingle_key_description (key, Qnil); |
| 1924 { | 2083 args[len++] = sep; |
| 1925 args[i * 2] = Fsingle_key_description (XCAR (keys), Qnil); | 2084 } |
| 1926 args[i * 2 + 1] = sep; | 2085 goto next_list; |
| 1927 keys = XCDR (keys); | 2086 } |
| 1928 } | 2087 |
| 1929 } | |
| 1930 else | |
| 1931 keys = wrong_type_argument (Qarrayp, keys); | |
| 1932 | |
| 1933 if (len == 0) | |
| 1934 return empty_string; | |
| 1935 return Fconcat (len * 2 - 1, args); | |
| 1936 } | |
| 1937 | 2088 |
| 1938 char * | 2089 char * |
| 1939 push_key_description (c, p, force_multibyte) | 2090 push_key_description (c, p, force_multibyte) |
| 1940 register unsigned int c; | 2091 register unsigned int c; |
| 1941 register char *p; | 2092 register char *p; |
| 2165 | 2316 |
| 2166 /* This function cannot GC. */ | 2317 /* This function cannot GC. */ |
| 2167 | 2318 |
| 2168 DEFUN ("text-char-description", Ftext_char_description, Stext_char_description, 1, 1, 0, | 2319 DEFUN ("text-char-description", Ftext_char_description, Stext_char_description, 1, 1, 0, |
| 2169 doc: /* Return a pretty description of file-character CHARACTER. | 2320 doc: /* Return a pretty description of file-character CHARACTER. |
| 2170 Control characters turn into "^char", etc. */) | 2321 Control characters turn into "^char", etc. This differs from |
| 2322 `single-key-description' which turns them into "C-char". | |
| 2323 Also, this function recognizes the 2**7 bit as the Meta character, | |
| 2324 whereas `single-key-description' uses the 2**27 bit for Meta. | |
| 2325 See Info node `(elisp)Describing Characters' for examples. */) | |
| 2171 (character) | 2326 (character) |
| 2172 Lisp_Object character; | 2327 Lisp_Object character; |
| 2173 { | 2328 { |
| 2174 /* Currently MAX_MULTIBYTE_LENGTH is 4 (< 6). */ | 2329 /* Currently MAX_MULTIBYTE_LENGTH is 4 (< 6). */ |
| 2175 unsigned char str[6]; | 2330 unsigned char str[6]; |
| 2231 Lisp_Object tail, value; | 2386 Lisp_Object tail, value; |
| 2232 | 2387 |
| 2233 for (tail = shadow; CONSP (tail); tail = XCDR (tail)) | 2388 for (tail = shadow; CONSP (tail); tail = XCDR (tail)) |
| 2234 { | 2389 { |
| 2235 value = Flookup_key (XCAR (tail), key, flag); | 2390 value = Flookup_key (XCAR (tail), key, flag); |
| 2236 if (!NILP (value) && !NATNUMP (value)) | 2391 if (NATNUMP (value)) |
| 2392 { | |
| 2393 value = Flookup_key (XCAR (tail), | |
| 2394 Fsubstring (key, make_number (0), value), flag); | |
| 2395 if (!NILP (value)) | |
| 2396 return Qnil; | |
| 2397 } | |
| 2398 else if (!NILP (value)) | |
| 2237 return value; | 2399 return value; |
| 2238 } | 2400 } |
| 2239 return Qnil; | 2401 return Qnil; |
| 2240 } | 2402 } |
| 2403 | |
| 2404 static Lisp_Object Vmouse_events; | |
| 2241 | 2405 |
| 2242 /* This function can GC if Flookup_key autoloads any keymaps. */ | 2406 /* This function can GC if Flookup_key autoloads any keymaps. */ |
| 2243 | 2407 |
| 2244 static Lisp_Object | 2408 static Lisp_Object |
| 2245 where_is_internal (definition, keymaps, firstonly, noindirect, no_remap) | 2409 where_is_internal (definition, keymaps, firstonly, noindirect, no_remap) |
| 2275 sequences = Qnil; | 2439 sequences = Qnil; |
| 2276 | 2440 |
| 2277 for (; !NILP (maps); maps = Fcdr (maps)) | 2441 for (; !NILP (maps); maps = Fcdr (maps)) |
| 2278 { | 2442 { |
| 2279 /* Key sequence to reach map, and the map that it reaches */ | 2443 /* Key sequence to reach map, and the map that it reaches */ |
| 2280 register Lisp_Object this, map; | 2444 register Lisp_Object this, map, tem; |
| 2281 | 2445 |
| 2282 /* In order to fold [META-PREFIX-CHAR CHAR] sequences into | 2446 /* In order to fold [META-PREFIX-CHAR CHAR] sequences into |
| 2283 [M-CHAR] sequences, check if last character of the sequence | 2447 [M-CHAR] sequences, check if last character of the sequence |
| 2284 is the meta-prefix char. */ | 2448 is the meta-prefix char. */ |
| 2285 Lisp_Object last; | 2449 Lisp_Object last; |
| 2291 last_is_meta = (XINT (last) >= 0 | 2455 last_is_meta = (XINT (last) >= 0 |
| 2292 && EQ (Faref (this, last), meta_prefix_char)); | 2456 && EQ (Faref (this, last), meta_prefix_char)); |
| 2293 | 2457 |
| 2294 /* if (nomenus && !ascii_sequence_p (this)) */ | 2458 /* if (nomenus && !ascii_sequence_p (this)) */ |
| 2295 if (nomenus && XINT (last) >= 0 | 2459 if (nomenus && XINT (last) >= 0 |
| 2296 && !INTEGERP (Faref (this, make_number (0)))) | 2460 && SYMBOLP (tem = Faref (this, make_number (0))) |
| 2461 && !NILP (Fmemq (XCAR (parse_modifiers (tem)), Vmouse_events))) | |
| 2297 /* If no menu entries should be returned, skip over the | 2462 /* If no menu entries should be returned, skip over the |
| 2298 keymaps bound to `menu-bar' and `tool-bar' and other | 2463 keymaps bound to `menu-bar' and `tool-bar' and other |
| 2299 non-ascii prefixes like `C-down-mouse-2'. */ | 2464 non-ascii prefixes like `C-down-mouse-2'. */ |
| 2300 continue; | 2465 continue; |
| 2301 | 2466 |
| 2345 args = Fcons (Fcons (Fcons (definition, noindirect), | 2510 args = Fcons (Fcons (Fcons (definition, noindirect), |
| 2346 Qnil), /* Result accumulator. */ | 2511 Qnil), /* Result accumulator. */ |
| 2347 Fcons (Fcons (this, last), | 2512 Fcons (Fcons (this, last), |
| 2348 Fcons (make_number (nomenus), | 2513 Fcons (make_number (nomenus), |
| 2349 make_number (last_is_meta)))); | 2514 make_number (last_is_meta)))); |
| 2350 map_char_table (where_is_internal_2, Qnil, elt, args, | 2515 map_char_table (where_is_internal_2, Qnil, elt, elt, args, |
| 2351 0, indices); | 2516 0, indices); |
| 2352 sequences = XCDR (XCAR (args)); | 2517 sequences = XCDR (XCAR (args)); |
| 2353 } | 2518 } |
| 2354 else if (CONSP (elt)) | 2519 else if (CONSP (elt)) |
| 2355 { | 2520 { |
| 2408 means undefined. */ | 2573 means undefined. */ |
| 2409 if (!EQ (shadow_lookup (keymaps, sequence, Qnil), definition)) | 2574 if (!EQ (shadow_lookup (keymaps, sequence, Qnil), definition)) |
| 2410 continue; | 2575 continue; |
| 2411 | 2576 |
| 2412 record_sequence: | 2577 record_sequence: |
| 2578 /* Don't annoy user with strings from a menu such as | |
| 2579 Select Paste. Change them all to "(any string)", | |
| 2580 so that there seems to be only one menu item | |
| 2581 to report. */ | |
| 2582 if (! NILP (sequence)) | |
| 2583 { | |
| 2584 Lisp_Object tem; | |
| 2585 tem = Faref (sequence, make_number (XVECTOR (sequence)->size - 1)); | |
| 2586 if (STRINGP (tem)) | |
| 2587 Faset (sequence, make_number (XVECTOR (sequence)->size - 1), | |
| 2588 build_string ("(any string)")); | |
| 2589 } | |
| 2590 | |
| 2413 /* It is a true unshadowed match. Record it, unless it's already | 2591 /* It is a true unshadowed match. Record it, unless it's already |
| 2414 been seen (as could happen when inheriting keymaps). */ | 2592 been seen (as could happen when inheriting keymaps). */ |
| 2415 if (NILP (Fmember (sequence, found))) | 2593 if (NILP (Fmember (sequence, found))) |
| 2416 found = Fcons (sequence, found); | 2594 found = Fcons (sequence, found); |
| 2417 | 2595 |
| 2447 return found; | 2625 return found; |
| 2448 } | 2626 } |
| 2449 | 2627 |
| 2450 DEFUN ("where-is-internal", Fwhere_is_internal, Swhere_is_internal, 1, 5, 0, | 2628 DEFUN ("where-is-internal", Fwhere_is_internal, Swhere_is_internal, 1, 5, 0, |
| 2451 doc: /* Return list of keys that invoke DEFINITION. | 2629 doc: /* Return list of keys that invoke DEFINITION. |
| 2452 If KEYMAP is non-nil, search only KEYMAP and the global keymap. | 2630 If KEYMAP is a keymap, search only KEYMAP and the global keymap. |
| 2453 If KEYMAP is nil, search all the currently active keymaps. | 2631 If KEYMAP is nil, search all the currently active keymaps. |
| 2454 If KEYMAP is a list of keymaps, search only those keymaps. | 2632 If KEYMAP is a list of keymaps, search only those keymaps. |
| 2455 | 2633 |
| 2456 If optional 3rd arg FIRSTONLY is non-nil, return the first key sequence found, | 2634 If optional 3rd arg FIRSTONLY is non-nil, return the first key sequence found, |
| 2457 rather than a list of all possible key sequences. | 2635 rather than a list of all possible key sequences. |
| 2458 If FIRSTONLY is the symbol `non-ascii', return the first binding found, | 2636 If FIRSTONLY is the symbol `non-ascii', return the first binding found, |
| 2459 no matter what it is. | 2637 no matter what it is. |
| 2460 If FIRSTONLY has another non-nil value, prefer sequences of ASCII characters, | 2638 If FIRSTONLY has another non-nil value, prefer sequences of ASCII characters |
| 2461 and entirely reject menu bindings. | 2639 \(or their meta variants) and entirely reject menu bindings. |
| 2462 | 2640 |
| 2463 If optional 4th arg NOINDIRECT is non-nil, don't follow indirections | 2641 If optional 4th arg NOINDIRECT is non-nil, don't follow indirections |
| 2464 to other keymaps or slots. This makes it possible to search for an | 2642 to other keymaps or slots. This makes it possible to search for an |
| 2465 indirect definition itself. | 2643 indirect definition itself. |
| 2466 | 2644 |
| 2585 | 2763 |
| 2586 UNGCPRO; | 2764 UNGCPRO; |
| 2587 } | 2765 } |
| 2588 | 2766 |
| 2589 | 2767 |
| 2590 /* This function cannot GC. */ | 2768 /* This function can GC because get_keyelt can. */ |
| 2591 | 2769 |
| 2592 static Lisp_Object | 2770 static Lisp_Object |
| 2593 where_is_internal_1 (binding, key, definition, noindirect, this, last, | 2771 where_is_internal_1 (binding, key, definition, noindirect, this, last, |
| 2594 nomenus, last_is_meta) | 2772 nomenus, last_is_meta) |
| 2595 Lisp_Object binding, key, definition, noindirect, this, last; | 2773 Lisp_Object binding, key, definition, noindirect, this, last; |
| 2682 Findent_to (make_number (16), make_number (1)); | 2860 Findent_to (make_number (16), make_number (1)); |
| 2683 bufend = push_key_description (c, buf, 1); | 2861 bufend = push_key_description (c, buf, 1); |
| 2684 insert (buf, bufend - buf); | 2862 insert (buf, bufend - buf); |
| 2685 | 2863 |
| 2686 insert ("\n", 1); | 2864 insert ("\n", 1); |
| 2865 | |
| 2866 /* Insert calls signal_after_change which may GC. */ | |
| 2867 translate = SDATA (Vkeyboard_translate_table); | |
| 2687 } | 2868 } |
| 2688 | 2869 |
| 2689 insert ("\n", 1); | 2870 insert ("\n", 1); |
| 2690 } | 2871 } |
| 2691 | 2872 |
| 2692 if (!NILP (Vkey_translation_map)) | 2873 if (!NILP (Vkey_translation_map)) |
| 2693 describe_map_tree (Vkey_translation_map, 0, Qnil, prefix, | 2874 describe_map_tree (Vkey_translation_map, 0, Qnil, prefix, |
| 2694 "Key translations", nomenu, 1, 0); | 2875 "Key translations", nomenu, 1, 0, 0); |
| 2695 | 2876 |
| 2696 | 2877 |
| 2697 /* Print the (major mode) local map. */ | 2878 /* Print the (major mode) local map. */ |
| 2698 start1 = Qnil; | 2879 start1 = Qnil; |
| 2699 if (!NILP (current_kboard->Voverriding_terminal_local_map)) | 2880 if (!NILP (current_kboard->Voverriding_terminal_local_map)) |
| 2702 start1 = Voverriding_local_map; | 2883 start1 = Voverriding_local_map; |
| 2703 | 2884 |
| 2704 if (!NILP (start1)) | 2885 if (!NILP (start1)) |
| 2705 { | 2886 { |
| 2706 describe_map_tree (start1, 1, shadow, prefix, | 2887 describe_map_tree (start1, 1, shadow, prefix, |
| 2707 "\f\nOverriding Bindings", nomenu, 0, 0); | 2888 "\f\nOverriding Bindings", nomenu, 0, 0, 0); |
| 2708 shadow = Fcons (start1, shadow); | 2889 shadow = Fcons (start1, shadow); |
| 2709 } | 2890 } |
| 2710 else | 2891 else |
| 2711 { | 2892 { |
| 2712 /* Print the minor mode and major mode keymaps. */ | 2893 /* Print the minor mode and major mode keymaps. */ |
| 2723 start1 = get_local_map (BUF_PT (XBUFFER (buffer)), | 2904 start1 = get_local_map (BUF_PT (XBUFFER (buffer)), |
| 2724 XBUFFER (buffer), Qkeymap); | 2905 XBUFFER (buffer), Qkeymap); |
| 2725 if (!NILP (start1)) | 2906 if (!NILP (start1)) |
| 2726 { | 2907 { |
| 2727 describe_map_tree (start1, 1, shadow, prefix, | 2908 describe_map_tree (start1, 1, shadow, prefix, |
| 2728 "\f\n`keymap' Property Bindings", nomenu, 0, 0); | 2909 "\f\n`keymap' Property Bindings", nomenu, |
| 2910 0, 0, 0); | |
| 2729 shadow = Fcons (start1, shadow); | 2911 shadow = Fcons (start1, shadow); |
| 2730 } | 2912 } |
| 2731 | 2913 |
| 2732 /* Print the minor mode maps. */ | 2914 /* Print the minor mode maps. */ |
| 2733 for (i = 0; i < nmaps; i++) | 2915 for (i = 0; i < nmaps; i++) |
| 2751 *p++ = '\''; | 2933 *p++ = '\''; |
| 2752 bcopy (" Minor Mode Bindings", p, sizeof (" Minor Mode Bindings") - 1); | 2934 bcopy (" Minor Mode Bindings", p, sizeof (" Minor Mode Bindings") - 1); |
| 2753 p += sizeof (" Minor Mode Bindings") - 1; | 2935 p += sizeof (" Minor Mode Bindings") - 1; |
| 2754 *p = 0; | 2936 *p = 0; |
| 2755 | 2937 |
| 2756 describe_map_tree (maps[i], 1, shadow, prefix, title, nomenu, 0, 0); | 2938 describe_map_tree (maps[i], 1, shadow, prefix, |
| 2939 title, nomenu, 0, 0, 0); | |
| 2757 shadow = Fcons (maps[i], shadow); | 2940 shadow = Fcons (maps[i], shadow); |
| 2758 } | 2941 } |
| 2759 | 2942 |
| 2760 start1 = get_local_map (BUF_PT (XBUFFER (buffer)), | 2943 start1 = get_local_map (BUF_PT (XBUFFER (buffer)), |
| 2761 XBUFFER (buffer), Qlocal_map); | 2944 XBUFFER (buffer), Qlocal_map); |
| 2762 if (!NILP (start1)) | 2945 if (!NILP (start1)) |
| 2763 { | 2946 { |
| 2764 if (EQ (start1, XBUFFER (buffer)->keymap)) | 2947 if (EQ (start1, XBUFFER (buffer)->keymap)) |
| 2765 describe_map_tree (start1, 1, shadow, prefix, | 2948 describe_map_tree (start1, 1, shadow, prefix, |
| 2766 "\f\nMajor Mode Bindings", nomenu, 0, 0); | 2949 "\f\nMajor Mode Bindings", nomenu, 0, 0, 0); |
| 2767 else | 2950 else |
| 2768 describe_map_tree (start1, 1, shadow, prefix, | 2951 describe_map_tree (start1, 1, shadow, prefix, |
| 2769 "\f\n`local-map' Property Bindings", | 2952 "\f\n`local-map' Property Bindings", |
| 2770 nomenu, 0, 0); | 2953 nomenu, 0, 0, 0); |
| 2771 | 2954 |
| 2772 shadow = Fcons (start1, shadow); | 2955 shadow = Fcons (start1, shadow); |
| 2773 } | 2956 } |
| 2774 } | 2957 } |
| 2775 | 2958 |
| 2776 describe_map_tree (current_global_map, 1, shadow, prefix, | 2959 describe_map_tree (current_global_map, 1, shadow, prefix, |
| 2777 "\f\nGlobal Bindings", nomenu, 0, 1); | 2960 "\f\nGlobal Bindings", nomenu, 0, 1, 0); |
| 2778 | 2961 |
| 2779 /* Print the function-key-map translations under this prefix. */ | 2962 /* Print the function-key-map translations under this prefix. */ |
| 2780 if (!NILP (Vfunction_key_map)) | 2963 if (!NILP (Vfunction_key_map)) |
| 2781 describe_map_tree (Vfunction_key_map, 0, Qnil, prefix, | 2964 describe_map_tree (Vfunction_key_map, 0, Qnil, prefix, |
| 2782 "\f\nFunction key map translations", nomenu, 1, 0); | 2965 "\f\nFunction key map translations", nomenu, 1, 0, 0); |
| 2783 | 2966 |
| 2784 UNGCPRO; | 2967 UNGCPRO; |
| 2785 return Qnil; | 2968 return Qnil; |
| 2786 } | 2969 } |
| 2787 | 2970 |
| 2798 | 2981 |
| 2799 If TRANSL is nonzero, the definitions are actually key translations | 2982 If TRANSL is nonzero, the definitions are actually key translations |
| 2800 so print strings and vectors differently. | 2983 so print strings and vectors differently. |
| 2801 | 2984 |
| 2802 If ALWAYS_TITLE is nonzero, print the title even if there are no maps | 2985 If ALWAYS_TITLE is nonzero, print the title even if there are no maps |
| 2803 to look through. */ | 2986 to look through. |
| 2987 | |
| 2988 If MENTION_SHADOW is nonzero, then when something is shadowed by SHADOW, | |
| 2989 don't omit it; instead, mention it but say it is shadowed. */ | |
| 2804 | 2990 |
| 2805 void | 2991 void |
| 2806 describe_map_tree (startmap, partial, shadow, prefix, title, nomenu, transl, | 2992 describe_map_tree (startmap, partial, shadow, prefix, title, nomenu, transl, |
| 2807 always_title) | 2993 always_title, mention_shadow) |
| 2808 Lisp_Object startmap, shadow, prefix; | 2994 Lisp_Object startmap, shadow, prefix; |
| 2809 int partial; | 2995 int partial; |
| 2810 char *title; | 2996 char *title; |
| 2811 int nomenu; | 2997 int nomenu; |
| 2812 int transl; | 2998 int transl; |
| 2813 int always_title; | 2999 int always_title; |
| 3000 int mention_shadow; | |
| 2814 { | 3001 { |
| 2815 Lisp_Object maps, orig_maps, seen, sub_shadows; | 3002 Lisp_Object maps, orig_maps, seen, sub_shadows; |
| 2816 struct gcpro gcpro1, gcpro2, gcpro3; | 3003 struct gcpro gcpro1, gcpro2, gcpro3; |
| 2817 int something = 0; | 3004 int something = 0; |
| 2818 char *key_heading | 3005 char *key_heading |
| 2851 { | 3038 { |
| 2852 insert_string (title); | 3039 insert_string (title); |
| 2853 if (!NILP (prefix)) | 3040 if (!NILP (prefix)) |
| 2854 { | 3041 { |
| 2855 insert_string (" Starting With "); | 3042 insert_string (" Starting With "); |
| 2856 insert1 (Fkey_description (prefix)); | 3043 insert1 (Fkey_description (prefix, Qnil)); |
| 2857 } | 3044 } |
| 2858 insert_string (":\n"); | 3045 insert_string (":\n"); |
| 2859 } | 3046 } |
| 2860 insert_string (key_heading); | 3047 insert_string (key_heading); |
| 2861 something = 1; | 3048 something = 1; |
| 2910 sub_shadows = Fcons (XCDR (XCAR (tail)), sub_shadows); | 3097 sub_shadows = Fcons (XCDR (XCAR (tail)), sub_shadows); |
| 2911 } | 3098 } |
| 2912 | 3099 |
| 2913 describe_map (Fcdr (elt), prefix, | 3100 describe_map (Fcdr (elt), prefix, |
| 2914 transl ? describe_translation : describe_command, | 3101 transl ? describe_translation : describe_command, |
| 2915 partial, sub_shadows, &seen, nomenu); | 3102 partial, sub_shadows, &seen, nomenu, mention_shadow); |
| 2916 | 3103 |
| 2917 skip: ; | 3104 skip: ; |
| 2918 } | 3105 } |
| 2919 | 3106 |
| 2920 if (something) | 3107 if (something) |
| 2976 insert1 (tem1); | 3163 insert1 (tem1); |
| 2977 insert_string ("\n"); | 3164 insert_string ("\n"); |
| 2978 } | 3165 } |
| 2979 else if (STRINGP (definition) || VECTORP (definition)) | 3166 else if (STRINGP (definition) || VECTORP (definition)) |
| 2980 { | 3167 { |
| 2981 insert1 (Fkey_description (definition)); | 3168 insert1 (Fkey_description (definition, Qnil)); |
| 2982 insert_string ("\n"); | 3169 insert_string ("\n"); |
| 2983 } | 3170 } |
| 2984 else if (KEYMAPP (definition)) | 3171 else if (KEYMAPP (definition)) |
| 2985 insert_string ("Prefix Command\n"); | 3172 insert_string ("Prefix Command\n"); |
| 2986 else | 3173 else |
| 2987 insert_string ("??\n"); | 3174 insert_string ("??\n"); |
| 2988 } | 3175 } |
| 2989 | 3176 |
| 3177 /* describe_map puts all the usable elements of a sparse keymap | |
| 3178 into an array of `struct describe_map_elt', | |
| 3179 then sorts them by the events. */ | |
| 3180 | |
| 3181 struct describe_map_elt { Lisp_Object event; Lisp_Object definition; int shadowed; }; | |
| 3182 | |
| 3183 /* qsort comparison function for sorting `struct describe_map_elt' by | |
| 3184 the event field. */ | |
| 3185 | |
| 3186 static int | |
| 3187 describe_map_compare (aa, bb) | |
| 3188 const void *aa, *bb; | |
| 3189 { | |
| 3190 const struct describe_map_elt *a = aa, *b = bb; | |
| 3191 if (INTEGERP (a->event) && INTEGERP (b->event)) | |
| 3192 return ((XINT (a->event) > XINT (b->event)) | |
| 3193 - (XINT (a->event) < XINT (b->event))); | |
| 3194 if (!INTEGERP (a->event) && INTEGERP (b->event)) | |
| 3195 return 1; | |
| 3196 if (INTEGERP (a->event) && !INTEGERP (b->event)) | |
| 3197 return -1; | |
| 3198 if (SYMBOLP (a->event) && SYMBOLP (b->event)) | |
| 3199 return (!NILP (Fstring_lessp (a->event, b->event)) ? -1 | |
| 3200 : !NILP (Fstring_lessp (b->event, a->event)) ? 1 | |
| 3201 : 0); | |
| 3202 return 0; | |
| 3203 } | |
| 3204 | |
| 2990 /* Describe the contents of map MAP, assuming that this map itself is | 3205 /* Describe the contents of map MAP, assuming that this map itself is |
| 2991 reached by the sequence of prefix keys KEYS (a string or vector). | 3206 reached by the sequence of prefix keys PREFIX (a string or vector). |
| 2992 PARTIAL, SHADOW, NOMENU are as in `describe_map_tree' above. */ | 3207 PARTIAL, SHADOW, NOMENU are as in `describe_map_tree' above. */ |
| 2993 | 3208 |
| 2994 static void | 3209 static void |
| 2995 describe_map (map, keys, elt_describer, partial, shadow, seen, nomenu) | 3210 describe_map (map, prefix, elt_describer, partial, shadow, |
| 3211 seen, nomenu, mention_shadow) | |
| 2996 register Lisp_Object map; | 3212 register Lisp_Object map; |
| 2997 Lisp_Object keys; | 3213 Lisp_Object prefix; |
| 2998 void (*elt_describer) P_ ((Lisp_Object, Lisp_Object)); | 3214 void (*elt_describer) P_ ((Lisp_Object, Lisp_Object)); |
| 2999 int partial; | 3215 int partial; |
| 3000 Lisp_Object shadow; | 3216 Lisp_Object shadow; |
| 3001 Lisp_Object *seen; | 3217 Lisp_Object *seen; |
| 3002 int nomenu; | 3218 int nomenu; |
| 3003 { | 3219 int mention_shadow; |
| 3004 Lisp_Object elt_prefix; | 3220 { |
| 3005 Lisp_Object tail, definition, event; | 3221 Lisp_Object tail, definition, event; |
| 3006 Lisp_Object tem; | 3222 Lisp_Object tem; |
| 3007 Lisp_Object suppress; | 3223 Lisp_Object suppress; |
| 3008 Lisp_Object kludge; | 3224 Lisp_Object kludge; |
| 3009 int first = 1; | 3225 int first = 1; |
| 3010 struct gcpro gcpro1, gcpro2, gcpro3; | 3226 struct gcpro gcpro1, gcpro2, gcpro3; |
| 3011 | 3227 |
| 3228 /* These accumulate the values from sparse keymap bindings, | |
| 3229 so we can sort them and handle them in order. */ | |
| 3230 int length_needed = 0; | |
| 3231 struct describe_map_elt *vect; | |
| 3232 int slots_used = 0; | |
| 3233 int i; | |
| 3234 | |
| 3012 suppress = Qnil; | 3235 suppress = Qnil; |
| 3013 | |
| 3014 if (!NILP (keys) && XFASTINT (Flength (keys)) > 0) | |
| 3015 { | |
| 3016 /* Call Fkey_description first, to avoid GC bug for the other string. */ | |
| 3017 tem = Fkey_description (keys); | |
| 3018 elt_prefix = concat2 (tem, build_string (" ")); | |
| 3019 } | |
| 3020 else | |
| 3021 elt_prefix = Qnil; | |
| 3022 | 3236 |
| 3023 if (partial) | 3237 if (partial) |
| 3024 suppress = intern ("suppress-keymap"); | 3238 suppress = intern ("suppress-keymap"); |
| 3025 | 3239 |
| 3026 /* This vector gets used to present single keys to Flookup_key. Since | 3240 /* This vector gets used to present single keys to Flookup_key. Since |
| 3027 that is done once per keymap element, we don't want to cons up a | 3241 that is done once per keymap element, we don't want to cons up a |
| 3028 fresh vector every time. */ | 3242 fresh vector every time. */ |
| 3029 kludge = Fmake_vector (make_number (1), Qnil); | 3243 kludge = Fmake_vector (make_number (1), Qnil); |
| 3030 definition = Qnil; | 3244 definition = Qnil; |
| 3031 | 3245 |
| 3032 GCPRO3 (elt_prefix, definition, kludge); | 3246 for (tail = map; CONSP (tail); tail = XCDR (tail)) |
| 3247 length_needed++; | |
| 3248 | |
| 3249 vect = ((struct describe_map_elt *) | |
| 3250 alloca (sizeof (struct describe_map_elt) * length_needed)); | |
| 3251 | |
| 3252 GCPRO3 (prefix, definition, kludge); | |
| 3033 | 3253 |
| 3034 for (tail = map; CONSP (tail); tail = XCDR (tail)) | 3254 for (tail = map; CONSP (tail); tail = XCDR (tail)) |
| 3035 { | 3255 { |
| 3036 QUIT; | 3256 QUIT; |
| 3037 | 3257 |
| 3038 if (VECTORP (XCAR (tail)) | 3258 if (VECTORP (XCAR (tail)) |
| 3039 || CHAR_TABLE_P (XCAR (tail))) | 3259 || CHAR_TABLE_P (XCAR (tail))) |
| 3040 describe_vector (XCAR (tail), | 3260 describe_vector (XCAR (tail), |
| 3041 elt_prefix, Qnil, elt_describer, partial, shadow, map, | 3261 prefix, Qnil, elt_describer, partial, shadow, map, |
| 3042 (int *)0, 0); | 3262 (int *)0, 0, 1, mention_shadow); |
| 3043 else if (CONSP (XCAR (tail))) | 3263 else if (CONSP (XCAR (tail))) |
| 3044 { | 3264 { |
| 3265 int this_shadowed = 0; | |
| 3266 | |
| 3045 event = XCAR (XCAR (tail)); | 3267 event = XCAR (XCAR (tail)); |
| 3046 | 3268 |
| 3047 /* Ignore bindings whose "keys" are not really valid events. | 3269 /* Ignore bindings whose "prefix" are not really valid events. |
| 3048 (We get these in the frames and buffers menu.) */ | 3270 (We get these in the frames and buffers menu.) */ |
| 3049 if (!(SYMBOLP (event) || INTEGERP (event))) | 3271 if (!(SYMBOLP (event) || INTEGERP (event))) |
| 3050 continue; | 3272 continue; |
| 3051 | 3273 |
| 3052 if (nomenu && EQ (event, Qmenu_bar)) | 3274 if (nomenu && EQ (event, Qmenu_bar)) |
| 3068 | 3290 |
| 3069 ASET (kludge, 0, event); | 3291 ASET (kludge, 0, event); |
| 3070 if (!NILP (shadow)) | 3292 if (!NILP (shadow)) |
| 3071 { | 3293 { |
| 3072 tem = shadow_lookup (shadow, kludge, Qt); | 3294 tem = shadow_lookup (shadow, kludge, Qt); |
| 3073 if (!NILP (tem)) continue; | 3295 if (!NILP (tem)) |
| 3296 { | |
| 3297 if (mention_shadow) | |
| 3298 this_shadowed = 1; | |
| 3299 else | |
| 3300 continue; | |
| 3301 } | |
| 3074 } | 3302 } |
| 3075 | 3303 |
| 3076 tem = Flookup_key (map, kludge, Qt); | 3304 tem = Flookup_key (map, kludge, Qt); |
| 3077 if (!EQ (tem, definition)) continue; | 3305 if (!EQ (tem, definition)) continue; |
| 3078 | 3306 |
| 3079 if (first) | 3307 vect[slots_used].event = event; |
| 3080 { | 3308 vect[slots_used].definition = definition; |
| 3081 previous_description_column = 0; | 3309 vect[slots_used].shadowed = this_shadowed; |
| 3082 insert ("\n", 1); | 3310 slots_used++; |
| 3083 first = 0; | |
| 3084 } | |
| 3085 | |
| 3086 if (!NILP (elt_prefix)) | |
| 3087 insert1 (elt_prefix); | |
| 3088 | |
| 3089 /* THIS gets the string to describe the character EVENT. */ | |
| 3090 insert1 (Fsingle_key_description (event, Qnil)); | |
| 3091 | |
| 3092 /* Print a description of the definition of this character. | |
| 3093 elt_describer will take care of spacing out far enough | |
| 3094 for alignment purposes. */ | |
| 3095 (*elt_describer) (definition, Qnil); | |
| 3096 } | 3311 } |
| 3097 else if (EQ (XCAR (tail), Qkeymap)) | 3312 else if (EQ (XCAR (tail), Qkeymap)) |
| 3098 { | 3313 { |
| 3099 /* The same keymap might be in the structure twice, if we're | 3314 /* The same keymap might be in the structure twice, if we're |
| 3100 using an inherited keymap. So skip anything we've already | 3315 using an inherited keymap. So skip anything we've already |
| 3101 encountered. */ | 3316 encountered. */ |
| 3102 tem = Fassq (tail, *seen); | 3317 tem = Fassq (tail, *seen); |
| 3103 if (CONSP (tem) && !NILP (Fequal (XCAR (tem), keys))) | 3318 if (CONSP (tem) && !NILP (Fequal (XCAR (tem), prefix))) |
| 3104 break; | 3319 break; |
| 3105 *seen = Fcons (Fcons (tail, keys), *seen); | 3320 *seen = Fcons (Fcons (tail, prefix), *seen); |
| 3321 } | |
| 3322 } | |
| 3323 | |
| 3324 /* If we found some sparse map events, sort them. */ | |
| 3325 | |
| 3326 qsort (vect, slots_used, sizeof (struct describe_map_elt), | |
| 3327 describe_map_compare); | |
| 3328 | |
| 3329 /* Now output them in sorted order. */ | |
| 3330 | |
| 3331 for (i = 0; i < slots_used; i++) | |
| 3332 { | |
| 3333 Lisp_Object start, end; | |
| 3334 | |
| 3335 if (first) | |
| 3336 { | |
| 3337 previous_description_column = 0; | |
| 3338 insert ("\n", 1); | |
| 3339 first = 0; | |
| 3340 } | |
| 3341 | |
| 3342 ASET (kludge, 0, vect[i].event); | |
| 3343 start = vect[i].event; | |
| 3344 end = start; | |
| 3345 | |
| 3346 definition = vect[i].definition; | |
| 3347 | |
| 3348 /* Find consecutive chars that are identically defined. */ | |
| 3349 if (INTEGERP (vect[i].event)) | |
| 3350 { | |
| 3351 while (i + 1 < slots_used | |
| 3352 && XINT (vect[i + 1].event) == XINT (vect[i].event) + 1 | |
| 3353 && !NILP (Fequal (vect[i + 1].definition, definition)) | |
| 3354 && vect[i].shadowed == vect[i + 1].shadowed) | |
| 3355 i++; | |
| 3356 end = vect[i].event; | |
| 3357 } | |
| 3358 | |
| 3359 /* Now START .. END is the range to describe next. */ | |
| 3360 | |
| 3361 /* Insert the string to describe the event START. */ | |
| 3362 insert1 (Fkey_description (kludge, prefix)); | |
| 3363 | |
| 3364 if (!EQ (start, end)) | |
| 3365 { | |
| 3366 insert (" .. ", 4); | |
| 3367 | |
| 3368 ASET (kludge, 0, end); | |
| 3369 /* Insert the string to describe the character END. */ | |
| 3370 insert1 (Fkey_description (kludge, prefix)); | |
| 3371 } | |
| 3372 | |
| 3373 /* Print a description of the definition of this character. | |
| 3374 elt_describer will take care of spacing out far enough | |
| 3375 for alignment purposes. */ | |
| 3376 (*elt_describer) (vect[i].definition, Qnil); | |
| 3377 | |
| 3378 if (vect[i].shadowed) | |
| 3379 { | |
| 3380 SET_PT (PT - 1); | |
| 3381 insert_string (" (binding currently shadowed)"); | |
| 3382 SET_PT (PT + 1); | |
| 3106 } | 3383 } |
| 3107 } | 3384 } |
| 3108 | 3385 |
| 3109 UNGCPRO; | 3386 UNGCPRO; |
| 3110 } | 3387 } |
| 3118 Fterpri (Qnil); | 3395 Fterpri (Qnil); |
| 3119 } | 3396 } |
| 3120 | 3397 |
| 3121 DEFUN ("describe-vector", Fdescribe_vector, Sdescribe_vector, 1, 2, 0, | 3398 DEFUN ("describe-vector", Fdescribe_vector, Sdescribe_vector, 1, 2, 0, |
| 3122 doc: /* Insert a description of contents of VECTOR. | 3399 doc: /* Insert a description of contents of VECTOR. |
| 3123 This is text showing the elements of vector matched against indices. */) | 3400 This is text showing the elements of vector matched against indices. |
| 3401 DESCRIBER is the output function used; nil means use `princ'. */) | |
| 3124 (vector, describer) | 3402 (vector, describer) |
| 3125 Lisp_Object vector, describer; | 3403 Lisp_Object vector, describer; |
| 3126 { | 3404 { |
| 3127 int count = SPECPDL_INDEX (); | 3405 int count = SPECPDL_INDEX (); |
| 3128 if (NILP (describer)) | 3406 if (NILP (describer)) |
| 3129 describer = intern ("princ"); | 3407 describer = intern ("princ"); |
| 3130 specbind (Qstandard_output, Fcurrent_buffer ()); | 3408 specbind (Qstandard_output, Fcurrent_buffer ()); |
| 3131 CHECK_VECTOR_OR_CHAR_TABLE (vector); | 3409 CHECK_VECTOR_OR_CHAR_TABLE (vector); |
| 3132 describe_vector (vector, Qnil, describer, describe_vector_princ, 0, | 3410 describe_vector (vector, Qnil, describer, describe_vector_princ, 0, |
| 3133 Qnil, Qnil, (int *)0, 0); | 3411 Qnil, Qnil, (int *)0, 0, 0, 0); |
| 3134 | 3412 |
| 3135 return unbind_to (count, Qnil); | 3413 return unbind_to (count, Qnil); |
| 3136 } | 3414 } |
| 3137 | 3415 |
| 3138 /* Insert in the current buffer a description of the contents of VECTOR. | 3416 /* Insert in the current buffer a description of the contents of VECTOR. |
| 3163 | 3441 |
| 3164 When describing a sub-char-table, INDICES is a list of | 3442 When describing a sub-char-table, INDICES is a list of |
| 3165 indices at higher levels in this char-table, | 3443 indices at higher levels in this char-table, |
| 3166 and CHAR_TABLE_DEPTH says how many levels down we have gone. | 3444 and CHAR_TABLE_DEPTH says how many levels down we have gone. |
| 3167 | 3445 |
| 3446 KEYMAP_P is 1 if vector is known to be a keymap, so map ESC to M-. | |
| 3447 | |
| 3168 ARGS is simply passed as the second argument to ELT_DESCRIBER. */ | 3448 ARGS is simply passed as the second argument to ELT_DESCRIBER. */ |
| 3169 | 3449 |
| 3170 void | 3450 static void |
| 3171 describe_vector (vector, elt_prefix, args, elt_describer, | 3451 describe_vector (vector, prefix, args, elt_describer, |
| 3172 partial, shadow, entire_map, | 3452 partial, shadow, entire_map, |
| 3173 indices, char_table_depth) | 3453 indices, char_table_depth, keymap_p, |
| 3454 mention_shadow) | |
| 3174 register Lisp_Object vector; | 3455 register Lisp_Object vector; |
| 3175 Lisp_Object elt_prefix, args; | 3456 Lisp_Object prefix, args; |
| 3176 void (*elt_describer) P_ ((Lisp_Object, Lisp_Object)); | 3457 void (*elt_describer) P_ ((Lisp_Object, Lisp_Object)); |
| 3177 int partial; | 3458 int partial; |
| 3178 Lisp_Object shadow; | 3459 Lisp_Object shadow; |
| 3179 Lisp_Object entire_map; | 3460 Lisp_Object entire_map; |
| 3180 int *indices; | 3461 int *indices; |
| 3181 int char_table_depth; | 3462 int char_table_depth; |
| 3463 int keymap_p; | |
| 3464 int mention_shadow; | |
| 3182 { | 3465 { |
| 3183 Lisp_Object definition; | 3466 Lisp_Object definition; |
| 3184 Lisp_Object tem2; | 3467 Lisp_Object tem2; |
| 3468 Lisp_Object elt_prefix = Qnil; | |
| 3185 register int i; | 3469 register int i; |
| 3186 Lisp_Object suppress; | 3470 Lisp_Object suppress; |
| 3187 Lisp_Object kludge; | 3471 Lisp_Object kludge; |
| 3188 int first = 1; | 3472 int first = 1; |
| 3189 struct gcpro gcpro1, gcpro2, gcpro3; | 3473 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
| 3190 /* Range of elements to be handled. */ | 3474 /* Range of elements to be handled. */ |
| 3191 int from, to; | 3475 int from, to; |
| 3192 /* A flag to tell if a leaf in this level of char-table is not a | 3476 /* A flag to tell if a leaf in this level of char-table is not a |
| 3193 generic character (i.e. a complete multibyte character). */ | 3477 generic character (i.e. a complete multibyte character). */ |
| 3194 int complete_char; | 3478 int complete_char; |
| 3200 if (indices == 0) | 3484 if (indices == 0) |
| 3201 indices = (int *) alloca (3 * sizeof (int)); | 3485 indices = (int *) alloca (3 * sizeof (int)); |
| 3202 | 3486 |
| 3203 definition = Qnil; | 3487 definition = Qnil; |
| 3204 | 3488 |
| 3489 if (!keymap_p) | |
| 3490 { | |
| 3491 /* Call Fkey_description first, to avoid GC bug for the other string. */ | |
| 3492 if (!NILP (prefix) && XFASTINT (Flength (prefix)) > 0) | |
| 3493 { | |
| 3494 Lisp_Object tem; | |
| 3495 tem = Fkey_description (prefix, Qnil); | |
| 3496 elt_prefix = concat2 (tem, build_string (" ")); | |
| 3497 } | |
| 3498 prefix = Qnil; | |
| 3499 } | |
| 3500 | |
| 3205 /* This vector gets used to present single keys to Flookup_key. Since | 3501 /* This vector gets used to present single keys to Flookup_key. Since |
| 3206 that is done once per vector element, we don't want to cons up a | 3502 that is done once per vector element, we don't want to cons up a |
| 3207 fresh vector every time. */ | 3503 fresh vector every time. */ |
| 3208 kludge = Fmake_vector (make_number (1), Qnil); | 3504 kludge = Fmake_vector (make_number (1), Qnil); |
| 3209 GCPRO3 (elt_prefix, definition, kludge); | 3505 GCPRO4 (elt_prefix, prefix, definition, kludge); |
| 3210 | 3506 |
| 3211 if (partial) | 3507 if (partial) |
| 3212 suppress = intern ("suppress-keymap"); | 3508 suppress = intern ("suppress-keymap"); |
| 3213 | 3509 |
| 3214 if (CHAR_TABLE_P (vector)) | 3510 if (CHAR_TABLE_P (vector)) |
| 3247 to = XVECTOR (vector)->size; | 3543 to = XVECTOR (vector)->size; |
| 3248 } | 3544 } |
| 3249 | 3545 |
| 3250 for (i = from; i < to; i++) | 3546 for (i = from; i < to; i++) |
| 3251 { | 3547 { |
| 3548 int this_shadowed = 0; | |
| 3252 QUIT; | 3549 QUIT; |
| 3253 | 3550 |
| 3254 if (CHAR_TABLE_P (vector)) | 3551 if (CHAR_TABLE_P (vector)) |
| 3255 { | 3552 { |
| 3256 if (char_table_depth == 0 && i >= CHAR_TABLE_SINGLE_BYTE_SLOTS) | 3553 if (char_table_depth == 0 && i >= CHAR_TABLE_SINGLE_BYTE_SLOTS) |
| 3297 character = 0; | 3594 character = 0; |
| 3298 } | 3595 } |
| 3299 else | 3596 else |
| 3300 character = i; | 3597 character = i; |
| 3301 | 3598 |
| 3599 ASET (kludge, 0, make_number (character)); | |
| 3600 | |
| 3302 /* If this binding is shadowed by some other map, ignore it. */ | 3601 /* If this binding is shadowed by some other map, ignore it. */ |
| 3303 if (!NILP (shadow) && complete_char) | 3602 if (!NILP (shadow) && complete_char) |
| 3304 { | 3603 { |
| 3305 Lisp_Object tem; | 3604 Lisp_Object tem; |
| 3306 | 3605 |
| 3307 ASET (kludge, 0, make_number (character)); | |
| 3308 tem = shadow_lookup (shadow, kludge, Qt); | 3606 tem = shadow_lookup (shadow, kludge, Qt); |
| 3309 | 3607 |
| 3310 if (!NILP (tem)) continue; | 3608 if (!NILP (tem)) |
| 3609 { | |
| 3610 if (mention_shadow) | |
| 3611 this_shadowed = 1; | |
| 3612 else | |
| 3613 continue; | |
| 3614 } | |
| 3311 } | 3615 } |
| 3312 | 3616 |
| 3313 /* Ignore this definition if it is shadowed by an earlier | 3617 /* Ignore this definition if it is shadowed by an earlier |
| 3314 one in the same keymap. */ | 3618 one in the same keymap. */ |
| 3315 if (!NILP (entire_map) && complete_char) | 3619 if (!NILP (entire_map) && complete_char) |
| 3316 { | 3620 { |
| 3317 Lisp_Object tem; | 3621 Lisp_Object tem; |
| 3318 | 3622 |
| 3319 ASET (kludge, 0, make_number (character)); | |
| 3320 tem = Flookup_key (entire_map, kludge, Qt); | 3623 tem = Flookup_key (entire_map, kludge, Qt); |
| 3321 | 3624 |
| 3322 if (!EQ (tem, definition)) | 3625 if (!EQ (tem, definition)) |
| 3323 continue; | 3626 continue; |
| 3324 } | 3627 } |
| 3355 } | 3658 } |
| 3356 } | 3659 } |
| 3357 else if (CHAR_TABLE_P (vector)) | 3660 else if (CHAR_TABLE_P (vector)) |
| 3358 { | 3661 { |
| 3359 if (complete_char) | 3662 if (complete_char) |
| 3360 insert1 (Fsingle_key_description (make_number (character), Qnil)); | 3663 insert1 (Fkey_description (kludge, prefix)); |
| 3361 else | 3664 else |
| 3362 { | 3665 { |
| 3363 /* Print the information for this character set. */ | 3666 /* Print the information for this character set. */ |
| 3364 insert_string ("<"); | 3667 insert_string ("<"); |
| 3365 tem2 = CHARSET_TABLE_INFO (i - 128, CHARSET_SHORT_NAME_IDX); | 3668 tem2 = CHARSET_TABLE_INFO (i - 128, CHARSET_SHORT_NAME_IDX); |
| 3371 insert (">", 1); | 3674 insert (">", 1); |
| 3372 } | 3675 } |
| 3373 } | 3676 } |
| 3374 else | 3677 else |
| 3375 { | 3678 { |
| 3376 insert1 (Fsingle_key_description (make_number (character), Qnil)); | 3679 insert1 (Fkey_description (kludge, prefix)); |
| 3377 } | 3680 } |
| 3378 | 3681 |
| 3379 /* If we find a sub char-table within a char-table, | 3682 /* If we find a sub char-table within a char-table, |
| 3380 scan it recursively; it defines the details for | 3683 scan it recursively; it defines the details for |
| 3381 a character set or a portion of a character set. */ | 3684 a character set or a portion of a character set. */ |
| 3382 if (CHAR_TABLE_P (vector) && SUB_CHAR_TABLE_P (definition)) | 3685 if (CHAR_TABLE_P (vector) && SUB_CHAR_TABLE_P (definition)) |
| 3383 { | 3686 { |
| 3384 insert ("\n", 1); | 3687 insert ("\n", 1); |
| 3385 describe_vector (definition, elt_prefix, args, elt_describer, | 3688 describe_vector (definition, prefix, args, elt_describer, |
| 3386 partial, shadow, entire_map, | 3689 partial, shadow, entire_map, |
| 3387 indices, char_table_depth + 1); | 3690 indices, char_table_depth + 1, keymap_p, |
| 3691 mention_shadow); | |
| 3388 continue; | 3692 continue; |
| 3389 } | 3693 } |
| 3390 | 3694 |
| 3391 starting_i = i; | 3695 starting_i = i; |
| 3392 | 3696 |
| 3420 | 3724 |
| 3421 if (i != starting_i) | 3725 if (i != starting_i) |
| 3422 { | 3726 { |
| 3423 insert (" .. ", 4); | 3727 insert (" .. ", 4); |
| 3424 | 3728 |
| 3729 ASET (kludge, 0, make_number (i)); | |
| 3730 | |
| 3425 if (!NILP (elt_prefix)) | 3731 if (!NILP (elt_prefix)) |
| 3426 insert1 (elt_prefix); | 3732 insert1 (elt_prefix); |
| 3427 | 3733 |
| 3428 if (CHAR_TABLE_P (vector)) | 3734 if (CHAR_TABLE_P (vector)) |
| 3429 { | 3735 { |
| 3430 if (char_table_depth == 0) | 3736 if (char_table_depth == 0) |
| 3431 { | 3737 { |
| 3432 insert1 (Fsingle_key_description (make_number (i), Qnil)); | 3738 insert1 (Fkey_description (kludge, prefix)); |
| 3433 } | 3739 } |
| 3434 else if (complete_char) | 3740 else if (complete_char) |
| 3435 { | 3741 { |
| 3436 indices[char_table_depth] = i; | 3742 indices[char_table_depth] = i; |
| 3437 character = MAKE_CHAR (indices[0], indices[1], indices[2]); | 3743 character = MAKE_CHAR (indices[0], indices[1], indices[2]); |
| 3446 insert (work, strlen (work)); | 3752 insert (work, strlen (work)); |
| 3447 } | 3753 } |
| 3448 } | 3754 } |
| 3449 else | 3755 else |
| 3450 { | 3756 { |
| 3451 insert1 (Fsingle_key_description (make_number (i), Qnil)); | 3757 insert1 (Fkey_description (kludge, prefix)); |
| 3452 } | 3758 } |
| 3453 } | 3759 } |
| 3454 | 3760 |
| 3455 /* Print a description of the definition of this character. | 3761 /* Print a description of the definition of this character. |
| 3456 elt_describer will take care of spacing out far enough | 3762 elt_describer will take care of spacing out far enough |
| 3457 for alignment purposes. */ | 3763 for alignment purposes. */ |
| 3458 (*elt_describer) (definition, args); | 3764 (*elt_describer) (definition, args); |
| 3765 | |
| 3766 if (this_shadowed) | |
| 3767 { | |
| 3768 SET_PT (PT - 1); | |
| 3769 insert_string (" (binding currently shadowed)"); | |
| 3770 SET_PT (PT + 1); | |
| 3771 } | |
| 3459 } | 3772 } |
| 3460 | 3773 |
| 3461 /* For (sub) char-table, print `defalt' slot at last. */ | 3774 /* For (sub) char-table, print `defalt' slot at last. */ |
| 3462 if (CHAR_TABLE_P (vector) && !NILP (XCHAR_TABLE (vector)->defalt)) | 3775 if (CHAR_TABLE_P (vector) && !NILP (XCHAR_TABLE (vector)->defalt)) |
| 3463 { | 3776 { |
| 3493 Return list of symbols found. */) | 3806 Return list of symbols found. */) |
| 3494 (regexp, predicate) | 3807 (regexp, predicate) |
| 3495 Lisp_Object regexp, predicate; | 3808 Lisp_Object regexp, predicate; |
| 3496 { | 3809 { |
| 3497 Lisp_Object tem; | 3810 Lisp_Object tem; |
| 3498 struct gcpro gcpro1, gcpro2; | |
| 3499 CHECK_STRING (regexp); | 3811 CHECK_STRING (regexp); |
| 3500 apropos_predicate = predicate; | 3812 apropos_predicate = predicate; |
| 3501 apropos_accumulate = Qnil; | 3813 apropos_accumulate = Qnil; |
| 3502 map_obarray (Vobarray, apropos_accum, regexp); | 3814 map_obarray (Vobarray, apropos_accum, regexp); |
| 3503 tem = Fsort (apropos_accumulate, Qstring_lessp); | 3815 tem = Fsort (apropos_accumulate, Qstring_lessp); |
| 3566 DEFVAR_LISP ("minibuffer-local-completion-map", &Vminibuffer_local_completion_map, | 3878 DEFVAR_LISP ("minibuffer-local-completion-map", &Vminibuffer_local_completion_map, |
| 3567 doc: /* Local keymap for minibuffer input with completion. */); | 3879 doc: /* Local keymap for minibuffer input with completion. */); |
| 3568 Vminibuffer_local_completion_map = Fmake_sparse_keymap (Qnil); | 3880 Vminibuffer_local_completion_map = Fmake_sparse_keymap (Qnil); |
| 3569 Fset_keymap_parent (Vminibuffer_local_completion_map, Vminibuffer_local_map); | 3881 Fset_keymap_parent (Vminibuffer_local_completion_map, Vminibuffer_local_map); |
| 3570 | 3882 |
| 3883 DEFVAR_LISP ("minibuffer-local-filename-completion-map", | |
| 3884 &Vminibuffer_local_filename_completion_map, | |
| 3885 doc: /* Local keymap for minibuffer input with completion for filenames. */); | |
| 3886 Vminibuffer_local_filename_completion_map = Fmake_sparse_keymap (Qnil); | |
| 3887 Fset_keymap_parent (Vminibuffer_local_filename_completion_map, | |
| 3888 Vminibuffer_local_completion_map); | |
| 3889 | |
| 3890 | |
| 3571 DEFVAR_LISP ("minibuffer-local-must-match-map", &Vminibuffer_local_must_match_map, | 3891 DEFVAR_LISP ("minibuffer-local-must-match-map", &Vminibuffer_local_must_match_map, |
| 3572 doc: /* Local keymap for minibuffer input with completion, for exact match. */); | 3892 doc: /* Local keymap for minibuffer input with completion, for exact match. */); |
| 3573 Vminibuffer_local_must_match_map = Fmake_sparse_keymap (Qnil); | 3893 Vminibuffer_local_must_match_map = Fmake_sparse_keymap (Qnil); |
| 3574 Fset_keymap_parent (Vminibuffer_local_must_match_map, | 3894 Fset_keymap_parent (Vminibuffer_local_must_match_map, |
| 3575 Vminibuffer_local_completion_map); | 3895 Vminibuffer_local_completion_map); |
| 3896 | |
| 3897 DEFVAR_LISP ("minibuffer-local-must-match-filename-map", | |
| 3898 &Vminibuffer_local_must_match_filename_map, | |
| 3899 doc: /* Local keymap for minibuffer input with completion for filenames with exact match. */); | |
| 3900 Vminibuffer_local_must_match_filename_map = Fmake_sparse_keymap (Qnil); | |
| 3901 Fset_keymap_parent (Vminibuffer_local_must_match_filename_map, | |
| 3902 Vminibuffer_local_must_match_map); | |
| 3576 | 3903 |
| 3577 DEFVAR_LISP ("minor-mode-map-alist", &Vminor_mode_map_alist, | 3904 DEFVAR_LISP ("minor-mode-map-alist", &Vminor_mode_map_alist, |
| 3578 doc: /* Alist of keymaps to use for minor modes. | 3905 doc: /* Alist of keymaps to use for minor modes. |
| 3579 Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read | 3906 Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read |
| 3580 key sequences and look up bindings iff VARIABLE's value is non-nil. | 3907 key sequences and look up bindings iff VARIABLE's value is non-nil. |
| 3598 `minor-mode-map-alist' and `minor-mode-overriding-map-alist'. */); | 3925 `minor-mode-map-alist' and `minor-mode-overriding-map-alist'. */); |
| 3599 Vemulation_mode_map_alists = Qnil; | 3926 Vemulation_mode_map_alists = Qnil; |
| 3600 | 3927 |
| 3601 | 3928 |
| 3602 DEFVAR_LISP ("function-key-map", &Vfunction_key_map, | 3929 DEFVAR_LISP ("function-key-map", &Vfunction_key_map, |
| 3603 doc: /* Keymap mapping ASCII function key sequences onto their preferred forms. | 3930 doc: /* Keymap that translates key sequences to key sequences during input. |
| 3604 This allows Emacs to recognize function keys sent from ASCII | 3931 This is used mainly for mapping ASCII function key sequences into |
| 3605 terminals at any point in a key sequence. | 3932 real Emacs function key events (symbols). |
| 3606 | 3933 |
| 3607 The `read-key-sequence' function replaces any subsequence bound by | 3934 The `read-key-sequence' function replaces any subsequence bound by |
| 3608 `function-key-map' with its binding. More precisely, when the active | 3935 `function-key-map' with its binding. More precisely, when the active |
| 3609 keymaps have no binding for the current key sequence but | 3936 keymaps have no binding for the current key sequence but |
| 3610 `function-key-map' binds a suffix of the sequence to a vector or string, | 3937 `function-key-map' binds a suffix of the sequence to a vector or string, |
| 3611 `read-key-sequence' replaces the matching suffix with its binding, and | 3938 `read-key-sequence' replaces the matching suffix with its binding, and |
| 3612 continues with the new sequence. | 3939 continues with the new sequence. |
| 3613 | 3940 |
| 3941 If the binding is a function, it is called with one argument (the prompt) | |
| 3942 and its return value (a key sequence) is used. | |
| 3943 | |
| 3614 The events that come from bindings in `function-key-map' are not | 3944 The events that come from bindings in `function-key-map' are not |
| 3615 themselves looked up in `function-key-map'. | 3945 themselves looked up in `function-key-map'. |
| 3616 | 3946 |
| 3617 For example, suppose `function-key-map' binds `ESC O P' to [f1]. | 3947 For example, suppose `function-key-map' binds `ESC O P' to [f1]. |
| 3618 Typing `ESC O P' to `read-key-sequence' would return [f1]. Typing | 3948 Typing `ESC O P' to `read-key-sequence' would return [f1]. Typing |
| 3621 Vfunction_key_map = Fmake_sparse_keymap (Qnil); | 3951 Vfunction_key_map = Fmake_sparse_keymap (Qnil); |
| 3622 | 3952 |
| 3623 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map, | 3953 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map, |
| 3624 doc: /* Keymap of key translations that can override keymaps. | 3954 doc: /* Keymap of key translations that can override keymaps. |
| 3625 This keymap works like `function-key-map', but comes after that, | 3955 This keymap works like `function-key-map', but comes after that, |
| 3626 and applies even for keys that have ordinary bindings. */); | 3956 and its non-prefix bindings override ordinary bindings. */); |
| 3627 Vkey_translation_map = Qnil; | 3957 Vkey_translation_map = Qnil; |
| 3958 | |
| 3959 staticpro (&Vmouse_events); | |
| 3960 Vmouse_events = Fcons (intern ("menu-bar"), | |
| 3961 Fcons (intern ("tool-bar"), | |
| 3962 Fcons (intern ("header-line"), | |
| 3963 Fcons (intern ("mode-line"), | |
| 3964 Fcons (intern ("mouse-1"), | |
| 3965 Fcons (intern ("mouse-2"), | |
| 3966 Fcons (intern ("mouse-3"), | |
| 3967 Fcons (intern ("mouse-4"), | |
| 3968 Fcons (intern ("mouse-5"), | |
| 3969 Qnil))))))))); | |
| 3970 | |
| 3628 | 3971 |
| 3629 Qsingle_key_description = intern ("single-key-description"); | 3972 Qsingle_key_description = intern ("single-key-description"); |
| 3630 staticpro (&Qsingle_key_description); | 3973 staticpro (&Qsingle_key_description); |
| 3631 | 3974 |
| 3632 Qkey_description = intern ("key-description"); | 3975 Qkey_description = intern ("key-description"); |
| 3656 defsubr (&Skeymap_parent); | 3999 defsubr (&Skeymap_parent); |
| 3657 defsubr (&Skeymap_prompt); | 4000 defsubr (&Skeymap_prompt); |
| 3658 defsubr (&Sset_keymap_parent); | 4001 defsubr (&Sset_keymap_parent); |
| 3659 defsubr (&Smake_keymap); | 4002 defsubr (&Smake_keymap); |
| 3660 defsubr (&Smake_sparse_keymap); | 4003 defsubr (&Smake_sparse_keymap); |
| 4004 defsubr (&Smap_keymap); | |
| 3661 defsubr (&Scopy_keymap); | 4005 defsubr (&Scopy_keymap); |
| 3662 defsubr (&Scommand_remapping); | 4006 defsubr (&Scommand_remapping); |
| 3663 defsubr (&Skey_binding); | 4007 defsubr (&Skey_binding); |
| 3664 defsubr (&Slocal_key_binding); | 4008 defsubr (&Slocal_key_binding); |
| 3665 defsubr (&Sglobal_key_binding); | 4009 defsubr (&Sglobal_key_binding); |
| 3687 keys_of_keymap () | 4031 keys_of_keymap () |
| 3688 { | 4032 { |
| 3689 initial_define_key (global_map, 033, "ESC-prefix"); | 4033 initial_define_key (global_map, 033, "ESC-prefix"); |
| 3690 initial_define_key (global_map, Ctl('X'), "Control-X-prefix"); | 4034 initial_define_key (global_map, Ctl('X'), "Control-X-prefix"); |
| 3691 } | 4035 } |
| 4036 | |
| 4037 /* arch-tag: 6dd15c26-7cf1-41c4-b904-f42f7ddda463 | |
| 4038 (do not change this comment) */ |
