aboutsummaryrefslogtreecommitdiffstats
path: root/src/keymap.c
diff options
context:
space:
mode:
authorJoakim Verona2012-05-30 14:08:12 +0200
committerJoakim Verona2012-05-30 14:08:12 +0200
commit70700d8c47a35b19e29607ac5f0ed322bdd78249 (patch)
tree4fa00d3fac00025354f0b6e23dcda1b58689a094 /src/keymap.c
parent44fce8ffe7198991c41c985ff4e67ec7d407907e (diff)
parent72cb32cf2f0938dd7dc733eed77b1ed1e497b053 (diff)
downloademacs-70700d8c47a35b19e29607ac5f0ed322bdd78249.tar.gz
emacs-70700d8c47a35b19e29607ac5f0ed322bdd78249.zip
upstream
Diffstat (limited to 'src/keymap.c')
-rw-r--r--src/keymap.c68
1 files changed, 43 insertions, 25 deletions
diff --git a/src/keymap.c b/src/keymap.c
index 9f82175edc0..2a03dda5a5e 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -1117,12 +1117,12 @@ binding is altered. If there is no binding for KEY, the new pair
1117binding KEY to DEF is added at the front of KEYMAP. */) 1117binding KEY to DEF is added at the front of KEYMAP. */)
1118 (Lisp_Object keymap, Lisp_Object key, Lisp_Object def) 1118 (Lisp_Object keymap, Lisp_Object key, Lisp_Object def)
1119{ 1119{
1120 register int idx; 1120 register ptrdiff_t idx;
1121 register Lisp_Object c; 1121 register Lisp_Object c;
1122 register Lisp_Object cmd; 1122 register Lisp_Object cmd;
1123 int metized = 0; 1123 int metized = 0;
1124 int meta_bit; 1124 int meta_bit;
1125 int length; 1125 ptrdiff_t length;
1126 struct gcpro gcpro1, gcpro2, gcpro3; 1126 struct gcpro gcpro1, gcpro2, gcpro3;
1127 1127
1128 GCPRO3 (keymap, key, def); 1128 GCPRO3 (keymap, key, def);
@@ -1143,7 +1143,7 @@ binding KEY to DEF is added at the front of KEYMAP. */)
1143 if (VECTORP (def) && ASIZE (def) > 0 && CONSP (AREF (def, 0))) 1143 if (VECTORP (def) && ASIZE (def) > 0 && CONSP (AREF (def, 0)))
1144 { /* DEF is apparently an XEmacs-style keyboard macro. */ 1144 { /* DEF is apparently an XEmacs-style keyboard macro. */
1145 Lisp_Object tmp = Fmake_vector (make_number (ASIZE (def)), Qnil); 1145 Lisp_Object tmp = Fmake_vector (make_number (ASIZE (def)), Qnil);
1146 int i = ASIZE (def); 1146 ptrdiff_t i = ASIZE (def);
1147 while (--i >= 0) 1147 while (--i >= 0)
1148 { 1148 {
1149 Lisp_Object defi = AREF (def, i); 1149 Lisp_Object defi = AREF (def, i);
@@ -1274,10 +1274,10 @@ third optional argument ACCEPT-DEFAULT is non-nil, `lookup-key' will
1274recognize the default bindings, just as `read-key-sequence' does. */) 1274recognize the default bindings, just as `read-key-sequence' does. */)
1275 (Lisp_Object keymap, Lisp_Object key, Lisp_Object accept_default) 1275 (Lisp_Object keymap, Lisp_Object key, Lisp_Object accept_default)
1276{ 1276{
1277 register int idx; 1277 register ptrdiff_t idx;
1278 register Lisp_Object cmd; 1278 register Lisp_Object cmd;
1279 register Lisp_Object c; 1279 register Lisp_Object c;
1280 int length; 1280 ptrdiff_t length;
1281 int t_ok = !NILP (accept_default); 1281 int t_ok = !NILP (accept_default);
1282 struct gcpro gcpro1, gcpro2; 1282 struct gcpro gcpro1, gcpro2;
1283 1283
@@ -1527,6 +1527,19 @@ current_minor_maps (Lisp_Object **modeptr, Lisp_Object **mapptr)
1527 return i; 1527 return i;
1528} 1528}
1529 1529
1530/* Return the offset of POSITION, a click position, in the style of
1531 the respective argument of Fkey_binding. */
1532static ptrdiff_t
1533click_position (Lisp_Object position)
1534{
1535 EMACS_INT pos = (INTEGERP (position) ? XINT (position)
1536 : MARKERP (position) ? marker_position (position)
1537 : PT);
1538 if (! (BEGV <= pos && pos <= ZV))
1539 args_out_of_range (Fcurrent_buffer (), position);
1540 return pos;
1541}
1542
1530DEFUN ("current-active-maps", Fcurrent_active_maps, Scurrent_active_maps, 1543DEFUN ("current-active-maps", Fcurrent_active_maps, Scurrent_active_maps,
1531 0, 2, 0, 1544 0, 2, 0,
1532 doc: /* Return a list of the currently active keymaps. 1545 doc: /* Return a list of the currently active keymaps.
@@ -1535,7 +1548,7 @@ OLP if non-nil indicates that we should obey `overriding-local-map' and
1535like in the respective argument of `key-binding'. */) 1548like in the respective argument of `key-binding'. */)
1536 (Lisp_Object olp, Lisp_Object position) 1549 (Lisp_Object olp, Lisp_Object position)
1537{ 1550{
1538 int count = SPECPDL_INDEX (); 1551 ptrdiff_t count = SPECPDL_INDEX ();
1539 1552
1540 Lisp_Object keymaps = Fcons (current_global_map, Qnil); 1553 Lisp_Object keymaps = Fcons (current_global_map, Qnil);
1541 1554
@@ -1582,10 +1595,7 @@ like in the respective argument of `key-binding'. */)
1582 { 1595 {
1583 Lisp_Object *maps; 1596 Lisp_Object *maps;
1584 int nmaps, i; 1597 int nmaps, i;
1585 EMACS_INT pt 1598 ptrdiff_t pt = click_position (position);
1586 = INTEGERP (position) ? XINT (position)
1587 : MARKERP (position) ? marker_position (position)
1588 : PT;
1589 /* This usually returns the buffer's local map, 1599 /* This usually returns the buffer's local map,
1590 but that can be overridden by a `local-map' property. */ 1600 but that can be overridden by a `local-map' property. */
1591 Lisp_Object local_map = get_local_map (pt, current_buffer, Qlocal_map); 1601 Lisp_Object local_map = get_local_map (pt, current_buffer, Qlocal_map);
@@ -1904,10 +1914,10 @@ accessible_keymaps_1 (Lisp_Object key, Lisp_Object cmd, Lisp_Object args, void *
1904 while (!NILP (tem = Frassq (cmd, maps))) 1914 while (!NILP (tem = Frassq (cmd, maps)))
1905 { 1915 {
1906 Lisp_Object prefix = XCAR (tem); 1916 Lisp_Object prefix = XCAR (tem);
1907 int lim = XINT (Flength (XCAR (tem))); 1917 ptrdiff_t lim = XINT (Flength (XCAR (tem)));
1908 if (lim <= XINT (Flength (thisseq))) 1918 if (lim <= XINT (Flength (thisseq)))
1909 { /* This keymap was already seen with a smaller prefix. */ 1919 { /* This keymap was already seen with a smaller prefix. */
1910 int i = 0; 1920 ptrdiff_t i = 0;
1911 while (i < lim && EQ (Faref (prefix, make_number (i)), 1921 while (i < lim && EQ (Faref (prefix, make_number (i)),
1912 Faref (thisseq, make_number (i)))) 1922 Faref (thisseq, make_number (i))))
1913 i++; 1923 i++;
@@ -1960,7 +1970,7 @@ then the value includes only maps for prefixes that start with PREFIX. */)
1960 (Lisp_Object keymap, Lisp_Object prefix) 1970 (Lisp_Object keymap, Lisp_Object prefix)
1961{ 1971{
1962 Lisp_Object maps, tail; 1972 Lisp_Object maps, tail;
1963 int prefixlen = XINT (Flength (prefix)); 1973 EMACS_INT prefixlen = XFASTINT (Flength (prefix));
1964 1974
1965 /* no need for gcpro because we don't autoload any keymaps. */ 1975 /* no need for gcpro because we don't autoload any keymaps. */
1966 1976
@@ -2048,20 +2058,25 @@ For example, [?\C-x ?l] is converted into the string \"C-x l\".
2048The `kbd' macro is an approximate inverse of this. */) 2058The `kbd' macro is an approximate inverse of this. */)
2049 (Lisp_Object keys, Lisp_Object prefix) 2059 (Lisp_Object keys, Lisp_Object prefix)
2050{ 2060{
2051 int len = 0; 2061 ptrdiff_t len = 0;
2052 int i, i_byte; 2062 EMACS_INT i;
2063 ptrdiff_t i_byte;
2053 Lisp_Object *args; 2064 Lisp_Object *args;
2054 int size = XINT (Flength (keys)); 2065 EMACS_INT size = XINT (Flength (keys));
2055 Lisp_Object list; 2066 Lisp_Object list;
2056 Lisp_Object sep = build_string (" "); 2067 Lisp_Object sep = build_string (" ");
2057 Lisp_Object key; 2068 Lisp_Object key;
2069 Lisp_Object result;
2058 int add_meta = 0; 2070 int add_meta = 0;
2071 USE_SAFE_ALLOCA;
2059 2072
2060 if (!NILP (prefix)) 2073 if (!NILP (prefix))
2061 size += XINT (Flength (prefix)); 2074 size += XINT (Flength (prefix));
2062 2075
2063 /* This has one extra element at the end that we don't pass to Fconcat. */ 2076 /* This has one extra element at the end that we don't pass to Fconcat. */
2064 args = (Lisp_Object *) alloca (size * 4 * sizeof (Lisp_Object)); 2077 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object) / 4 < size)
2078 memory_full (SIZE_MAX);
2079 SAFE_ALLOCA_LISP (args, size * 4);
2065 2080
2066 /* In effect, this computes 2081 /* In effect, this computes
2067 (mapconcat 'single-key-description keys " ") 2082 (mapconcat 'single-key-description keys " ")
@@ -2077,11 +2092,14 @@ The `kbd' macro is an approximate inverse of this. */)
2077 if (add_meta) 2092 if (add_meta)
2078 { 2093 {
2079 args[len] = Fsingle_key_description (meta_prefix_char, Qnil); 2094 args[len] = Fsingle_key_description (meta_prefix_char, Qnil);
2080 len += 2; 2095 result = Fconcat (len + 1, args);
2081 } 2096 }
2082 else if (len == 0) 2097 else if (len == 0)
2083 return empty_unibyte_string; 2098 result = empty_unibyte_string;
2084 return Fconcat (len - 1, args); 2099 else
2100 result = Fconcat (len - 1, args);
2101 SAFE_FREE ();
2102 return result;
2085 } 2103 }
2086 2104
2087 if (STRINGP (list)) 2105 if (STRINGP (list))
@@ -2350,7 +2368,7 @@ See Info node `(elisp)Describing Characters' for examples. */)
2350 char str[6]; 2368 char str[6];
2351 int c; 2369 int c;
2352 2370
2353 CHECK_NUMBER (character); 2371 CHECK_CHARACTER (character);
2354 2372
2355 c = XINT (character); 2373 c = XINT (character);
2356 if (!ASCII_CHAR_P (c)) 2374 if (!ASCII_CHAR_P (c))
@@ -2373,8 +2391,8 @@ static int where_is_preferred_modifier;
2373static int 2391static int
2374preferred_sequence_p (Lisp_Object seq) 2392preferred_sequence_p (Lisp_Object seq)
2375{ 2393{
2376 int i; 2394 EMACS_INT i;
2377 int len = XINT (Flength (seq)); 2395 EMACS_INT len = XFASTINT (Flength (seq));
2378 int result = 1; 2396 int result = 1;
2379 2397
2380 for (i = 0; i < len; i++) 2398 for (i = 0; i < len; i++)
@@ -3100,7 +3118,7 @@ static void
3100describe_command (Lisp_Object definition, Lisp_Object args) 3118describe_command (Lisp_Object definition, Lisp_Object args)
3101{ 3119{
3102 register Lisp_Object tem1; 3120 register Lisp_Object tem1;
3103 EMACS_INT column = current_column (); 3121 ptrdiff_t column = current_column ();
3104 int description_column; 3122 int description_column;
3105 3123
3106 /* If column 16 is no good, go to col 32; 3124 /* If column 16 is no good, go to col 32;
@@ -3383,7 +3401,7 @@ This is text showing the elements of vector matched against indices.
3383DESCRIBER is the output function used; nil means use `princ'. */) 3401DESCRIBER is the output function used; nil means use `princ'. */)
3384 (Lisp_Object vector, Lisp_Object describer) 3402 (Lisp_Object vector, Lisp_Object describer)
3385{ 3403{
3386 int count = SPECPDL_INDEX (); 3404 ptrdiff_t count = SPECPDL_INDEX ();
3387 if (NILP (describer)) 3405 if (NILP (describer))
3388 describer = intern ("princ"); 3406 describer = intern ("princ");
3389 specbind (Qstandard_output, Fcurrent_buffer ()); 3407 specbind (Qstandard_output, Fcurrent_buffer ());