/* Manipulation of keymaps
- Copyright (C) 1985-1988, 1993-1995, 1998-2011 Free Software Foundation, Inc.
+ Copyright (C) 1985-1988, 1993-1995, 1998-2012 Free Software Foundation, Inc.
This file is part of GNU Emacs.
}
else
{
- /* It may be an old fomat menu item.
+ /* It may be an old format menu item.
Skip the optional menu string. */
if (STRINGP (XCAR (tem)))
{
binding KEY to DEF is added at the front of KEYMAP. */)
(Lisp_Object keymap, Lisp_Object key, Lisp_Object def)
{
- register int idx;
+ register ptrdiff_t idx;
register Lisp_Object c;
register Lisp_Object cmd;
int metized = 0;
int meta_bit;
- int length;
+ ptrdiff_t length;
struct gcpro gcpro1, gcpro2, gcpro3;
GCPRO3 (keymap, key, def);
if (VECTORP (def) && ASIZE (def) > 0 && CONSP (AREF (def, 0)))
{ /* DEF is apparently an XEmacs-style keyboard macro. */
Lisp_Object tmp = Fmake_vector (make_number (ASIZE (def)), Qnil);
- int i = ASIZE (def);
+ ptrdiff_t i = ASIZE (def);
while (--i >= 0)
{
Lisp_Object defi = AREF (def, i);
recognize the default bindings, just as `read-key-sequence' does. */)
(Lisp_Object keymap, Lisp_Object key, Lisp_Object accept_default)
{
- register int idx;
+ register ptrdiff_t idx;
register Lisp_Object cmd;
register Lisp_Object c;
- int length;
+ ptrdiff_t length;
int t_ok = !NILP (accept_default);
struct gcpro gcpro1, gcpro2;
return i;
}
+/* Return the offset of POSITION, a click position, in the style of
+ the respective argument of Fkey_binding. */
+static ptrdiff_t
+click_position (Lisp_Object position)
+{
+ EMACS_INT pos = (INTEGERP (position) ? XINT (position)
+ : MARKERP (position) ? marker_position (position)
+ : PT);
+ if (! (BEGV <= pos && pos <= ZV))
+ args_out_of_range (Fcurrent_buffer (), position);
+ return pos;
+}
+
DEFUN ("current-active-maps", Fcurrent_active_maps, Scurrent_active_maps,
0, 2, 0,
doc: /* Return a list of the currently active keymaps.
like in the respective argument of `key-binding'. */)
(Lisp_Object olp, Lisp_Object position)
{
- int count = SPECPDL_INDEX ();
+ ptrdiff_t count = SPECPDL_INDEX ();
Lisp_Object keymaps = Fcons (current_global_map, Qnil);
{
Lisp_Object *maps;
int nmaps, i;
- EMACS_INT pt
- = INTEGERP (position) ? XINT (position)
- : MARKERP (position) ? marker_position (position)
- : PT;
+ ptrdiff_t pt = click_position (position);
/* This usually returns the buffer's local map,
but that can be overridden by a `local-map' property. */
Lisp_Object local_map = get_local_map (pt, current_buffer, Qlocal_map);
while (!NILP (tem = Frassq (cmd, maps)))
{
Lisp_Object prefix = XCAR (tem);
- int lim = XINT (Flength (XCAR (tem)));
+ ptrdiff_t lim = XINT (Flength (XCAR (tem)));
if (lim <= XINT (Flength (thisseq)))
{ /* This keymap was already seen with a smaller prefix. */
- int i = 0;
+ ptrdiff_t i = 0;
while (i < lim && EQ (Faref (prefix, make_number (i)),
Faref (thisseq, make_number (i))))
i++;
(Lisp_Object keymap, Lisp_Object prefix)
{
Lisp_Object maps, tail;
- int prefixlen = XINT (Flength (prefix));
+ EMACS_INT prefixlen = XFASTINT (Flength (prefix));
/* no need for gcpro because we don't autoload any keymaps. */
spaces are put between sequence elements, etc. */)
(Lisp_Object keys, Lisp_Object prefix)
{
- int len = 0;
- int i, i_byte;
+ ptrdiff_t len = 0;
+ EMACS_INT i;
+ ptrdiff_t i_byte;
Lisp_Object *args;
- int size = XINT (Flength (keys));
+ EMACS_INT size = XINT (Flength (keys));
Lisp_Object list;
Lisp_Object sep = build_string (" ");
Lisp_Object key;
+ Lisp_Object result;
int add_meta = 0;
+ USE_SAFE_ALLOCA;
if (!NILP (prefix))
size += XINT (Flength (prefix));
/* This has one extra element at the end that we don't pass to Fconcat. */
- args = (Lisp_Object *) alloca (size * 4 * sizeof (Lisp_Object));
+ if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object) / 4 < size)
+ memory_full (SIZE_MAX);
+ SAFE_ALLOCA_LISP (args, size * 4);
/* In effect, this computes
(mapconcat 'single-key-description keys " ")
if (add_meta)
{
args[len] = Fsingle_key_description (meta_prefix_char, Qnil);
- len += 2;
+ result = Fconcat (len + 1, args);
}
else if (len == 0)
- return empty_unibyte_string;
- return Fconcat (len - 1, args);
+ result = empty_unibyte_string;
+ else
+ result = Fconcat (len - 1, args);
+ SAFE_FREE ();
+ return result;
}
if (STRINGP (list))
if (CONSP (key) && lucid_event_type_list_p (key))
key = Fevent_convert_list (key);
+ if (CONSP (key) && INTEGERP (XCAR (key)) && INTEGERP (XCDR (key)))
+ /* An interval from a map-char-table. */
+ return concat3 (Fsingle_key_description (XCAR (key), no_angles),
+ build_string (".."),
+ Fsingle_key_description (XCDR (key), no_angles));
+
key = EVENT_HEAD (key);
- if (INTEGERP (key)) /* Normal character */
+ if (INTEGERP (key)) /* Normal character. */
{
- char tem[KEY_DESCRIPTION_SIZE];
+ char tem[KEY_DESCRIPTION_SIZE], *p;
- *push_key_description (XINT (key), tem, 1) = 0;
- return build_string (tem);
+ p = push_key_description (XINT (key), tem, 1);
+ *p = 0;
+ return make_specified_string (tem, -1, p - tem, 1);
}
- else if (SYMBOLP (key)) /* Function key or event-symbol */
+ else if (SYMBOLP (key)) /* Function key or event-symbol. */
{
if (NILP (no_angles))
{
char str[6];
int c;
- CHECK_NUMBER (character);
+ CHECK_CHARACTER (character);
c = XINT (character);
if (!ASCII_CHAR_P (c))
static int
preferred_sequence_p (Lisp_Object seq)
{
- int i;
- int len = XINT (Flength (seq));
+ EMACS_INT i;
+ EMACS_INT len = XFASTINT (Flength (seq));
int result = 1;
for (i = 0; i < len; i++)
/* We have a list of advertised bindings. */
while (CONSP (tem))
if (EQ (shadow_lookup (keymaps, XCAR (tem), Qnil, 0), definition))
- return XCAR (tem);
+ RETURN_UNGCPRO (XCAR (tem));
else
tem = XCDR (tem);
if (EQ (shadow_lookup (keymaps, tem, Qnil, 0), definition))
- return tem;
+ RETURN_UNGCPRO (tem);
}
sequences = Freverse (where_is_internal (definition, keymaps,
describe_command (Lisp_Object definition, Lisp_Object args)
{
register Lisp_Object tem1;
- EMACS_INT column = current_column ();
+ ptrdiff_t column = current_column ();
int description_column;
/* If column 16 is no good, go to col 32;
DESCRIBER is the output function used; nil means use `princ'. */)
(Lisp_Object vector, Lisp_Object describer)
{
- int count = SPECPDL_INDEX ();
+ ptrdiff_t count = SPECPDL_INDEX ();
if (NILP (describer))
describer = intern ("princ");
specbind (Qstandard_output, Fcurrent_buffer ());