aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJim Blandy1993-02-14 14:38:43 +0000
committerJim Blandy1993-02-14 14:38:43 +0000
commit7c1402521d3bc33b9104b0ed1101b3f80fb0ce92 (patch)
tree64e9ce6e8b132b3243713e83fc0a89750da2a706 /src
parent39acc701e677d5054548bc3e3479560e83f52215 (diff)
downloademacs-7c1402521d3bc33b9104b0ed1101b3f80fb0ce92.tar.gz
emacs-7c1402521d3bc33b9104b0ed1101b3f80fb0ce92.zip
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Fglobal_key_binding, Fminor_mode_key_binding): Add a new optional argument ACCEPT_DEFAULT, to control whether this function sees bindings for t. (Fwhere_is_internal, describe_map_tree, describe_map_2, describe_vector): Pass the proper arguments to Flookup_key.
Diffstat (limited to 'src')
-rw-r--r--src/keymap.c83
1 files changed, 54 insertions, 29 deletions
diff --git a/src/keymap.c b/src/keymap.c
index e1b61f5db90..5cfb94fcb83 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -568,17 +568,25 @@ the front of KEYMAP.")
568 568
569/* Value is number if KEY is too long; NIL if valid but has no definition. */ 569/* Value is number if KEY is too long; NIL if valid but has no definition. */
570 570
571DEFUN ("lookup-key", Flookup_key, Slookup_key, 2, 2, 0, 571DEFUN ("lookup-key", Flookup_key, Slookup_key, 2, 3, 0,
572 "In keymap KEYMAP, look up key sequence KEY. Return the definition.\n\ 572 "In keymap KEYMAP, look up key sequence KEY. Return the definition.\n\
573nil means undefined. See doc of `define-key' for kinds of definitions.\n\ 573nil means undefined. See doc of `define-key' for kinds of definitions.\n\
574\n\
574A number as value means KEY is \"too long\";\n\ 575A number as value means KEY is \"too long\";\n\
575that is, characters or symbols in it except for the last one\n\ 576that is, characters or symbols in it except for the last one\n\
576fail to be a valid sequence of prefix characters in KEYMAP.\n\ 577fail to be a valid sequence of prefix characters in KEYMAP.\n\
577The number is how many characters at the front of KEY\n\ 578The number is how many characters at the front of KEY\n\
578it takes to reach a non-prefix command.") 579it takes to reach a non-prefix command.\n\
579 (keymap, key) 580\n\
581Normally, `lookup-key' ignores bindings for t, which act as default\n\
582bindings, used when nothing else in the keymap applies; this makes it\n\
583useable as a general function for probing keymaps. However, if the\n\
584third optional argument ACCEPT-DEFAULT is non-nil, `lookup-key' will\n\
585recognize the default bindings, just as `read-key-sequence' does.")
586 (keymap, key, accept_default)
580 register Lisp_Object keymap; 587 register Lisp_Object keymap;
581 Lisp_Object key; 588 Lisp_Object key;
589 Lisp_Object accept_default;
582{ 590{
583 register int idx; 591 register int idx;
584 register Lisp_Object tem; 592 register Lisp_Object tem;
@@ -586,6 +594,7 @@ it takes to reach a non-prefix command.")
586 register Lisp_Object c; 594 register Lisp_Object c;
587 int metized = 0; 595 int metized = 0;
588 int length; 596 int length;
597 int t_ok = ! NILP (accept_default);
589 598
590 keymap = get_keymap (keymap); 599 keymap = get_keymap (keymap);
591 600
@@ -618,7 +627,7 @@ it takes to reach a non-prefix command.")
618 idx++; 627 idx++;
619 } 628 }
620 629
621 cmd = get_keyelt (access_keymap (keymap, c, 0)); 630 cmd = get_keyelt (access_keymap (keymap, c, t_ok));
622 if (idx == length) 631 if (idx == length)
623 return cmd; 632 return cmd;
624 633
@@ -727,11 +736,17 @@ current_minor_maps (modeptr, mapptr)
727 return i; 736 return i;
728} 737}
729 738
730DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 1, 0, 739DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 2, 0,
731 "Return the binding for command KEY in current keymaps.\n\ 740 "Return the binding for command KEY in current keymaps.\n\
732KEY is a string, a sequence of keystrokes.\n\ 741KEY is a string or vector, a sequence of keystrokes.\n\
733The binding is probably a symbol with a function definition.") 742The binding is probably a symbol with a function definition.\n\
734 (key) 743\n\
744Normally, `key-binding' ignores bindings for t, which act as default\n\
745bindings, used when nothing else in the keymap applies; this makes it\n\
746useable as a general function for probing keymaps. However, if the\n\
747third optional argument ACCEPT-DEFAULT is non-nil, `key-binding' will\n\
748recognize the default bindings, just as `read-key-sequence' does.")
749 (key, accept_default)
735 Lisp_Object key; 750 Lisp_Object key;
736{ 751{
737 Lisp_Object *maps, value; 752 Lisp_Object *maps, value;
@@ -741,52 +756,58 @@ The binding is probably a symbol with a function definition.")
741 for (i = 0; i < nmaps; i++) 756 for (i = 0; i < nmaps; i++)
742 if (! NILP (maps[i])) 757 if (! NILP (maps[i]))
743 { 758 {
744 value = Flookup_key (maps[i], key); 759 value = Flookup_key (maps[i], key, accept_default);
745 if (! NILP (value) && XTYPE (value) != Lisp_Int) 760 if (! NILP (value) && XTYPE (value) != Lisp_Int)
746 return value; 761 return value;
747 } 762 }
748 763
749 if (! NILP (current_buffer->keymap)) 764 if (! NILP (current_buffer->keymap))
750 { 765 {
751 value = Flookup_key (current_buffer->keymap, key); 766 value = Flookup_key (current_buffer->keymap, key, accept_default);
752 if (! NILP (value) && XTYPE (value) != Lisp_Int) 767 if (! NILP (value) && XTYPE (value) != Lisp_Int)
753 return value; 768 return value;
754 } 769 }
755 770
756 value = Flookup_key (current_global_map, key); 771 value = Flookup_key (current_global_map, key, accept_default);
757 if (! NILP (value) && XTYPE (value) != Lisp_Int) 772 if (! NILP (value) && XTYPE (value) != Lisp_Int)
758 return value; 773 return value;
759 774
760 return Qnil; 775 return Qnil;
761} 776}
762 777
763DEFUN ("local-key-binding", Flocal_key_binding, Slocal_key_binding, 1, 1, 0, 778DEFUN ("local-key-binding", Flocal_key_binding, Slocal_key_binding, 1, 2, 0,
764 "Return the binding for command KEYS in current local keymap only.\n\ 779 "Return the binding for command KEYS in current local keymap only.\n\
765KEYS is a string, a sequence of keystrokes.\n\ 780KEYS is a string, a sequence of keystrokes.\n\
766The binding is probably a symbol with a function definition.") 781The binding is probably a symbol with a function definition.\n\
767 (keys) 782\n\
768 Lisp_Object keys; 783If optional argument ACCEPT-DEFAULT is non-nil, recognize default\n\
784bindings; see the description of `lookup-key' for more details about this.")
785 (keys, accept_default)
786 Lisp_Object keys, accept_default;
769{ 787{
770 register Lisp_Object map; 788 register Lisp_Object map;
771 map = current_buffer->keymap; 789 map = current_buffer->keymap;
772 if (NILP (map)) 790 if (NILP (map))
773 return Qnil; 791 return Qnil;
774 return Flookup_key (map, keys); 792 return Flookup_key (map, keys, accept_default);
775} 793}
776 794
777DEFUN ("global-key-binding", Fglobal_key_binding, Sglobal_key_binding, 1, 1, 0, 795DEFUN ("global-key-binding", Fglobal_key_binding, Sglobal_key_binding, 1, 2, 0,
778 "Return the binding for command KEYS in current global keymap only.\n\ 796 "Return the binding for command KEYS in current global keymap only.\n\
779KEYS is a string, a sequence of keystrokes.\n\ 797KEYS is a string, a sequence of keystrokes.\n\
780The binding is probably a symbol with a function definition.\n\ 798The binding is probably a symbol with a function definition.\n\
781This function's return values are the same as those of lookup-key\n\ 799This function's return values are the same as those of lookup-key\n\
782(which see).") 800(which see).\n\
783 (keys) 801\n\
784 Lisp_Object keys; 802If optional argument ACCEPT-DEFAULT is non-nil, recognize default\n\
803bindings; see the description of `lookup-key' for more details about this.")
804 (keys, accept_default)
805 Lisp_Object keys, accept_default;
785{ 806{
786 return Flookup_key (current_global_map, keys); 807 return Flookup_key (current_global_map, keys, accept_default);
787} 808}
788 809
789DEFUN ("minor-mode-key-binding", Fminor_mode_key_binding, Sminor_mode_key_binding, 1, 1, 0, 810DEFUN ("minor-mode-key-binding", Fminor_mode_key_binding, Sminor_mode_key_binding, 1, 2, 0,
790 "Find the visible minor mode bindings of KEY.\n\ 811 "Find the visible minor mode bindings of KEY.\n\
791Return an alist of pairs (MODENAME . BINDING), where MODENAME is the\n\ 812Return an alist of pairs (MODENAME . BINDING), where MODENAME is the\n\
792the symbol which names the minor mode binding KEY, and BINDING is\n\ 813the symbol which names the minor mode binding KEY, and BINDING is\n\
@@ -794,8 +815,12 @@ KEY's definition in that mode. In particular, if KEY has no\n\
794minor-mode bindings, return nil. If the first binding is a\n\ 815minor-mode bindings, return nil. If the first binding is a\n\
795non-prefix, all subsequent bindings will be omitted, since they would\n\ 816non-prefix, all subsequent bindings will be omitted, since they would\n\
796be ignored. Similarly, the list doesn't include non-prefix bindings\n\ 817be ignored. Similarly, the list doesn't include non-prefix bindings\n\
797that come after prefix bindings.") 818that come after prefix bindings.\n\
798 (key) 819\n\
820If optional argument ACCEPT-DEFAULT is non-nil, recognize default\n\
821bindings; see the description of `lookup-key' for more details about this.")
822 (key, accept_default)
823 Lisp_Object key, accept_default;
799{ 824{
800 Lisp_Object *modes, *maps; 825 Lisp_Object *modes, *maps;
801 int nmaps; 826 int nmaps;
@@ -806,7 +831,7 @@ that come after prefix bindings.")
806 831
807 for (i = j = 0; i < nmaps; i++) 832 for (i = j = 0; i < nmaps; i++)
808 if (! NILP (maps[i]) 833 if (! NILP (maps[i])
809 && ! NILP (binding = Flookup_key (maps[i], key)) 834 && ! NILP (binding = Flookup_key (maps[i], key, accept_default))
810 && XTYPE (binding) != Lisp_Int) 835 && XTYPE (binding) != Lisp_Int)
811 { 836 {
812 if (! NILP (get_keymap (binding))) 837 if (! NILP (get_keymap (binding)))
@@ -1362,7 +1387,7 @@ indirect definition itself.")
1362 means undefined. */ 1387 means undefined. */
1363 if (!NILP (local_keymap)) 1388 if (!NILP (local_keymap))
1364 { 1389 {
1365 binding = Flookup_key (local_keymap, sequence); 1390 binding = Flookup_key (local_keymap, sequence, Qnil);
1366 if (!NILP (binding) && XTYPE (binding) != Lisp_Int) 1391 if (!NILP (binding) && XTYPE (binding) != Lisp_Int)
1367 { 1392 {
1368 if (XTYPE (definition) == Lisp_Cons) 1393 if (XTYPE (definition) == Lisp_Cons)
@@ -1573,7 +1598,7 @@ describe_map_tree (startmap, partial, shadow)
1573 what we should use. */ 1598 what we should use. */
1574 else 1599 else
1575 { 1600 {
1576 sh = Flookup_key (shadow, Fcar (elt)); 1601 sh = Flookup_key (shadow, Fcar (elt), Qt);
1577 if (XTYPE (sh) == Lisp_Int) 1602 if (XTYPE (sh) == Lisp_Int)
1578 sh = Qnil; 1603 sh = Qnil;
1579 } 1604 }
@@ -1691,7 +1716,7 @@ describe_map_2 (keymap, elt_prefix, elt_describer, partial, shadow)
1691 Lisp_Object tem; 1716 Lisp_Object tem;
1692 1717
1693 XVECTOR (kludge)->contents[0] = tem1; 1718 XVECTOR (kludge)->contents[0] = tem1;
1694 tem = Flookup_key (shadow, kludge); 1719 tem = Flookup_key (shadow, kludge, Qt);
1695 if (!NILP (tem)) continue; 1720 if (!NILP (tem)) continue;
1696 } 1721 }
1697 1722
@@ -1784,7 +1809,7 @@ describe_vector (vector, elt_prefix, elt_describer, partial, shadow)
1784 Lisp_Object tem; 1809 Lisp_Object tem;
1785 1810
1786 XVECTOR (kludge)->contents[0] = make_number (i); 1811 XVECTOR (kludge)->contents[0] = make_number (i);
1787 tem = Flookup_key (shadow, kludge); 1812 tem = Flookup_key (shadow, kludge, Qt);
1788 1813
1789 if (!NILP (tem)) continue; 1814 if (!NILP (tem)) continue;
1790 } 1815 }