/* Manipulation of keymaps
- Copyright (C) 1985-1988, 1993-1995, 1998-2012 Free Software Foundation, Inc.
+ Copyright (C) 1985-1988, 1993-1995, 1998-2013 Free Software
+ Foundation, Inc.
This file is part of GNU Emacs.
#include <config.h>
#include <stdio.h>
-#include <setjmp.h>
+
#include "lisp.h"
#include "commands.h"
#include "character.h"
static void describe_translation (Lisp_Object, Lisp_Object);
static void describe_map (Lisp_Object, Lisp_Object,
void (*) (Lisp_Object, Lisp_Object),
- int, Lisp_Object, Lisp_Object*, int, int);
+ bool, Lisp_Object, Lisp_Object*, bool, bool);
static void describe_vector (Lisp_Object, Lisp_Object, Lisp_Object,
- void (*) (Lisp_Object, Lisp_Object), int,
- Lisp_Object, Lisp_Object, int, int);
+ void (*) (Lisp_Object, Lisp_Object), bool,
+ Lisp_Object, Lisp_Object, bool, bool);
static void silly_event_symbol_error (Lisp_Object);
-static Lisp_Object get_keyelt (Lisp_Object, int);
+static Lisp_Object get_keyelt (Lisp_Object, bool);
\f
/* Keymap object support - constructors and predicates. */
/* Check that OBJECT is a keymap (after dereferencing through any
symbols). If it is, return it.
- If AUTOLOAD is non-zero and OBJECT is a symbol whose function value
+ If AUTOLOAD and if OBJECT is a symbol whose function value
is an autoload form, do the autoload and try again.
- If AUTOLOAD is nonzero, callers must assume GC is possible.
-
- If the map needs to be autoloaded, but AUTOLOAD is zero (and ERROR
- is zero as well), return Qt.
+ If AUTOLOAD, callers must assume GC is possible.
ERROR_IF_NOT_KEYMAP controls how we respond if OBJECT isn't a keymap.
- If ERROR_IF_NOT_KEYMAP is non-zero, signal an error; otherwise,
+ If ERROR_IF_NOT_KEYMAP, signal an error; otherwise,
just return Qnil.
Note that most of the time, we don't want to pursue autoloads.
but it seems to me that only read_key_sequence, Flookup_key, and
Fdefine_key should cause keymaps to be autoloaded.
- This function can GC when AUTOLOAD is non-zero, because it calls
+ This function can GC when AUTOLOAD is true, because it calls
Fautoload_do_load which can GC. */
Lisp_Object
-get_keymap (Lisp_Object object, int error_if_not_keymap, int autoload)
+get_keymap (Lisp_Object object, bool error_if_not_keymap, bool autoload)
{
Lisp_Object tem;
We assume that KEYMAP is a valid keymap. */
static Lisp_Object
-keymap_parent (Lisp_Object keymap, int autoload)
+keymap_parent (Lisp_Object keymap, bool autoload)
{
Lisp_Object list;
}
/* Check whether MAP is one of MAPS parents. */
-static int
+static bool
keymap_memberp (Lisp_Object map, Lisp_Object maps)
{
if (NILP (map)) return 0;
MAP must be a keymap or a list of keymaps.
- If T_OK is non-zero, bindings for Qt are treated as default
+ If T_OK, bindings for Qt are treated as default
bindings; any key left unmentioned by other tables and bindings is
given the binding of Qt.
- If T_OK is zero, bindings for Qt are not treated specially.
+ If not T_OK, bindings for Qt are not treated specially.
If NOINHERIT, don't accept a subkeymap found in an inherited keymap.
- Returns Qunbound if no binding was found (and returns Qnil if a nil
+ Return Qunbound if no binding was found (and return Qnil if a nil
binding was found). */
static Lisp_Object
-access_keymap_1 (Lisp_Object map, Lisp_Object idx, int t_ok, int noinherit, int autoload)
+access_keymap_1 (Lisp_Object map, Lisp_Object idx,
+ bool t_ok, bool noinherit, bool autoload)
{
/* If idx is a list (some sort of mouse click, perhaps?),
the index we want to use is the car of the list, which
Lisp_Object
access_keymap (Lisp_Object map, Lisp_Object idx,
- int t_ok, int noinherit, int autoload)
+ bool t_ok, bool noinherit, bool autoload)
{
Lisp_Object val = access_keymap_1 (map, idx, t_ok, noinherit, autoload);
return EQ (val, Qunbound) ? Qnil : val;
{
if (!NILP (val))
{
- map_keymap_function_t fun
- = (map_keymap_function_t) XSAVE_VALUE (XCAR (args))->pointer;
- args = XCDR (args);
+ map_keymap_function_t fun = XSAVE_POINTER (args, 0);
/* If the key is a range, make a copy since map_char_table modifies
it in place. */
if (CONSP (key))
key = Fcons (XCAR (key), XCDR (key));
- map_keymap_item (fun, XCDR (args), key, val,
- XSAVE_VALUE (XCAR (args))->pointer);
+ map_keymap_item (fun, XSAVE_OBJECT (args, 2), key,
+ val, XSAVE_POINTER (args, 1));
}
}
}
}
else if (CHAR_TABLE_P (binding))
- {
- map_char_table (map_keymap_char_table_item, Qnil, binding,
- Fcons (make_save_value ((void *) fun, 0),
- Fcons (make_save_value (data, 0),
- args)));
- }
+ map_char_table (map_keymap_char_table_item, Qnil, binding,
+ make_save_value ("ppo", fun, data, args));
}
UNGCPRO;
return tail;
}
/* Same as map_keymap_internal, but traverses parent keymaps as well.
- A non-zero AUTOLOAD indicates that autoloaded keymaps should be loaded. */
+ AUTOLOAD indicates that autoloaded keymaps should be loaded. */
void
-map_keymap (Lisp_Object map, map_keymap_function_t fun, Lisp_Object args, void *data, int autoload)
+map_keymap (Lisp_Object map, map_keymap_function_t fun, Lisp_Object args,
+ void *data, bool autoload)
{
struct gcpro gcpro1;
GCPRO1 (args);
Also if OBJECT has a menu string as the first element,
remove that. Also remove a menu help string as second element.
- If AUTOLOAD is nonzero, load autoloadable keymaps
+ If AUTOLOAD, load autoloadable keymaps
that are referred to with indirection.
This can GC because menu_item_eval_property calls Feval. */
static Lisp_Object
-get_keyelt (Lisp_Object object, int autoload)
+get_keyelt (Lisp_Object object, bool autoload)
{
while (1)
{
binding KEY to DEF is added at the front of KEYMAP. */)
(Lisp_Object keymap, Lisp_Object key, Lisp_Object def)
{
- register ptrdiff_t idx;
- register Lisp_Object c;
- register Lisp_Object cmd;
- int metized = 0;
+ ptrdiff_t idx;
+ Lisp_Object c;
+ Lisp_Object cmd;
+ bool metized = 0;
int meta_bit;
ptrdiff_t length;
struct gcpro gcpro1, gcpro2, gcpro3;
recognize the default bindings, just as `read-key-sequence' does. */)
(Lisp_Object keymap, Lisp_Object key, Lisp_Object accept_default)
{
- register ptrdiff_t idx;
- register Lisp_Object cmd;
- register Lisp_Object c;
+ ptrdiff_t idx;
+ Lisp_Object cmd;
+ Lisp_Object c;
ptrdiff_t length;
- int t_ok = !NILP (accept_default);
+ bool t_ok = !NILP (accept_default);
struct gcpro gcpro1, gcpro2;
GCPRO2 (keymap, key);
/* Use malloc here. See the comment above this function.
Avoid realloc here; it causes spurious traps on GNU/Linux [KFS] */
- BLOCK_INPUT;
+ block_input ();
newmodes = malloc (allocsize);
if (newmodes)
{
}
cmm_maps = newmaps;
}
- UNBLOCK_INPUT;
+ unblock_input ();
if (newmodes == NULL || newmaps == NULL)
break;
window = POSN_WINDOW (position);
if (WINDOWP (window)
- && BUFFERP (WGET (XWINDOW (window), buffer))
- && XBUFFER (WGET (XWINDOW (window), buffer)) != current_buffer)
+ && BUFFERP (XWINDOW (window)->buffer)
+ && XBUFFER (XWINDOW (window)->buffer) != current_buffer)
{
/* Arrange to go back to the original buffer once we're done
processing the key sequence. We don't use
would not be a problem here, but it is easier to keep
things the same.
*/
-
- record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
-
- set_buffer_internal (XBUFFER (WGET (XWINDOW (window), buffer)));
+ record_unwind_current_buffer ();
+ set_buffer_internal (XBUFFER (XWINDOW (window)->buffer));
}
}
if (!NILP (keymap))
keymap = get_keymap (keymap, 1, 1);
- BVAR (current_buffer, keymap) = keymap;
+ bset_keymap (current_buffer, keymap);
return Qnil;
}
struct accessible_keymaps_data {
Lisp_Object maps, tail, thisseq;
/* Does the current sequence end in the meta-prefix-char? */
- int is_metized;
+ bool is_metized;
};
static void
Lisp_Object maps = d->maps;
Lisp_Object tail = d->tail;
Lisp_Object thisseq = d->thisseq;
- int is_metized = d->is_metized && INTEGERP (key);
+ bool is_metized = d->is_metized && INTEGERP (key);
Lisp_Object tem;
cmd = get_keymap (get_keyelt (cmd, 0), 0, 0);
Optional arg PREFIX is the sequence of keys leading up to KEYS.
For example, [?\C-x ?l] is converted into the string \"C-x l\".
-The `kbd' macro is an approximate inverse of this. */)
+For an approximate inverse of this, see `kbd'. */)
(Lisp_Object keys, Lisp_Object prefix)
{
ptrdiff_t len = 0;
Lisp_Object sep = build_string (" ");
Lisp_Object key;
Lisp_Object result;
- int add_meta = 0;
+ bool add_meta = 0;
USE_SAFE_ALLOCA;
if (!NILP (prefix))
char *
-push_key_description (EMACS_INT ch, char *p, int force_multibyte)
+push_key_description (EMACS_INT ch, char *p)
{
int c, c2;
+ bool tab_as_ci;
/* Clear all the meaningless bits above the meta bit. */
c = ch & (meta_modifier | ~ - meta_modifier);
return p;
}
+ tab_as_ci = (c2 == '\t' && (c & meta_modifier));
+
if (c & alt_modifier)
{
*p++ = 'A';
c -= alt_modifier;
}
if ((c & ctrl_modifier) != 0
- || (c2 < ' ' && c2 != 27 && c2 != '\t' && c2 != Ctl ('M')))
+ || (c2 < ' ' && c2 != 27 && c2 != '\t' && c2 != Ctl ('M'))
+ || tab_as_ci)
{
*p++ = 'C';
*p++ = '-';
*p++ = 'S';
*p++ = 'C';
}
+ else if (tab_as_ci)
+ {
+ *p++ = 'i';
+ }
else if (c == '\t')
{
*p++ = 'T';
*p++ = 'P';
*p++ = 'C';
}
- else if (c < 128
- || (NILP (BVAR (current_buffer, enable_multibyte_characters))
- && SINGLE_BYTE_CHAR_P (c)
- && !force_multibyte))
- {
- *p++ = c;
- }
+ else if (c < 128)
+ *p++ = c;
else
{
/* Now we are sure that C is a valid character code. */
- if (NILP (BVAR (current_buffer, enable_multibyte_characters))
- && ! force_multibyte)
- *p++ = multibyte_char_to_unibyte (c);
- else
- p += CHAR_STRING (c, (unsigned char *) p);
+ p += CHAR_STRING (c, (unsigned char *) p);
}
return p;
if (INTEGERP (key)) /* Normal character. */
{
- char tem[KEY_DESCRIPTION_SIZE], *p;
-
- p = push_key_description (XINT (key), tem, 1);
+ char tem[KEY_DESCRIPTION_SIZE];
+ char *p = push_key_description (XINT (key), tem);
*p = 0;
return make_specified_string (tem, -1, p - tem, 1);
}
static Lisp_Object
shadow_lookup (Lisp_Object shadow, Lisp_Object key, Lisp_Object flag,
- int remap)
+ bool remap)
{
Lisp_Object tail, value;
struct where_is_internal_data {
Lisp_Object definition, this, last;
- int last_is_meta, noindirect;
+ bool last_is_meta, noindirect;
Lisp_Object sequences;
};
static Lisp_Object
where_is_internal (Lisp_Object definition, Lisp_Object keymaps,
- int noindirect, int nomenus)
+ bool noindirect, bool nomenus)
{
Lisp_Object maps = Qnil;
Lisp_Object found;
[M-CHAR] sequences, check if last character of the sequence
is the meta-prefix char. */
Lisp_Object last;
- int last_is_meta;
+ bool last_is_meta;
this = Fcar (XCAR (maps));
map = Fcdr (XCAR (maps));
/* Actually relevant bindings. */
Lisp_Object found = Qnil;
/* 1 means ignore all menu bindings entirely. */
- int nomenus = !NILP (firstonly) && !EQ (firstonly, Qnon_ascii);
+ bool nomenus = !NILP (firstonly) && !EQ (firstonly, Qnon_ascii);
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
/* List of sequences found via remapping. Keep them in a separate
variable, so as to push them later, since we prefer
/* Whether or not we're handling remapped sequences. This is needed
because remapping is not done recursively by Fcommand_remapping: you
can't remap a remapped command. */
- int remapped = 0;
+ bool remapped = 0;
Lisp_Object tem = Qnil;
/* Refresh the C version of the modifier preference. */
{
struct where_is_internal_data *d = data; /* Cast! */
Lisp_Object definition = d->definition;
- int noindirect = d->noindirect;
+ bool noindirect = d->noindirect;
Lisp_Object this = d->this;
Lisp_Object last = d->last;
- int last_is_meta = d->last_is_meta;
+ bool last_is_meta = d->last_is_meta;
Lisp_Object sequence;
/* Search through indirections unless that's not wanted. */
(Lisp_Object buffer, Lisp_Object prefix, Lisp_Object menus)
{
Lisp_Object outbuf, shadow;
- int nomenu = NILP (menus);
- register Lisp_Object start1;
+ bool nomenu = NILP (menus);
+ Lisp_Object start1;
struct gcpro gcpro1;
const char *alternate_heading
alternate_heading = 0;
}
- bufend = push_key_description (translate[c], buf, 1);
+ bufend = push_key_description (translate[c], buf);
insert (buf, bufend - buf);
Findent_to (make_number (16), make_number (1));
- bufend = push_key_description (c, buf, 1);
+ bufend = push_key_description (c, buf);
insert (buf, bufend - buf);
insert ("\n", 1);
char *title, *p;
if (!SYMBOLP (modes[i]))
- abort ();
+ emacs_abort ();
p = title = alloca (42 + SCHARS (SYMBOL_NAME (modes[i])));
*p++ = '\f';
/* Insert a description of the key bindings in STARTMAP,
followed by those of all maps reachable through STARTMAP.
- If PARTIAL is nonzero, omit certain "uninteresting" commands
+ If PARTIAL, omit certain "uninteresting" commands
(such as `undefined').
If SHADOW is non-nil, it is a list of maps;
don't mention keys which would be shadowed by any of them.
PREFIX, if non-nil, says mention only keys that start with PREFIX.
TITLE, if not 0, is a string to insert at the beginning.
TITLE should not end with a colon or a newline; we supply that.
- If NOMENU is not 0, then omit menu-bar commands.
+ If NOMENU, then omit menu-bar commands.
- If TRANSL is nonzero, the definitions are actually key translations
+ If TRANSL, the definitions are actually key translations
so print strings and vectors differently.
- If ALWAYS_TITLE is nonzero, print the title even if there are no maps
+ If ALWAYS_TITLE, print the title even if there are no maps
to look through.
- If MENTION_SHADOW is nonzero, then when something is shadowed by SHADOW,
+ If MENTION_SHADOW, then when something is shadowed by SHADOW,
don't omit it; instead, mention it but say it is shadowed.
Any inserted text ends in two newlines (used by `help-make-xrefs'). */
void
-describe_map_tree (Lisp_Object startmap, int partial, Lisp_Object shadow,
- Lisp_Object prefix, const char *title, int nomenu, int transl,
- int always_title, int mention_shadow)
+describe_map_tree (Lisp_Object startmap, bool partial, Lisp_Object shadow,
+ Lisp_Object prefix, const char *title, bool nomenu,
+ bool transl, bool always_title, bool mention_shadow)
{
Lisp_Object maps, orig_maps, seen, sub_shadows;
struct gcpro gcpro1, gcpro2, gcpro3;
- int something = 0;
+ bool something = 0;
const char *key_heading
= "\
key binding\n\
into an array of `struct describe_map_elt',
then sorts them by the events. */
-struct describe_map_elt { Lisp_Object event; Lisp_Object definition; int shadowed; };
+struct describe_map_elt
+{
+ Lisp_Object event;
+ Lisp_Object definition;
+ bool shadowed;
+};
/* qsort comparison function for sorting `struct describe_map_elt' by
the event field. */
static void
describe_map (Lisp_Object map, Lisp_Object prefix,
void (*elt_describer) (Lisp_Object, Lisp_Object),
- int partial, Lisp_Object shadow,
- Lisp_Object *seen, int nomenu, int mention_shadow)
+ bool partial, Lisp_Object shadow,
+ Lisp_Object *seen, bool nomenu, bool mention_shadow)
{
Lisp_Object tail, definition, event;
Lisp_Object tem;
Lisp_Object suppress;
Lisp_Object kludge;
- int first = 1;
+ bool first = 1;
struct gcpro gcpro1, gcpro2, gcpro3;
/* These accumulate the values from sparse keymap bindings,
1, mention_shadow);
else if (CONSP (XCAR (tail)))
{
- int this_shadowed = 0;
+ bool this_shadowed = 0;
event = XCAR (XCAR (tail));
of bytes that lead to the character set or portion of a character
set described by this chartable.
- If PARTIAL is nonzero, it means do not mention suppressed commands
+ If PARTIAL, it means do not mention suppressed commands
(that assumes the vector is in a keymap).
SHADOW is a list of keymaps that shadow this map.
static void
describe_vector (Lisp_Object vector, Lisp_Object prefix, Lisp_Object args,
void (*elt_describer) (Lisp_Object, Lisp_Object),
- int partial, Lisp_Object shadow, Lisp_Object entire_map,
- int keymap_p, int mention_shadow)
+ bool partial, Lisp_Object shadow, Lisp_Object entire_map,
+ bool keymap_p, bool mention_shadow)
{
Lisp_Object definition;
Lisp_Object tem2;
int i;
Lisp_Object suppress;
Lisp_Object kludge;
- int first = 1;
+ bool first = 1;
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
/* Range of elements to be handled. */
int from, to, stop;
for (i = from; ; i++)
{
- int this_shadowed = 0;
+ bool this_shadowed = 0;
int range_beg, range_end;
Lisp_Object val;