aboutsummaryrefslogtreecommitdiffstats
path: root/src/keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/keymap.c')
-rw-r--r--src/keymap.c63
1 files changed, 39 insertions, 24 deletions
diff --git a/src/keymap.c b/src/keymap.c
index 4485080db21..2d2f36d91c3 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);
@@ -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
@@ -2047,20 +2057,25 @@ Control characters turn into "C-foo" sequences, meta into "M-foo",
2047spaces are put between sequence elements, etc. */) 2057spaces are put between sequence elements, etc. */)
2048 (Lisp_Object keys, Lisp_Object prefix) 2058 (Lisp_Object keys, Lisp_Object prefix)
2049{ 2059{
2050 int len = 0; 2060 ptrdiff_t len = 0;
2051 int i, i_byte; 2061 EMACS_INT i;
2062 ptrdiff_t i_byte;
2052 Lisp_Object *args; 2063 Lisp_Object *args;
2053 int size = XINT (Flength (keys)); 2064 EMACS_INT size = XINT (Flength (keys));
2054 Lisp_Object list; 2065 Lisp_Object list;
2055 Lisp_Object sep = build_string (" "); 2066 Lisp_Object sep = build_string (" ");
2056 Lisp_Object key; 2067 Lisp_Object key;
2068 Lisp_Object result;
2057 int add_meta = 0; 2069 int add_meta = 0;
2070 USE_SAFE_ALLOCA;
2058 2071
2059 if (!NILP (prefix)) 2072 if (!NILP (prefix))
2060 size += XINT (Flength (prefix)); 2073 size += XINT (Flength (prefix));
2061 2074
2062 /* This has one extra element at the end that we don't pass to Fconcat. */ 2075 /* This has one extra element at the end that we don't pass to Fconcat. */
2063 args = (Lisp_Object *) alloca (size * 4 * sizeof (Lisp_Object)); 2076 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object) / 4 < size)
2077 memory_full (SIZE_MAX);
2078 SAFE_ALLOCA_LISP (args, size * 4);
2064 2079
2065 /* In effect, this computes 2080 /* In effect, this computes
2066 (mapconcat 'single-key-description keys " ") 2081 (mapconcat 'single-key-description keys " ")
@@ -2078,9 +2093,9 @@ spaces are put between sequence elements, etc. */)
2078 args[len] = Fsingle_key_description (meta_prefix_char, Qnil); 2093 args[len] = Fsingle_key_description (meta_prefix_char, Qnil);
2079 len += 2; 2094 len += 2;
2080 } 2095 }
2081 else if (len == 0) 2096 result = len == 0 ? empty_unibyte_string : Fconcat (len - 1, args);
2082 return empty_unibyte_string; 2097 SAFE_FREE ();
2083 return Fconcat (len - 1, args); 2098 return result;
2084 } 2099 }
2085 2100
2086 if (STRINGP (list)) 2101 if (STRINGP (list))
@@ -2342,7 +2357,7 @@ See Info node `(elisp)Describing Characters' for examples. */)
2342 char str[6]; 2357 char str[6];
2343 int c; 2358 int c;
2344 2359
2345 CHECK_NUMBER (character); 2360 CHECK_CHARACTER (character);
2346 2361
2347 c = XINT (character); 2362 c = XINT (character);
2348 if (!ASCII_CHAR_P (c)) 2363 if (!ASCII_CHAR_P (c))
@@ -2365,8 +2380,8 @@ static int where_is_preferred_modifier;
2365static int 2380static int
2366preferred_sequence_p (Lisp_Object seq) 2381preferred_sequence_p (Lisp_Object seq)
2367{ 2382{
2368 int i; 2383 EMACS_INT i;
2369 int len = XINT (Flength (seq)); 2384 EMACS_INT len = XFASTINT (Flength (seq));
2370 int result = 1; 2385 int result = 1;
2371 2386
2372 for (i = 0; i < len; i++) 2387 for (i = 0; i < len; i++)
@@ -3083,7 +3098,7 @@ static void
3083describe_command (Lisp_Object definition, Lisp_Object args) 3098describe_command (Lisp_Object definition, Lisp_Object args)
3084{ 3099{
3085 register Lisp_Object tem1; 3100 register Lisp_Object tem1;
3086 EMACS_INT column = current_column (); 3101 ptrdiff_t column = current_column ();
3087 int description_column; 3102 int description_column;
3088 3103
3089 /* If column 16 is no good, go to col 32; 3104 /* If column 16 is no good, go to col 32;
@@ -3366,7 +3381,7 @@ This is text showing the elements of vector matched against indices.
3366DESCRIBER is the output function used; nil means use `princ'. */) 3381DESCRIBER is the output function used; nil means use `princ'. */)
3367 (Lisp_Object vector, Lisp_Object describer) 3382 (Lisp_Object vector, Lisp_Object describer)
3368{ 3383{
3369 int count = SPECPDL_INDEX (); 3384 ptrdiff_t count = SPECPDL_INDEX ();
3370 if (NILP (describer)) 3385 if (NILP (describer))
3371 describer = intern ("princ"); 3386 describer = intern ("princ");
3372 specbind (Qstandard_output, Fcurrent_buffer ()); 3387 specbind (Qstandard_output, Fcurrent_buffer ());