diff options
| author | Stefan Monnier | 2002-05-14 03:04:31 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2002-05-14 03:04:31 +0000 |
| commit | 31bea176a601dbd6a6ed3756057e5b78a791f5be (patch) | |
| tree | 8a451558423c9f3520d3fb6a0cc17fbf118be319 /src/keymap.c | |
| parent | cadc926b47906a4f37cfe8b2f2a7c7be106084fe (diff) | |
| download | emacs-31bea176a601dbd6a6ed3756057e5b78a791f5be.tar.gz emacs-31bea176a601dbd6a6ed3756057e5b78a791f5be.zip | |
(keymap_parent): New fun, extracted from Fkeymap_parent.
(Fkeymap_parent, keymap_memberp, fix_submap_inheritance): Use it.
(Fset_keymap_parent): Gcpro a bit more.
(access_keymap): Gcpro around meta_map call and around the main loop.
(get_keyelt): Gcpro when following indirect references.
(copy_keymap_item): New fun, extracted from Fcopy_keymap.
(copy_keymap_1, Fcopy_keymap): Use it. Don't copy the parent map.
(Fdefine_key, Flookup_key): Gcpro before calling get_keymap.
Remove useless ad-hoc remap code.
Diffstat (limited to 'src/keymap.c')
| -rw-r--r-- | src/keymap.c | 323 |
1 files changed, 153 insertions, 170 deletions
diff --git a/src/keymap.c b/src/keymap.c index a119a2fa49d..e68210cf81b 100644 --- a/src/keymap.c +++ b/src/keymap.c | |||
| @@ -273,11 +273,11 @@ get_keymap (object, error, autoload) | |||
| 273 | if (autoload) | 273 | if (autoload) |
| 274 | { | 274 | { |
| 275 | struct gcpro gcpro1, gcpro2; | 275 | struct gcpro gcpro1, gcpro2; |
| 276 | 276 | ||
| 277 | GCPRO2 (tem, object); | 277 | GCPRO2 (tem, object); |
| 278 | do_autoload (tem, object); | 278 | do_autoload (tem, object); |
| 279 | UNGCPRO; | 279 | UNGCPRO; |
| 280 | 280 | ||
| 281 | goto autoload_retry; | 281 | goto autoload_retry; |
| 282 | } | 282 | } |
| 283 | else | 283 | else |
| @@ -292,17 +292,17 @@ get_keymap (object, error, autoload) | |||
| 292 | return Qnil; | 292 | return Qnil; |
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | /* Return the parent map of the keymap MAP, or nil if it has none. | 295 | /* Return the parent map of KEYMAP, or nil if it has none. |
| 296 | We assume that MAP is a valid keymap. */ | 296 | We assume that KEYMAP is a valid keymap. */ |
| 297 | 297 | ||
| 298 | DEFUN ("keymap-parent", Fkeymap_parent, Skeymap_parent, 1, 1, 0, | 298 | Lisp_Object |
| 299 | doc: /* Return the parent keymap of KEYMAP. */) | 299 | keymap_parent (keymap, autoload) |
| 300 | (keymap) | ||
| 301 | Lisp_Object keymap; | 300 | Lisp_Object keymap; |
| 301 | int autoload; | ||
| 302 | { | 302 | { |
| 303 | Lisp_Object list; | 303 | Lisp_Object list; |
| 304 | 304 | ||
| 305 | keymap = get_keymap (keymap, 1, 1); | 305 | keymap = get_keymap (keymap, 1, autoload); |
| 306 | 306 | ||
| 307 | /* Skip past the initial element `keymap'. */ | 307 | /* Skip past the initial element `keymap'. */ |
| 308 | list = XCDR (keymap); | 308 | list = XCDR (keymap); |
| @@ -313,9 +313,16 @@ DEFUN ("keymap-parent", Fkeymap_parent, Skeymap_parent, 1, 1, 0, | |||
| 313 | return list; | 313 | return list; |
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | return get_keymap (list, 0, 1); | 316 | return get_keymap (list, 0, autoload); |
| 317 | } | 317 | } |
| 318 | 318 | ||
| 319 | DEFUN ("keymap-parent", Fkeymap_parent, Skeymap_parent, 1, 1, 0, | ||
| 320 | doc: /* Return the parent keymap of KEYMAP. */) | ||
| 321 | (keymap) | ||
| 322 | Lisp_Object keymap; | ||
| 323 | { | ||
| 324 | return keymap_parent (keymap, 1); | ||
| 325 | } | ||
| 319 | 326 | ||
| 320 | /* Check whether MAP is one of MAPS parents. */ | 327 | /* Check whether MAP is one of MAPS parents. */ |
| 321 | int | 328 | int |
| @@ -324,7 +331,7 @@ keymap_memberp (map, maps) | |||
| 324 | { | 331 | { |
| 325 | if (NILP (map)) return 0; | 332 | if (NILP (map)) return 0; |
| 326 | while (KEYMAPP (maps) && !EQ (map, maps)) | 333 | while (KEYMAPP (maps) && !EQ (map, maps)) |
| 327 | maps = Fkeymap_parent (maps); | 334 | maps = keymap_parent (maps, 0); |
| 328 | return (EQ (map, maps)); | 335 | return (EQ (map, maps)); |
| 329 | } | 336 | } |
| 330 | 337 | ||
| @@ -337,7 +344,7 @@ PARENT should be nil or another keymap. */) | |||
| 337 | Lisp_Object keymap, parent; | 344 | Lisp_Object keymap, parent; |
| 338 | { | 345 | { |
| 339 | Lisp_Object list, prev; | 346 | Lisp_Object list, prev; |
| 340 | struct gcpro gcpro1; | 347 | struct gcpro gcpro1, gcpro2; |
| 341 | int i; | 348 | int i; |
| 342 | 349 | ||
| 343 | /* Force a keymap flush for the next call to where-is. | 350 | /* Force a keymap flush for the next call to where-is. |
| @@ -349,9 +356,9 @@ PARENT should be nil or another keymap. */) | |||
| 349 | This is a very minor correctness (rather than safety) issue. */ | 356 | This is a very minor correctness (rather than safety) issue. */ |
| 350 | where_is_cache_keymaps = Qt; | 357 | where_is_cache_keymaps = Qt; |
| 351 | 358 | ||
| 359 | GCPRO2 (keymap, parent); | ||
| 352 | keymap = get_keymap (keymap, 1, 1); | 360 | keymap = get_keymap (keymap, 1, 1); |
| 353 | GCPRO1 (keymap); | 361 | |
| 354 | |||
| 355 | if (!NILP (parent)) | 362 | if (!NILP (parent)) |
| 356 | { | 363 | { |
| 357 | parent = get_keymap (parent, 1, 1); | 364 | parent = get_keymap (parent, 1, 1); |
| @@ -432,7 +439,7 @@ fix_submap_inheritance (map, event, submap) | |||
| 432 | if (!CONSP (submap)) | 439 | if (!CONSP (submap)) |
| 433 | return; | 440 | return; |
| 434 | 441 | ||
| 435 | map_parent = Fkeymap_parent (map); | 442 | map_parent = keymap_parent (map, 0); |
| 436 | if (!NILP (map_parent)) | 443 | if (!NILP (map_parent)) |
| 437 | parent_entry = | 444 | parent_entry = |
| 438 | get_keymap (access_keymap (map_parent, event, 0, 0, 0), 0, 0); | 445 | get_keymap (access_keymap (map_parent, event, 0, 0, 0), 0, 0); |
| @@ -452,7 +459,7 @@ fix_submap_inheritance (map, event, submap) | |||
| 452 | { | 459 | { |
| 453 | Lisp_Object tem; | 460 | Lisp_Object tem; |
| 454 | 461 | ||
| 455 | tem = Fkeymap_parent (submap_parent); | 462 | tem = keymap_parent (submap_parent, 0); |
| 456 | 463 | ||
| 457 | if (KEYMAPP (tem)) | 464 | if (KEYMAPP (tem)) |
| 458 | { | 465 | { |
| @@ -512,10 +519,13 @@ access_keymap (map, idx, t_ok, noinherit, autoload) | |||
| 512 | { | 519 | { |
| 513 | /* See if there is a meta-map. If there's none, there is | 520 | /* See if there is a meta-map. If there's none, there is |
| 514 | no binding for IDX, unless a default binding exists in MAP. */ | 521 | no binding for IDX, unless a default binding exists in MAP. */ |
| 515 | Lisp_Object meta_map = | 522 | struct gcpro gcpro1; |
| 516 | get_keymap (access_keymap (map, meta_prefix_char, | 523 | Lisp_Object meta_map; |
| 517 | t_ok, noinherit, autoload), | 524 | GCPRO1 (map); |
| 518 | 0, autoload); | 525 | meta_map = get_keymap (access_keymap (map, meta_prefix_char, |
| 526 | t_ok, noinherit, autoload), | ||
| 527 | 0, autoload); | ||
| 528 | UNGCPRO; | ||
| 519 | if (CONSP (meta_map)) | 529 | if (CONSP (meta_map)) |
| 520 | { | 530 | { |
| 521 | map = meta_map; | 531 | map = meta_map; |
| @@ -529,15 +539,15 @@ access_keymap (map, idx, t_ok, noinherit, autoload) | |||
| 529 | return Qnil; | 539 | return Qnil; |
| 530 | } | 540 | } |
| 531 | 541 | ||
| 542 | /* t_binding is where we put a default binding that applies, | ||
| 543 | to use in case we do not find a binding specifically | ||
| 544 | for this key sequence. */ | ||
| 532 | { | 545 | { |
| 533 | Lisp_Object tail; | 546 | Lisp_Object tail; |
| 547 | Lisp_Object t_binding = Qnil; | ||
| 548 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | ||
| 534 | 549 | ||
| 535 | /* t_binding is where we put a default binding that applies, | 550 | GCPRO4 (map, tail, idx, t_binding); |
| 536 | to use in case we do not find a binding specifically | ||
| 537 | for this key sequence. */ | ||
| 538 | |||
| 539 | Lisp_Object t_binding; | ||
| 540 | t_binding = Qnil; | ||
| 541 | 551 | ||
| 542 | /* If `t_ok' is 2, both `t' and generic-char bindings are accepted. | 552 | /* If `t_ok' is 2, both `t' and generic-char bindings are accepted. |
| 543 | If it is 1, only generic-char bindings are accepted. | 553 | If it is 1, only generic-char bindings are accepted. |
| @@ -557,7 +567,7 @@ access_keymap (map, idx, t_ok, noinherit, autoload) | |||
| 557 | /* If NOINHERIT, stop finding prefix definitions | 567 | /* If NOINHERIT, stop finding prefix definitions |
| 558 | after we pass a second occurrence of the `keymap' symbol. */ | 568 | after we pass a second occurrence of the `keymap' symbol. */ |
| 559 | if (noinherit && EQ (binding, Qkeymap)) | 569 | if (noinherit && EQ (binding, Qkeymap)) |
| 560 | return Qnil; | 570 | RETURN_UNGCPRO (Qnil); |
| 561 | } | 571 | } |
| 562 | else if (CONSP (binding)) | 572 | else if (CONSP (binding)) |
| 563 | { | 573 | { |
| @@ -621,11 +631,11 @@ access_keymap (map, idx, t_ok, noinherit, autoload) | |||
| 621 | val = get_keyelt (val, autoload); | 631 | val = get_keyelt (val, autoload); |
| 622 | if (KEYMAPP (val)) | 632 | if (KEYMAPP (val)) |
| 623 | fix_submap_inheritance (map, idx, val); | 633 | fix_submap_inheritance (map, idx, val); |
| 624 | return val; | 634 | RETURN_UNGCPRO (val); |
| 625 | } | 635 | } |
| 626 | QUIT; | 636 | QUIT; |
| 627 | } | 637 | } |
| 628 | 638 | UNGCPRO; | |
| 629 | return get_keyelt (t_binding, autoload); | 639 | return get_keyelt (t_binding, autoload); |
| 630 | } | 640 | } |
| 631 | } | 641 | } |
| @@ -644,7 +654,7 @@ access_keymap (map, idx, t_ok, noinherit, autoload) | |||
| 644 | 654 | ||
| 645 | Lisp_Object | 655 | Lisp_Object |
| 646 | get_keyelt (object, autoload) | 656 | get_keyelt (object, autoload) |
| 647 | register Lisp_Object object; | 657 | Lisp_Object object; |
| 648 | int autoload; | 658 | int autoload; |
| 649 | { | 659 | { |
| 650 | while (1) | 660 | while (1) |
| @@ -686,7 +696,7 @@ get_keyelt (object, autoload) | |||
| 686 | } | 696 | } |
| 687 | } | 697 | } |
| 688 | else | 698 | else |
| 689 | /* Invalid keymap */ | 699 | /* Invalid keymap. */ |
| 690 | return object; | 700 | return object; |
| 691 | } | 701 | } |
| 692 | 702 | ||
| @@ -713,8 +723,11 @@ get_keyelt (object, autoload) | |||
| 713 | /* If the contents are (KEYMAP . ELEMENT), go indirect. */ | 723 | /* If the contents are (KEYMAP . ELEMENT), go indirect. */ |
| 714 | else | 724 | else |
| 715 | { | 725 | { |
| 726 | struct gcpro gcpro1; | ||
| 716 | Lisp_Object map; | 727 | Lisp_Object map; |
| 728 | GCPRO1 (object); | ||
| 717 | map = get_keymap (Fcar_safe (object), 0, autoload); | 729 | map = get_keymap (Fcar_safe (object), 0, autoload); |
| 730 | UNGCPRO; | ||
| 718 | return (!CONSP (map) ? object /* Invalid keymap */ | 731 | return (!CONSP (map) ? object /* Invalid keymap */ |
| 719 | : access_keymap (map, Fcdr (object), 0, 0, autoload)); | 732 | : access_keymap (map, Fcdr (object), 0, 0, autoload)); |
| 720 | } | 733 | } |
| @@ -821,18 +834,91 @@ store_in_keymap (keymap, idx, def) | |||
| 821 | XSETCDR (insertion_point, | 834 | XSETCDR (insertion_point, |
| 822 | Fcons (Fcons (idx, def), XCDR (insertion_point))); | 835 | Fcons (Fcons (idx, def), XCDR (insertion_point))); |
| 823 | } | 836 | } |
| 824 | 837 | ||
| 825 | return def; | 838 | return def; |
| 826 | } | 839 | } |
| 827 | 840 | ||
| 828 | EXFUN (Fcopy_keymap, 1); | 841 | EXFUN (Fcopy_keymap, 1); |
| 829 | 842 | ||
| 843 | Lisp_Object | ||
| 844 | copy_keymap_item (elt) | ||
| 845 | Lisp_Object elt; | ||
| 846 | { | ||
| 847 | Lisp_Object res, tem; | ||
| 848 | |||
| 849 | if (!CONSP (elt)) | ||
| 850 | return elt; | ||
| 851 | |||
| 852 | res = tem = elt; | ||
| 853 | |||
| 854 | /* Is this a new format menu item. */ | ||
| 855 | if (EQ (XCAR (tem), Qmenu_item)) | ||
| 856 | { | ||
| 857 | /* Copy cell with menu-item marker. */ | ||
| 858 | res = elt = Fcons (XCAR (tem), XCDR (tem)); | ||
| 859 | tem = XCDR (elt); | ||
| 860 | if (CONSP (tem)) | ||
| 861 | { | ||
| 862 | /* Copy cell with menu-item name. */ | ||
| 863 | XSETCDR (elt, Fcons (XCAR (tem), XCDR (tem))); | ||
| 864 | elt = XCDR (elt); | ||
| 865 | tem = XCDR (elt); | ||
| 866 | } | ||
| 867 | if (CONSP (tem)) | ||
| 868 | { | ||
| 869 | /* Copy cell with binding and if the binding is a keymap, | ||
| 870 | copy that. */ | ||
| 871 | XSETCDR (elt, Fcons (XCAR (tem), XCDR (tem))); | ||
| 872 | elt = XCDR (elt); | ||
| 873 | tem = XCAR (elt); | ||
| 874 | if (CONSP (tem) && EQ (XCAR (tem), Qkeymap)) | ||
| 875 | XSETCAR (elt, Fcopy_keymap (tem)); | ||
| 876 | tem = XCDR (elt); | ||
| 877 | if (CONSP (tem) && CONSP (XCAR (tem))) | ||
| 878 | /* Delete cache for key equivalences. */ | ||
| 879 | XSETCDR (elt, XCDR (tem)); | ||
| 880 | } | ||
| 881 | } | ||
| 882 | else | ||
| 883 | { | ||
| 884 | /* It may be an old fomat menu item. | ||
| 885 | Skip the optional menu string. */ | ||
| 886 | if (STRINGP (XCAR (tem))) | ||
| 887 | { | ||
| 888 | /* Copy the cell, since copy-alist didn't go this deep. */ | ||
| 889 | res = elt = Fcons (XCAR (tem), XCDR (tem)); | ||
| 890 | tem = XCDR (elt); | ||
| 891 | /* Also skip the optional menu help string. */ | ||
| 892 | if (CONSP (tem) && STRINGP (XCAR (tem))) | ||
| 893 | { | ||
| 894 | XSETCDR (elt, Fcons (XCAR (tem), XCDR (tem))); | ||
| 895 | elt = XCDR (elt); | ||
| 896 | tem = XCDR (elt); | ||
| 897 | } | ||
| 898 | /* There may also be a list that caches key equivalences. | ||
| 899 | Just delete it for the new keymap. */ | ||
| 900 | if (CONSP (tem) | ||
| 901 | && CONSP (XCAR (tem)) | ||
| 902 | && (NILP (XCAR (XCAR (tem))) | ||
| 903 | || VECTORP (XCAR (XCAR (tem))))) | ||
| 904 | { | ||
| 905 | XSETCDR (elt, XCDR (tem)); | ||
| 906 | tem = XCDR (tem); | ||
| 907 | } | ||
| 908 | if (CONSP (tem) && EQ (XCAR (tem), Qkeymap)) | ||
| 909 | XSETCDR (elt, Fcopy_keymap (tem)); | ||
| 910 | } | ||
| 911 | else if (EQ (XCAR (tem), Qkeymap)) | ||
| 912 | res = Fcopy_keymap (elt); | ||
| 913 | } | ||
| 914 | return res; | ||
| 915 | } | ||
| 916 | |||
| 830 | void | 917 | void |
| 831 | copy_keymap_1 (chartable, idx, elt) | 918 | copy_keymap_1 (chartable, idx, elt) |
| 832 | Lisp_Object chartable, idx, elt; | 919 | Lisp_Object chartable, idx, elt; |
| 833 | { | 920 | { |
| 834 | if (CONSP (elt) && EQ (XCAR (elt), Qkeymap)) | 921 | Faset (chartable, idx, copy_keymap_item (elt)); |
| 835 | Faset (chartable, idx, Fcopy_keymap (elt)); | ||
| 836 | } | 922 | } |
| 837 | 923 | ||
| 838 | DEFUN ("copy-keymap", Fcopy_keymap, Scopy_keymap, 1, 1, 0, | 924 | DEFUN ("copy-keymap", Fcopy_keymap, Scopy_keymap, 1, 1, 0, |
| @@ -845,112 +931,34 @@ is not copied. */) | |||
| 845 | (keymap) | 931 | (keymap) |
| 846 | Lisp_Object keymap; | 932 | Lisp_Object keymap; |
| 847 | { | 933 | { |
| 848 | /* FIXME: This doesn't properly copy menu-items in vectors. */ | ||
| 849 | /* FIXME: This also copies the parent keymap. */ | ||
| 850 | |||
| 851 | register Lisp_Object copy, tail; | 934 | register Lisp_Object copy, tail; |
| 935 | keymap = get_keymap (keymap, 1, 0); | ||
| 936 | copy = tail = Fcons (Qkeymap, Qnil); | ||
| 937 | keymap = XCDR (keymap); /* Skip the `keymap' symbol. */ | ||
| 852 | 938 | ||
| 853 | copy = Fcopy_alist (get_keymap (keymap, 1, 0)); | 939 | while (CONSP (keymap) && !EQ (XCAR (keymap), Qkeymap)) |
| 854 | |||
| 855 | for (tail = copy; CONSP (tail); tail = XCDR (tail)) | ||
| 856 | { | 940 | { |
| 857 | Lisp_Object elt; | 941 | Lisp_Object elt = XCAR (keymap); |
| 858 | |||
| 859 | elt = XCAR (tail); | ||
| 860 | if (CHAR_TABLE_P (elt)) | 942 | if (CHAR_TABLE_P (elt)) |
| 861 | { | 943 | { |
| 862 | Lisp_Object indices[3]; | 944 | Lisp_Object indices[3]; |
| 863 | |||
| 864 | elt = Fcopy_sequence (elt); | 945 | elt = Fcopy_sequence (elt); |
| 865 | XSETCAR (tail, elt); | ||
| 866 | |||
| 867 | map_char_table (copy_keymap_1, Qnil, elt, elt, 0, indices); | 946 | map_char_table (copy_keymap_1, Qnil, elt, elt, 0, indices); |
| 868 | } | 947 | } |
| 869 | else if (VECTORP (elt)) | 948 | else if (VECTORP (elt)) |
| 870 | { | 949 | { |
| 871 | int i; | 950 | int i; |
| 872 | |||
| 873 | elt = Fcopy_sequence (elt); | 951 | elt = Fcopy_sequence (elt); |
| 874 | XSETCAR (tail, elt); | ||
| 875 | |||
| 876 | for (i = 0; i < ASIZE (elt); i++) | 952 | for (i = 0; i < ASIZE (elt); i++) |
| 877 | if (CONSP (AREF (elt, i)) && EQ (XCAR (AREF (elt, i)), Qkeymap)) | 953 | ASET (elt, i, copy_keymap_item (AREF (elt, i))); |
| 878 | ASET (elt, i, Fcopy_keymap (AREF (elt, i))); | ||
| 879 | } | ||
| 880 | else if (CONSP (elt) && CONSP (XCDR (elt))) | ||
| 881 | { | ||
| 882 | Lisp_Object tem; | ||
| 883 | tem = XCDR (elt); | ||
| 884 | |||
| 885 | /* Is this a new format menu item. */ | ||
| 886 | if (EQ (XCAR (tem),Qmenu_item)) | ||
| 887 | { | ||
| 888 | /* Copy cell with menu-item marker. */ | ||
| 889 | XSETCDR (elt, | ||
| 890 | Fcons (XCAR (tem), XCDR (tem))); | ||
| 891 | elt = XCDR (elt); | ||
| 892 | tem = XCDR (elt); | ||
| 893 | if (CONSP (tem)) | ||
| 894 | { | ||
| 895 | /* Copy cell with menu-item name. */ | ||
| 896 | XSETCDR (elt, | ||
| 897 | Fcons (XCAR (tem), XCDR (tem))); | ||
| 898 | elt = XCDR (elt); | ||
| 899 | tem = XCDR (elt); | ||
| 900 | }; | ||
| 901 | if (CONSP (tem)) | ||
| 902 | { | ||
| 903 | /* Copy cell with binding and if the binding is a keymap, | ||
| 904 | copy that. */ | ||
| 905 | XSETCDR (elt, | ||
| 906 | Fcons (XCAR (tem), XCDR (tem))); | ||
| 907 | elt = XCDR (elt); | ||
| 908 | tem = XCAR (elt); | ||
| 909 | if (CONSP (tem) && EQ (XCAR (tem), Qkeymap)) | ||
| 910 | XSETCAR (elt, Fcopy_keymap (tem)); | ||
| 911 | tem = XCDR (elt); | ||
| 912 | if (CONSP (tem) && CONSP (XCAR (tem))) | ||
| 913 | /* Delete cache for key equivalences. */ | ||
| 914 | XSETCDR (elt, XCDR (tem)); | ||
| 915 | } | ||
| 916 | } | ||
| 917 | else | ||
| 918 | { | ||
| 919 | /* It may be an old fomat menu item. | ||
| 920 | Skip the optional menu string. | ||
| 921 | */ | ||
| 922 | if (STRINGP (XCAR (tem))) | ||
| 923 | { | ||
| 924 | /* Copy the cell, since copy-alist didn't go this deep. */ | ||
| 925 | XSETCDR (elt, | ||
| 926 | Fcons (XCAR (tem), XCDR (tem))); | ||
| 927 | elt = XCDR (elt); | ||
| 928 | tem = XCDR (elt); | ||
| 929 | /* Also skip the optional menu help string. */ | ||
| 930 | if (CONSP (tem) && STRINGP (XCAR (tem))) | ||
| 931 | { | ||
| 932 | XSETCDR (elt, | ||
| 933 | Fcons (XCAR (tem), XCDR (tem))); | ||
| 934 | elt = XCDR (elt); | ||
| 935 | tem = XCDR (elt); | ||
| 936 | } | ||
| 937 | /* There may also be a list that caches key equivalences. | ||
| 938 | Just delete it for the new keymap. */ | ||
| 939 | if (CONSP (tem) | ||
| 940 | && CONSP (XCAR (tem)) | ||
| 941 | && (NILP (XCAR (XCAR (tem))) | ||
| 942 | || VECTORP (XCAR (XCAR (tem))))) | ||
| 943 | XSETCDR (elt, XCDR (tem)); | ||
| 944 | } | ||
| 945 | if (CONSP (elt) | ||
| 946 | && CONSP (XCDR (elt)) | ||
| 947 | && EQ (XCAR (XCDR (elt)), Qkeymap)) | ||
| 948 | XSETCDR (elt, Fcopy_keymap (XCDR (elt))); | ||
| 949 | } | ||
| 950 | |||
| 951 | } | 954 | } |
| 955 | else if (CONSP (elt)) | ||
| 956 | elt = Fcons (XCAR (elt), copy_keymap_item (XCDR (elt))); | ||
| 957 | XSETCDR (tail, Fcons (elt, Qnil)); | ||
| 958 | tail = XCDR (tail); | ||
| 959 | keymap = XCDR (keymap); | ||
| 952 | } | 960 | } |
| 953 | 961 | XSETCDR (tail, keymap); | |
| 954 | return copy; | 962 | return copy; |
| 955 | } | 963 | } |
| 956 | 964 | ||
| @@ -993,29 +1001,20 @@ the front of KEYMAP. */) | |||
| 993 | int length; | 1001 | int length; |
| 994 | struct gcpro gcpro1, gcpro2, gcpro3; | 1002 | struct gcpro gcpro1, gcpro2, gcpro3; |
| 995 | 1003 | ||
| 1004 | GCPRO3 (keymap, key, def); | ||
| 996 | keymap = get_keymap (keymap, 1, 1); | 1005 | keymap = get_keymap (keymap, 1, 1); |
| 997 | 1006 | ||
| 998 | if (!VECTORP (key) && !STRINGP (key)) | 1007 | if (!VECTORP (key) && !STRINGP (key)) |
| 999 | key = wrong_type_argument (Qarrayp, key); | 1008 | key = wrong_type_argument (Qarrayp, key); |
| 1000 | 1009 | ||
| 1001 | length = XFASTINT (Flength (key)); | 1010 | length = XFASTINT (Flength (key)); |
| 1002 | if (length == 0) | 1011 | if (length == 0) |
| 1003 | return Qnil; | 1012 | RETURN_UNGCPRO (Qnil); |
| 1004 | |||
| 1005 | /* Check for valid [remap COMMAND] bindings. */ | ||
| 1006 | if (VECTORP (key) && EQ (AREF (key, 0), Qremap) | ||
| 1007 | && (length != 2 || !SYMBOLP (AREF (key, 1)))) | ||
| 1008 | wrong_type_argument (Qvectorp, key); | ||
| 1009 | 1013 | ||
| 1010 | if (SYMBOLP (def) && !EQ (Vdefine_key_rebound_commands, Qt)) | 1014 | if (SYMBOLP (def) && !EQ (Vdefine_key_rebound_commands, Qt)) |
| 1011 | Vdefine_key_rebound_commands = Fcons (def, Vdefine_key_rebound_commands); | 1015 | Vdefine_key_rebound_commands = Fcons (def, Vdefine_key_rebound_commands); |
| 1012 | 1016 | ||
| 1013 | GCPRO3 (keymap, key, def); | 1017 | meta_bit = VECTORP (key) ? meta_modifier : 0x80; |
| 1014 | |||
| 1015 | if (VECTORP (key)) | ||
| 1016 | meta_bit = meta_modifier; | ||
| 1017 | else | ||
| 1018 | meta_bit = 0x80; | ||
| 1019 | 1018 | ||
| 1020 | idx = 0; | 1019 | idx = 0; |
| 1021 | while (1) | 1020 | while (1) |
| @@ -1073,7 +1072,6 @@ Returns nil if COMMAND is not remapped. */) | |||
| 1073 | (command) | 1072 | (command) |
| 1074 | Lisp_Object command; | 1073 | Lisp_Object command; |
| 1075 | { | 1074 | { |
| 1076 | /* This will GCPRO the command argument. */ | ||
| 1077 | ASET (remap_command_vector, 1, command); | 1075 | ASET (remap_command_vector, 1, command); |
| 1078 | return Fkey_binding (remap_command_vector, Qnil, Qt); | 1076 | return Fkey_binding (remap_command_vector, Qnil, Qt); |
| 1079 | } | 1077 | } |
| @@ -1097,7 +1095,7 @@ usable as a general function for probing keymaps. However, if the | |||
| 1097 | third optional argument ACCEPT-DEFAULT is non-nil, `lookup-key' will | 1095 | third optional argument ACCEPT-DEFAULT is non-nil, `lookup-key' will |
| 1098 | recognize the default bindings, just as `read-key-sequence' does. */) | 1096 | recognize the default bindings, just as `read-key-sequence' does. */) |
| 1099 | (keymap, key, accept_default) | 1097 | (keymap, key, accept_default) |
| 1100 | register Lisp_Object keymap; | 1098 | Lisp_Object keymap; |
| 1101 | Lisp_Object key; | 1099 | Lisp_Object key; |
| 1102 | Lisp_Object accept_default; | 1100 | Lisp_Object accept_default; |
| 1103 | { | 1101 | { |
| @@ -1106,32 +1104,17 @@ recognize the default bindings, just as `read-key-sequence' does. */) | |||
| 1106 | register Lisp_Object c; | 1104 | register Lisp_Object c; |
| 1107 | int length; | 1105 | int length; |
| 1108 | int t_ok = !NILP (accept_default); | 1106 | int t_ok = !NILP (accept_default); |
| 1109 | struct gcpro gcpro1; | 1107 | struct gcpro gcpro1, gcpro2; |
| 1110 | 1108 | ||
| 1109 | GCPRO2 (keymap, key); | ||
| 1111 | keymap = get_keymap (keymap, 1, 1); | 1110 | keymap = get_keymap (keymap, 1, 1); |
| 1112 | 1111 | ||
| 1113 | /* Perform command remapping initiated by Fremap_command directly. | ||
| 1114 | This is strictly not necessary, but it is faster and it returns | ||
| 1115 | nil instead of 1 if KEYMAP doesn't contain command remappings. */ | ||
| 1116 | if (EQ (key, remap_command_vector)) | ||
| 1117 | { | ||
| 1118 | /* KEY has format [remap COMMAND]. | ||
| 1119 | Lookup `remap' in KEYMAP; result is nil or a keymap containing | ||
| 1120 | command remappings. Then lookup COMMAND in that keymap. */ | ||
| 1121 | if ((keymap = access_keymap (keymap, Qremap, t_ok, 0, 1), !NILP (keymap)) | ||
| 1122 | && (keymap = get_keymap (keymap, 0, 1), CONSP (keymap))) | ||
| 1123 | return access_keymap (keymap, AREF (key, 1), t_ok, 0, 1); | ||
| 1124 | return Qnil; | ||
| 1125 | } | ||
| 1126 | |||
| 1127 | if (!VECTORP (key) && !STRINGP (key)) | 1112 | if (!VECTORP (key) && !STRINGP (key)) |
| 1128 | key = wrong_type_argument (Qarrayp, key); | 1113 | key = wrong_type_argument (Qarrayp, key); |
| 1129 | 1114 | ||
| 1130 | length = XFASTINT (Flength (key)); | 1115 | length = XFASTINT (Flength (key)); |
| 1131 | if (length == 0) | 1116 | if (length == 0) |
| 1132 | return keymap; | 1117 | RETURN_UNGCPRO (keymap); |
| 1133 | |||
| 1134 | GCPRO1 (key); | ||
| 1135 | 1118 | ||
| 1136 | idx = 0; | 1119 | idx = 0; |
| 1137 | while (1) | 1120 | while (1) |
| @@ -1413,7 +1396,7 @@ OLP if non-nil indicates that we should obey `overriding-local-map' and | |||
| 1413 | if (!NILP (local)) | 1396 | if (!NILP (local)) |
| 1414 | keymaps = Fcons (local, keymaps); | 1397 | keymaps = Fcons (local, keymaps); |
| 1415 | } | 1398 | } |
| 1416 | 1399 | ||
| 1417 | return keymaps; | 1400 | return keymaps; |
| 1418 | } | 1401 | } |
| 1419 | 1402 | ||
| @@ -1692,9 +1675,9 @@ accessible_keymaps_1 (key, cmd, maps, tail, thisseq, is_metized) | |||
| 1692 | int meta_bit = meta_modifier; | 1675 | int meta_bit = meta_modifier; |
| 1693 | Lisp_Object last = make_number (XINT (Flength (thisseq)) - 1); | 1676 | Lisp_Object last = make_number (XINT (Flength (thisseq)) - 1); |
| 1694 | tem = Fcopy_sequence (thisseq); | 1677 | tem = Fcopy_sequence (thisseq); |
| 1695 | 1678 | ||
| 1696 | Faset (tem, last, make_number (XINT (key) | meta_bit)); | 1679 | Faset (tem, last, make_number (XINT (key) | meta_bit)); |
| 1697 | 1680 | ||
| 1698 | /* This new sequence is the same length as | 1681 | /* This new sequence is the same length as |
| 1699 | thisseq, so stick it in the list right | 1682 | thisseq, so stick it in the list right |
| 1700 | after this one. */ | 1683 | after this one. */ |
| @@ -1830,13 +1813,13 @@ then the value includes only maps for prefixes that start with PREFIX. */) | |||
| 1830 | for (i = 0; i < ASIZE (elt); i++) | 1813 | for (i = 0; i < ASIZE (elt); i++) |
| 1831 | accessible_keymaps_1 (make_number (i), AREF (elt, i), | 1814 | accessible_keymaps_1 (make_number (i), AREF (elt, i), |
| 1832 | maps, tail, thisseq, is_metized); | 1815 | maps, tail, thisseq, is_metized); |
| 1833 | 1816 | ||
| 1834 | } | 1817 | } |
| 1835 | else if (CONSP (elt)) | 1818 | else if (CONSP (elt)) |
| 1836 | accessible_keymaps_1 (XCAR (elt), XCDR (elt), | 1819 | accessible_keymaps_1 (XCAR (elt), XCDR (elt), |
| 1837 | maps, tail, thisseq, | 1820 | maps, tail, thisseq, |
| 1838 | is_metized && INTEGERP (XCAR (elt))); | 1821 | is_metized && INTEGERP (XCAR (elt))); |
| 1839 | 1822 | ||
| 1840 | } | 1823 | } |
| 1841 | } | 1824 | } |
| 1842 | 1825 | ||
| @@ -1954,7 +1937,7 @@ push_key_description (c, p, force_multibyte) | |||
| 1954 | int force_multibyte; | 1937 | int force_multibyte; |
| 1955 | { | 1938 | { |
| 1956 | unsigned c2; | 1939 | unsigned c2; |
| 1957 | 1940 | ||
| 1958 | /* Clear all the meaningless bits above the meta bit. */ | 1941 | /* Clear all the meaningless bits above the meta bit. */ |
| 1959 | c &= meta_modifier | ~ - meta_modifier; | 1942 | c &= meta_modifier | ~ - meta_modifier; |
| 1960 | c2 = c & ~(alt_modifier | ctrl_modifier | hyper_modifier | 1943 | c2 = c & ~(alt_modifier | ctrl_modifier | hyper_modifier |
| @@ -2048,7 +2031,7 @@ push_key_description (c, p, force_multibyte) | |||
| 2048 | else | 2031 | else |
| 2049 | { | 2032 | { |
| 2050 | int valid_p = SINGLE_BYTE_CHAR_P (c) || char_valid_p (c, 0); | 2033 | int valid_p = SINGLE_BYTE_CHAR_P (c) || char_valid_p (c, 0); |
| 2051 | 2034 | ||
| 2052 | if (force_multibyte && valid_p) | 2035 | if (force_multibyte && valid_p) |
| 2053 | { | 2036 | { |
| 2054 | if (SINGLE_BYTE_CHAR_P (c)) | 2037 | if (SINGLE_BYTE_CHAR_P (c)) |
| @@ -2281,7 +2264,7 @@ where_is_internal (definition, keymaps, firstonly, noindirect, no_remap) | |||
| 2281 | Faccessible_keymaps (get_keymap (XCAR (found), 1, 0), Qnil)); | 2264 | Faccessible_keymaps (get_keymap (XCAR (found), 1, 0), Qnil)); |
| 2282 | found = XCDR (found); | 2265 | found = XCDR (found); |
| 2283 | } | 2266 | } |
| 2284 | 2267 | ||
| 2285 | GCPRO5 (definition, keymaps, maps, found, sequences); | 2268 | GCPRO5 (definition, keymaps, maps, found, sequences); |
| 2286 | found = Qnil; | 2269 | found = Qnil; |
| 2287 | sequences = Qnil; | 2270 | sequences = Qnil; |
| @@ -2310,7 +2293,7 @@ where_is_internal (definition, keymaps, firstonly, noindirect, no_remap) | |||
| 2310 | keymaps bound to `menu-bar' and `tool-bar' and other | 2293 | keymaps bound to `menu-bar' and `tool-bar' and other |
| 2311 | non-ascii prefixes like `C-down-mouse-2'. */ | 2294 | non-ascii prefixes like `C-down-mouse-2'. */ |
| 2312 | continue; | 2295 | continue; |
| 2313 | 2296 | ||
| 2314 | QUIT; | 2297 | QUIT; |
| 2315 | 2298 | ||
| 2316 | while (CONSP (map)) | 2299 | while (CONSP (map)) |
| @@ -2455,7 +2438,7 @@ where_is_internal (definition, keymaps, firstonly, noindirect, no_remap) | |||
| 2455 | return the best we could find. */ | 2438 | return the best we could find. */ |
| 2456 | if (!NILP (firstonly)) | 2439 | if (!NILP (firstonly)) |
| 2457 | return Fcar (found); | 2440 | return Fcar (found); |
| 2458 | 2441 | ||
| 2459 | return found; | 2442 | return found; |
| 2460 | } | 2443 | } |
| 2461 | 2444 | ||
| @@ -2514,7 +2497,7 @@ remapped command in the returned list. */) | |||
| 2514 | Lisp_Object args[2]; | 2497 | Lisp_Object args[2]; |
| 2515 | where_is_cache = Fmake_hash_table (0, args); | 2498 | where_is_cache = Fmake_hash_table (0, args); |
| 2516 | where_is_cache_keymaps = Qt; | 2499 | where_is_cache_keymaps = Qt; |
| 2517 | 2500 | ||
| 2518 | /* Fill in the cache. */ | 2501 | /* Fill in the cache. */ |
| 2519 | GCPRO5 (definition, keymaps, firstonly, noindirect, no_remap); | 2502 | GCPRO5 (definition, keymaps, firstonly, noindirect, no_remap); |
| 2520 | where_is_internal (definition, keymaps, firstonly, noindirect, no_remap); | 2503 | where_is_internal (definition, keymaps, firstonly, noindirect, no_remap); |
| @@ -2531,7 +2514,7 @@ remapped command in the returned list. */) | |||
| 2531 | defns = (Lisp_Object *) alloca (n * sizeof *defns); | 2514 | defns = (Lisp_Object *) alloca (n * sizeof *defns); |
| 2532 | for (i = 0; CONSP (sequences); sequences = XCDR (sequences)) | 2515 | for (i = 0; CONSP (sequences); sequences = XCDR (sequences)) |
| 2533 | defns[i++] = XCAR (sequences); | 2516 | defns[i++] = XCAR (sequences); |
| 2534 | 2517 | ||
| 2535 | /* Verify that the key bindings are not shadowed. Note that | 2518 | /* Verify that the key bindings are not shadowed. Note that |
| 2536 | the following can GC. */ | 2519 | the following can GC. */ |
| 2537 | GCPRO2 (definition, keymaps); | 2520 | GCPRO2 (definition, keymaps); |
| @@ -3315,7 +3298,7 @@ describe_vector (vector, elt_prefix, args, elt_describer, | |||
| 3315 | if (!NILP (shadow) && complete_char) | 3298 | if (!NILP (shadow) && complete_char) |
| 3316 | { | 3299 | { |
| 3317 | Lisp_Object tem; | 3300 | Lisp_Object tem; |
| 3318 | 3301 | ||
| 3319 | ASET (kludge, 0, make_number (character)); | 3302 | ASET (kludge, 0, make_number (character)); |
| 3320 | tem = shadow_lookup (shadow, kludge, Qt); | 3303 | tem = shadow_lookup (shadow, kludge, Qt); |
| 3321 | 3304 | ||
| @@ -3425,7 +3408,7 @@ describe_vector (vector, elt_prefix, args, elt_describer, | |||
| 3425 | !NILP (tem2)) | 3408 | !NILP (tem2)) |
| 3426 | && !NILP (Fequal (tem2, definition))) | 3409 | && !NILP (Fequal (tem2, definition))) |
| 3427 | i++; | 3410 | i++; |
| 3428 | 3411 | ||
| 3429 | 3412 | ||
| 3430 | /* If we have a range of more than one character, | 3413 | /* If we have a range of more than one character, |
| 3431 | print where the range reaches to. */ | 3414 | print where the range reaches to. */ |