aboutsummaryrefslogtreecommitdiffstats
path: root/src/keymap.c
diff options
context:
space:
mode:
authorRichard M. Stallman1994-06-21 19:46:07 +0000
committerRichard M. Stallman1994-06-21 19:46:07 +0000
commit21a0d7a0004522005fa603ab331de2c650ee9b7a (patch)
tree8342c5a9042e970ba056a6d7c8a47f73c141452b /src/keymap.c
parent8c512fcb00bacdf3a698db9a388ea9e0abd96eae (diff)
downloademacs-21a0d7a0004522005fa603ab331de2c650ee9b7a.tar.gz
emacs-21a0d7a0004522005fa603ab331de2c650ee9b7a.zip
(Flookup_key): Add gcpro.
(Fkey_binding, Fminor_mode_key_binding): Likewise. (Fwhere_is_internal): Likewise.
Diffstat (limited to 'src/keymap.c')
-rw-r--r--src/keymap.c70
1 files changed, 58 insertions, 12 deletions
diff --git a/src/keymap.c b/src/keymap.c
index 4a928848694..3ae7d7e3608 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -188,6 +188,7 @@ is also allowed as an element.")
188 188
189 If AUTOLOAD is non-zero and OBJECT is a symbol whose function value 189 If AUTOLOAD is non-zero and OBJECT is a symbol whose function value
190 is an autoload form, do the autoload and try again. 190 is an autoload form, do the autoload and try again.
191 If AUTOLOAD is nonzero, callers must assume GC is possible.
191 192
192 ERROR controls how we respond if OBJECT isn't a keymap. 193 ERROR controls how we respond if OBJECT isn't a keymap.
193 If ERROR is non-zero, signal an error; otherwise, just return Qnil. 194 If ERROR is non-zero, signal an error; otherwise, just return Qnil.
@@ -552,6 +553,8 @@ is not copied.")
552 553
553/* Simple Keymap mutators and accessors. */ 554/* Simple Keymap mutators and accessors. */
554 555
556/* GC is possible in this function if it autoloads a keymap. */
557
555DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0, 558DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0,
556 "Args KEYMAP, KEY, DEF. Define key sequence KEY, in KEYMAP, as DEF.\n\ 559 "Args KEYMAP, KEY, DEF. Define key sequence KEY, in KEYMAP, as DEF.\n\
557KEYMAP is a keymap. KEY is a string or a vector of symbols and characters\n\ 560KEYMAP is a keymap. KEY is a string or a vector of symbols and characters\n\
@@ -646,6 +649,7 @@ the front of KEYMAP.")
646} 649}
647 650
648/* Value is number if KEY is too long; NIL if valid but has no definition. */ 651/* Value is number if KEY is too long; NIL if valid but has no definition. */
652/* GC is possible in this function if it autoloads a keymap. */
649 653
650DEFUN ("lookup-key", Flookup_key, Slookup_key, 2, 3, 0, 654DEFUN ("lookup-key", Flookup_key, Slookup_key, 2, 3, 0,
651 "In keymap KEYMAP, look up key sequence KEY. Return the definition.\n\ 655 "In keymap KEYMAP, look up key sequence KEY. Return the definition.\n\
@@ -675,6 +679,7 @@ recognize the default bindings, just as `read-key-sequence' does.")
675 int length; 679 int length;
676 int t_ok = ! NILP (accept_default); 680 int t_ok = ! NILP (accept_default);
677 int meta_bit; 681 int meta_bit;
682 struct gcpro gcpro1;
678 683
679 keymap = get_keymap_1 (keymap, 1, 1); 684 keymap = get_keymap_1 (keymap, 1, 1);
680 685
@@ -691,6 +696,8 @@ recognize the default bindings, just as `read-key-sequence' does.")
691 else 696 else
692 meta_bit = 0x80; 697 meta_bit = 0x80;
693 698
699 GCPRO1 (key);
700
694 idx = 0; 701 idx = 0;
695 while (1) 702 while (1)
696 { 703 {
@@ -714,11 +721,11 @@ recognize the default bindings, just as `read-key-sequence' does.")
714 721
715 cmd = get_keyelt (access_keymap (keymap, c, t_ok, 0), 1); 722 cmd = get_keyelt (access_keymap (keymap, c, t_ok, 0), 1);
716 if (idx == length) 723 if (idx == length)
717 return cmd; 724 RETURN_UNGCPRO (cmd);
718 725
719 keymap = get_keymap_1 (cmd, 0, 1); 726 keymap = get_keymap_1 (cmd, 0, 1);
720 if (NILP (keymap)) 727 if (NILP (keymap))
721 return make_number (idx); 728 RETURN_UNGCPRO (make_number (idx));
722 729
723 QUIT; 730 QUIT;
724 } 731 }
@@ -859,6 +866,8 @@ current_minor_maps (modeptr, mapptr)
859 return i; 866 return i;
860} 867}
861 868
869/* GC is possible in this function if it autoloads a keymap. */
870
862DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 2, 0, 871DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 2, 0,
863 "Return the binding for command KEY in current keymaps.\n\ 872 "Return the binding for command KEY in current keymaps.\n\
864KEY is a string or vector, a sequence of keystrokes.\n\ 873KEY is a string or vector, a sequence of keystrokes.\n\
@@ -874,39 +883,48 @@ recognize the default bindings, just as `read-key-sequence' does.")
874{ 883{
875 Lisp_Object *maps, value; 884 Lisp_Object *maps, value;
876 int nmaps, i; 885 int nmaps, i;
886 struct gcpro gcpro1;
887
888 GCPRO1 (key);
877 889
878 if (!NILP (Voverriding_local_map)) 890 if (!NILP (Voverriding_local_map))
879 { 891 {
880 value = Flookup_key (Voverriding_local_map, key, accept_default); 892 value = Flookup_key (Voverriding_local_map, key, accept_default);
881 if (! NILP (value) && XTYPE (value) != Lisp_Int) 893 if (! NILP (value) && XTYPE (value) != Lisp_Int)
882 return value; 894 RETURN_UNGCPRO (value);
883 } 895 }
884 else 896 else
885 { 897 {
886 nmaps = current_minor_maps (0, &maps); 898 nmaps = current_minor_maps (0, &maps);
899 /* Note that all these maps are GCPRO'd
900 in the places where we found them. */
901
887 for (i = 0; i < nmaps; i++) 902 for (i = 0; i < nmaps; i++)
888 if (! NILP (maps[i])) 903 if (! NILP (maps[i]))
889 { 904 {
890 value = Flookup_key (maps[i], key, accept_default); 905 value = Flookup_key (maps[i], key, accept_default);
891 if (! NILP (value) && XTYPE (value) != Lisp_Int) 906 if (! NILP (value) && XTYPE (value) != Lisp_Int)
892 return value; 907 RETURN_UNGCPRO (value);
893 } 908 }
894 909
895 if (! NILP (current_buffer->keymap)) 910 if (! NILP (current_buffer->keymap))
896 { 911 {
897 value = Flookup_key (current_buffer->keymap, key, accept_default); 912 value = Flookup_key (current_buffer->keymap, key, accept_default);
898 if (! NILP (value) && XTYPE (value) != Lisp_Int) 913 if (! NILP (value) && XTYPE (value) != Lisp_Int)
899 return value; 914 RETURN_UNGCPRO (value);
900 } 915 }
901 } 916 }
902 917
903 value = Flookup_key (current_global_map, key, accept_default); 918 value = Flookup_key (current_global_map, key, accept_default);
919 UNGCPRO;
904 if (! NILP (value) && XTYPE (value) != Lisp_Int) 920 if (! NILP (value) && XTYPE (value) != Lisp_Int)
905 return value; 921 return value;
906 922
907 return Qnil; 923 return Qnil;
908} 924}
909 925
926/* GC is possible in this function if it autoloads a keymap. */
927
910DEFUN ("local-key-binding", Flocal_key_binding, Slocal_key_binding, 1, 2, 0, 928DEFUN ("local-key-binding", Flocal_key_binding, Slocal_key_binding, 1, 2, 0,
911 "Return the binding for command KEYS in current local keymap only.\n\ 929 "Return the binding for command KEYS in current local keymap only.\n\
912KEYS is a string, a sequence of keystrokes.\n\ 930KEYS is a string, a sequence of keystrokes.\n\
@@ -924,12 +942,14 @@ bindings; see the description of `lookup-key' for more details about this.")
924 return Flookup_key (map, keys, accept_default); 942 return Flookup_key (map, keys, accept_default);
925} 943}
926 944
945/* GC is possible in this function if it autoloads a keymap. */
946
927DEFUN ("global-key-binding", Fglobal_key_binding, Sglobal_key_binding, 1, 2, 0, 947DEFUN ("global-key-binding", Fglobal_key_binding, Sglobal_key_binding, 1, 2, 0,
928 "Return the binding for command KEYS in current global keymap only.\n\ 948 "Return the binding for command KEYS in current global keymap only.\n\
929KEYS is a string, a sequence of keystrokes.\n\ 949KEYS is a string, a sequence of keystrokes.\n\
930The binding is probably a symbol with a function definition.\n\ 950The binding is probably a symbol with a function definition.\n\
931This function's return values are the same as those of lookup-key\n\ 951This function's return values are the same as those of lookup-key\n\
932(which see).\n\ 952\(which see).\n\
933\n\ 953\n\
934If optional argument ACCEPT-DEFAULT is non-nil, recognize default\n\ 954If optional argument ACCEPT-DEFAULT is non-nil, recognize default\n\
935bindings; see the description of `lookup-key' for more details about this.") 955bindings; see the description of `lookup-key' for more details about this.")
@@ -939,6 +959,8 @@ bindings; see the description of `lookup-key' for more details about this.")
939 return Flookup_key (current_global_map, keys, accept_default); 959 return Flookup_key (current_global_map, keys, accept_default);
940} 960}
941 961
962/* GC is possible in this function if it autoloads a keymap. */
963
942DEFUN ("minor-mode-key-binding", Fminor_mode_key_binding, Sminor_mode_key_binding, 1, 2, 0, 964DEFUN ("minor-mode-key-binding", Fminor_mode_key_binding, Sminor_mode_key_binding, 1, 2, 0,
943 "Find the visible minor mode bindings of KEY.\n\ 965 "Find the visible minor mode bindings of KEY.\n\
944Return an alist of pairs (MODENAME . BINDING), where MODENAME is the\n\ 966Return an alist of pairs (MODENAME . BINDING), where MODENAME is the\n\
@@ -958,8 +980,14 @@ bindings; see the description of `lookup-key' for more details about this.")
958 int nmaps; 980 int nmaps;
959 Lisp_Object binding; 981 Lisp_Object binding;
960 int i, j; 982 int i, j;
983 struct gcpro gcpro1, gcpro2;
961 984
962 nmaps = current_minor_maps (&modes, &maps); 985 nmaps = current_minor_maps (&modes, &maps);
986 /* Note that all these maps are GCPRO'd
987 in the places where we found them. */
988
989 binding = Qnil;
990 GCPRO2 (key, binding);
963 991
964 for (i = j = 0; i < nmaps; i++) 992 for (i = j = 0; i < nmaps; i++)
965 if (! NILP (maps[i]) 993 if (! NILP (maps[i])
@@ -969,9 +997,10 @@ bindings; see the description of `lookup-key' for more details about this.")
969 if (! NILP (get_keymap (binding))) 997 if (! NILP (get_keymap (binding)))
970 maps[j++] = Fcons (modes[i], binding); 998 maps[j++] = Fcons (modes[i], binding);
971 else if (j == 0) 999 else if (j == 0)
972 return Fcons (Fcons (modes[i], binding), Qnil); 1000 RETURN_UNGCPRO (Fcons (Fcons (modes[i], binding), Qnil));
973 } 1001 }
974 1002
1003 UNGCPRO;
975 return Flist (j, maps); 1004 return Flist (j, maps);
976} 1005}
977 1006
@@ -1114,6 +1143,8 @@ DEFUN ("current-minor-mode-maps", Fcurrent_minor_mode_maps, Scurrent_minor_mode_
1114 1143
1115/* Help functions for describing and documenting keymaps. */ 1144/* Help functions for describing and documenting keymaps. */
1116 1145
1146/* This function cannot GC. */
1147
1117DEFUN ("accessible-keymaps", Faccessible_keymaps, Saccessible_keymaps, 1148DEFUN ("accessible-keymaps", Faccessible_keymaps, Saccessible_keymaps,
1118 1, 2, 0, 1149 1, 2, 0,
1119 "Find all keymaps accessible via prefix characters from KEYMAP.\n\ 1150 "Find all keymaps accessible via prefix characters from KEYMAP.\n\
@@ -1128,6 +1159,8 @@ then the value includes only maps for prefixes that start with PREFIX.")
1128 Lisp_Object maps, good_maps, tail; 1159 Lisp_Object maps, good_maps, tail;
1129 int prefixlen = 0; 1160 int prefixlen = 0;
1130 1161
1162 /* no need for gcpro because we don't autoload any keymaps. */
1163
1131 if (!NILP (prefix)) 1164 if (!NILP (prefix))
1132 prefixlen = XINT (Flength (prefix)); 1165 prefixlen = XINT (Flength (prefix));
1133 1166
@@ -1285,6 +1318,8 @@ then the value includes only maps for prefixes that start with PREFIX.")
1285 1318
1286Lisp_Object Qsingle_key_description, Qkey_description; 1319Lisp_Object Qsingle_key_description, Qkey_description;
1287 1320
1321/* This function cannot GC. */
1322
1288DEFUN ("key-description", Fkey_description, Skey_description, 1, 1, 0, 1323DEFUN ("key-description", Fkey_description, Skey_description, 1, 1, 0,
1289 "Return a pretty description of key-sequence KEYS.\n\ 1324 "Return a pretty description of key-sequence KEYS.\n\
1290Control characters turn into \"C-foo\" sequences, meta into \"M-foo\"\n\ 1325Control characters turn into \"C-foo\" sequences, meta into \"M-foo\"\n\
@@ -1439,6 +1474,8 @@ push_key_description (c, p)
1439 return p; 1474 return p;
1440} 1475}
1441 1476
1477/* This function cannot GC. */
1478
1442DEFUN ("single-key-description", Fsingle_key_description, Ssingle_key_description, 1, 1, 0, 1479DEFUN ("single-key-description", Fsingle_key_description, Ssingle_key_description, 1, 1, 0,
1443 "Return a pretty description of command character KEY.\n\ 1480 "Return a pretty description of command character KEY.\n\
1444Control characters turn into C-whatever, etc.") 1481Control characters turn into C-whatever, etc.")
@@ -1493,6 +1530,8 @@ push_text_char_description (c, p)
1493 return p; 1530 return p;
1494} 1531}
1495 1532
1533/* This function cannot GC. */
1534
1496DEFUN ("text-char-description", Ftext_char_description, Stext_char_description, 1, 1, 0, 1535DEFUN ("text-char-description", Ftext_char_description, Stext_char_description, 1, 1, 0,
1497 "Return a pretty description of file-character CHAR.\n\ 1536 "Return a pretty description of file-character CHAR.\n\
1498Control characters turn into \"^char\", etc.") 1537Control characters turn into \"^char\", etc.")
@@ -1534,6 +1573,8 @@ ascii_sequence_p (seq)
1534 1573
1535/* where-is - finding a command in a set of keymaps. */ 1574/* where-is - finding a command in a set of keymaps. */
1536 1575
1576/* This function can GC if Flookup_key autoloads any keymaps. */
1577
1537DEFUN ("where-is-internal", Fwhere_is_internal, Swhere_is_internal, 1, 4, 0, 1578DEFUN ("where-is-internal", Fwhere_is_internal, Swhere_is_internal, 1, 4, 0,
1538 "Return list of keys that invoke DEFINITION.\n\ 1579 "Return list of keys that invoke DEFINITION.\n\
1539If KEYMAP is non-nil, search only KEYMAP and the global keymap.\n\ 1580If KEYMAP is non-nil, search only KEYMAP and the global keymap.\n\
@@ -1553,9 +1594,10 @@ indirect definition itself.")
1553 Lisp_Object definition, keymap; 1594 Lisp_Object definition, keymap;
1554 Lisp_Object firstonly, noindirect; 1595 Lisp_Object firstonly, noindirect;
1555{ 1596{
1556 register Lisp_Object maps; 1597 Lisp_Object maps;
1557 Lisp_Object found; 1598 Lisp_Object found, sequence;
1558 int keymap_specified = !NILP (keymap); 1599 int keymap_specified = !NILP (keymap);
1600 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
1559 1601
1560 if (! keymap_specified) 1602 if (! keymap_specified)
1561 { 1603 {
@@ -1587,7 +1629,9 @@ indirect definition itself.")
1587 } 1629 }
1588 } 1630 }
1589 1631
1632 GCPRO5 (definition, keymap, maps, found, sequence);
1590 found = Qnil; 1633 found = Qnil;
1634 sequence = Qnil;
1591 1635
1592 for (; !NILP (maps); maps = Fcdr (maps)) 1636 for (; !NILP (maps); maps = Fcdr (maps))
1593 { 1637 {
@@ -1622,7 +1666,7 @@ indirect definition itself.")
1622 advance map to the next element until i indicates that we 1666 advance map to the next element until i indicates that we
1623 have finished off the vector. */ 1667 have finished off the vector. */
1624 1668
1625 Lisp_Object elt, key, binding, sequence; 1669 Lisp_Object elt, key, binding;
1626 elt = XCONS (map)->car; 1670 elt = XCONS (map)->car;
1627 1671
1628 QUIT; 1672 QUIT;
@@ -1731,12 +1775,14 @@ indirect definition itself.")
1731 nil, then we should return the first ascii-only binding 1775 nil, then we should return the first ascii-only binding
1732 we find. */ 1776 we find. */
1733 if (EQ (firstonly, Qnon_ascii)) 1777 if (EQ (firstonly, Qnon_ascii))
1734 return sequence; 1778 RETURN_UNGCPRO (sequence);
1735 else if (! NILP (firstonly) && ascii_sequence_p (sequence)) 1779 else if (! NILP (firstonly) && ascii_sequence_p (sequence))
1736 return sequence; 1780 RETURN_UNGCPRO (sequence);
1737 } 1781 }
1738 } 1782 }
1739 1783
1784 UNGCPRO;
1785
1740 found = Fnreverse (found); 1786 found = Fnreverse (found);
1741 1787
1742 /* firstonly may have been t, but we may have gone all the way through 1788 /* firstonly may have been t, but we may have gone all the way through