aboutsummaryrefslogtreecommitdiffstats
path: root/src/keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/keymap.c')
-rw-r--r--src/keymap.c105
1 files changed, 60 insertions, 45 deletions
diff --git a/src/keymap.c b/src/keymap.c
index d33af68be48..ecaeb32896e 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -1,5 +1,5 @@
1/* Manipulation of keymaps 1/* Manipulation of keymaps
2 Copyright (C) 1985-1988, 1993-1995, 1998-2011 Free Software Foundation, Inc. 2 Copyright (C) 1985-1988, 1993-1995, 1998-2012 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -150,17 +150,6 @@ in case you use it as a menu with `x-popup-menu'. */)
150 return Fcons (Qkeymap, Qnil); 150 return Fcons (Qkeymap, Qnil);
151} 151}
152 152
153DEFUN ("make-composed-keymap", Fmake_composed_keymap, Smake_composed_keymap,
154 0, MANY, 0,
155 doc: /* Construct and return a new keymap composed of KEYMAPS.
156When looking up a key in the returned map, the key is looked in each
157keymap in turn until a binding is found.
158usage: (make-composed-keymap &rest KEYMAPS) */)
159 (ptrdiff_t nargs, Lisp_Object *args)
160{
161 return Fcons (Qkeymap, Flist (nargs, args));
162}
163
164/* This function is used for installing the standard key bindings 153/* This function is used for installing the standard key bindings
165 at initialization time. 154 at initialization time.
166 155
@@ -1009,7 +998,7 @@ copy_keymap_item (Lisp_Object elt)
1009 } 998 }
1010 else 999 else
1011 { 1000 {
1012 /* It may be an old fomat menu item. 1001 /* It may be an old format menu item.
1013 Skip the optional menu string. */ 1002 Skip the optional menu string. */
1014 if (STRINGP (XCAR (tem))) 1003 if (STRINGP (XCAR (tem)))
1015 { 1004 {
@@ -1216,13 +1205,20 @@ binding KEY to DEF is added at the front of KEYMAP. */)
1216 1205
1217 keymap = get_keymap (cmd, 0, 1); 1206 keymap = get_keymap (cmd, 0, 1);
1218 if (!CONSP (keymap)) 1207 if (!CONSP (keymap))
1219 /* We must use Fkey_description rather than just passing key to 1208 {
1220 error; key might be a vector, not a string. */ 1209 const char *trailing_esc = ((EQ (c, meta_prefix_char) && metized)
1221 error ("Key sequence %s starts with non-prefix key %s", 1210 ? (idx == 0 ? "ESC" : " ESC")
1222 SDATA (Fkey_description (key, Qnil)), 1211 : "");
1223 SDATA (Fkey_description (Fsubstring (key, make_number (0), 1212
1224 make_number (idx)), 1213 /* We must use Fkey_description rather than just passing key to
1225 Qnil))); 1214 error; key might be a vector, not a string. */
1215 error ("Key sequence %s starts with non-prefix key %s%s",
1216 SDATA (Fkey_description (key, Qnil)),
1217 SDATA (Fkey_description (Fsubstring (key, make_number (0),
1218 make_number (idx)),
1219 Qnil)),
1220 trailing_esc);
1221 }
1226 } 1222 }
1227} 1223}
1228 1224
@@ -1403,7 +1399,7 @@ silly_event_symbol_error (Lisp_Object c)
1403 some systems, static gets macro-defined to be the empty string. 1399 some systems, static gets macro-defined to be the empty string.
1404 Ickypoo. */ 1400 Ickypoo. */
1405static Lisp_Object *cmm_modes = NULL, *cmm_maps = NULL; 1401static Lisp_Object *cmm_modes = NULL, *cmm_maps = NULL;
1406static int cmm_size = 0; 1402static ptrdiff_t cmm_size = 0;
1407 1403
1408/* Store a pointer to an array of the currently active minor modes in 1404/* Store a pointer to an array of the currently active minor modes in
1409 *modeptr, a pointer to an array of the keymaps of the currently 1405 *modeptr, a pointer to an array of the keymaps of the currently
@@ -1423,10 +1419,10 @@ static int cmm_size = 0;
1423 loop. Instead, we'll use realloc/malloc and silently truncate the 1419 loop. Instead, we'll use realloc/malloc and silently truncate the
1424 list, let the key sequence be read, and hope some other piece of 1420 list, let the key sequence be read, and hope some other piece of
1425 code signals the error. */ 1421 code signals the error. */
1426int 1422ptrdiff_t
1427current_minor_maps (Lisp_Object **modeptr, Lisp_Object **mapptr) 1423current_minor_maps (Lisp_Object **modeptr, Lisp_Object **mapptr)
1428{ 1424{
1429 int i = 0; 1425 ptrdiff_t i = 0;
1430 int list_number = 0; 1426 int list_number = 0;
1431 Lisp_Object alist, assoc, var, val; 1427 Lisp_Object alist, assoc, var, val;
1432 Lisp_Object emulation_alists; 1428 Lisp_Object emulation_alists;
@@ -1469,9 +1465,16 @@ current_minor_maps (Lisp_Object **modeptr, Lisp_Object **mapptr)
1469 1465
1470 if (i >= cmm_size) 1466 if (i >= cmm_size)
1471 { 1467 {
1472 int newsize, allocsize; 1468 ptrdiff_t newsize, allocsize;
1473 Lisp_Object *newmodes, *newmaps; 1469 Lisp_Object *newmodes, *newmaps;
1474 1470
1471 /* Check for size calculation overflow. Other code
1472 (e.g., read_key_sequence) adds 3 to the count
1473 later, so subtract 3 from the limit here. */
1474 if (min (PTRDIFF_MAX, SIZE_MAX) / (2 * sizeof *newmodes) - 3
1475 < cmm_size)
1476 break;
1477
1475 newsize = cmm_size == 0 ? 30 : cmm_size * 2; 1478 newsize = cmm_size == 0 ? 30 : cmm_size * 2;
1476 allocsize = newsize * sizeof *newmodes; 1479 allocsize = newsize * sizeof *newmodes;
1477 1480
@@ -2040,8 +2043,9 @@ static Lisp_Object Qsingle_key_description, Qkey_description;
2040DEFUN ("key-description", Fkey_description, Skey_description, 1, 2, 0, 2043DEFUN ("key-description", Fkey_description, Skey_description, 1, 2, 0,
2041 doc: /* Return a pretty description of key-sequence KEYS. 2044 doc: /* Return a pretty description of key-sequence KEYS.
2042Optional arg PREFIX is the sequence of keys leading up to KEYS. 2045Optional arg PREFIX is the sequence of keys leading up to KEYS.
2043Control characters turn into "C-foo" sequences, meta into "M-foo", 2046For example, [?\C-x ?l] is converted into the string \"C-x l\".
2044spaces are put between sequence elements, etc. */) 2047
2048The `kbd' macro is an approximate inverse of this. */)
2045 (Lisp_Object keys, Lisp_Object prefix) 2049 (Lisp_Object keys, Lisp_Object prefix)
2046{ 2050{
2047 int len = 0; 2051 int len = 0;
@@ -2140,12 +2144,12 @@ spaces are put between sequence elements, etc. */)
2140 2144
2141 2145
2142char * 2146char *
2143push_key_description (register unsigned int c, register char *p, int force_multibyte) 2147push_key_description (EMACS_INT ch, char *p, int force_multibyte)
2144{ 2148{
2145 unsigned c2; 2149 int c, c2;
2146 2150
2147 /* Clear all the meaningless bits above the meta bit. */ 2151 /* Clear all the meaningless bits above the meta bit. */
2148 c &= meta_modifier | ~ - meta_modifier; 2152 c = ch & (meta_modifier | ~ - meta_modifier);
2149 c2 = c & ~(alt_modifier | ctrl_modifier | hyper_modifier 2153 c2 = c & ~(alt_modifier | ctrl_modifier | hyper_modifier
2150 | meta_modifier | shift_modifier | super_modifier); 2154 | meta_modifier | shift_modifier | super_modifier);
2151 2155
@@ -2267,23 +2271,35 @@ around function keys and event symbols. */)
2267 if (CONSP (key) && lucid_event_type_list_p (key)) 2271 if (CONSP (key) && lucid_event_type_list_p (key))
2268 key = Fevent_convert_list (key); 2272 key = Fevent_convert_list (key);
2269 2273
2274 if (CONSP (key) && INTEGERP (XCAR (key)) && INTEGERP (XCDR (key)))
2275 /* An interval from a map-char-table. */
2276 return concat3 (Fsingle_key_description (XCAR (key), no_angles),
2277 build_string (".."),
2278 Fsingle_key_description (XCDR (key), no_angles));
2279
2270 key = EVENT_HEAD (key); 2280 key = EVENT_HEAD (key);
2271 2281
2272 if (INTEGERP (key)) /* Normal character */ 2282 if (INTEGERP (key)) /* Normal character. */
2273 { 2283 {
2274 char tem[KEY_DESCRIPTION_SIZE]; 2284 char tem[KEY_DESCRIPTION_SIZE], *p;
2275 2285
2276 *push_key_description (XINT (key), tem, 1) = 0; 2286 p = push_key_description (XINT (key), tem, 1);
2277 return build_string (tem); 2287 *p = 0;
2288 return make_specified_string (tem, -1, p - tem, 1);
2278 } 2289 }
2279 else if (SYMBOLP (key)) /* Function key or event-symbol */ 2290 else if (SYMBOLP (key)) /* Function key or event-symbol. */
2280 { 2291 {
2281 if (NILP (no_angles)) 2292 if (NILP (no_angles))
2282 { 2293 {
2283 char *buffer 2294 char *buffer;
2284 = (char *) alloca (SBYTES (SYMBOL_NAME (key)) + 5); 2295 Lisp_Object result;
2285 sprintf (buffer, "<%s>", SDATA (SYMBOL_NAME (key))); 2296 USE_SAFE_ALLOCA;
2286 return build_string (buffer); 2297 SAFE_ALLOCA (buffer, char *,
2298 sizeof "<>" + SBYTES (SYMBOL_NAME (key)));
2299 esprintf (buffer, "<%s>", SDATA (SYMBOL_NAME (key)));
2300 result = build_string (buffer);
2301 SAFE_FREE ();
2302 return result;
2287 } 2303 }
2288 else 2304 else
2289 return Fsymbol_name (key); 2305 return Fsymbol_name (key);
@@ -2615,11 +2631,11 @@ remapped command in the returned list. */)
2615 /* We have a list of advertised bindings. */ 2631 /* We have a list of advertised bindings. */
2616 while (CONSP (tem)) 2632 while (CONSP (tem))
2617 if (EQ (shadow_lookup (keymaps, XCAR (tem), Qnil, 0), definition)) 2633 if (EQ (shadow_lookup (keymaps, XCAR (tem), Qnil, 0), definition))
2618 return XCAR (tem); 2634 RETURN_UNGCPRO (XCAR (tem));
2619 else 2635 else
2620 tem = XCDR (tem); 2636 tem = XCDR (tem);
2621 if (EQ (shadow_lookup (keymaps, tem, Qnil, 0), definition)) 2637 if (EQ (shadow_lookup (keymaps, tem, Qnil, 0), definition))
2622 return tem; 2638 RETURN_UNGCPRO (tem);
2623 } 2639 }
2624 2640
2625 sequences = Freverse (where_is_internal (definition, keymaps, 2641 sequences = Freverse (where_is_internal (definition, keymaps,
@@ -3712,11 +3728,11 @@ the same way. The "active" keymaps in each alist are used before
3712 Vemulation_mode_map_alists = Qnil; 3728 Vemulation_mode_map_alists = Qnil;
3713 3729
3714 DEFVAR_LISP ("where-is-preferred-modifier", Vwhere_is_preferred_modifier, 3730 DEFVAR_LISP ("where-is-preferred-modifier", Vwhere_is_preferred_modifier,
3715 doc: /* Preferred modifier to use for `where-is'. 3731 doc: /* Preferred modifier key to use for `where-is'.
3716When a single binding is requested, `where-is' will return one that 3732When a single binding is requested, `where-is' will return one that
3717uses this modifier if possible. If nil, or if no such binding exists, 3733uses this modifier key if possible. If nil, or if no such binding
3718bindings using keys without modifiers (or only with meta) will be 3734exists, bindings using keys without modifiers (or only with meta) will
3719preferred. */); 3735be preferred. */);
3720 Vwhere_is_preferred_modifier = Qnil; 3736 Vwhere_is_preferred_modifier = Qnil;
3721 where_is_preferred_modifier = 0; 3737 where_is_preferred_modifier = 0;
3722 3738
@@ -3754,7 +3770,6 @@ preferred. */);
3754 defsubr (&Sset_keymap_parent); 3770 defsubr (&Sset_keymap_parent);
3755 defsubr (&Smake_keymap); 3771 defsubr (&Smake_keymap);
3756 defsubr (&Smake_sparse_keymap); 3772 defsubr (&Smake_sparse_keymap);
3757 defsubr (&Smake_composed_keymap);
3758 defsubr (&Smap_keymap_internal); 3773 defsubr (&Smap_keymap_internal);
3759 defsubr (&Smap_keymap); 3774 defsubr (&Smap_keymap);
3760 defsubr (&Scopy_keymap); 3775 defsubr (&Scopy_keymap);