/* Manipulation of keymaps
Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
1998, 1999, 2000, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007 Free Software Foundation, Inc.
+ 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
This file is part of GNU Emacs.
GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Emacs is distributed in the hope that it will be useful,
a cons (STRING . DEFN), meaning that DEFN is the definition
(DEFN should be a valid definition in its own right),
or a cons (MAP . CHAR), meaning use definition of CHAR in keymap MAP,
- or an extended menu item definition. (See info node `Extended Menu Items'.)
+ or an extended menu item definition.
+ (See info node `(elisp)Extended Menu Items'.)
If KEYMAP is a sparse keymap with a binding for KEY, the existing
binding is altered. If there is no binding for KEY, the new pair
/* This function may GC (it calls Fkey_binding). */
-DEFUN ("command-remapping", Fcommand_remapping, Scommand_remapping, 1, 2, 0,
- doc: /* Return the remapping for command COMMAND in current keymaps.
+DEFUN ("command-remapping", Fcommand_remapping, Scommand_remapping, 1, 3, 0,
+ doc: /* Return the remapping for command COMMAND.
Returns nil if COMMAND is not remapped (or not a symbol).
If the optional argument POSITION is non-nil, it specifies a mouse
position as returned by `event-start' and `event-end', and the
remapping occurs in the keymaps associated with it. It can also be a
number or marker, in which case the keymap properties at the specified
-buffer position instead of point are used. */)
- (command, position)
- Lisp_Object command, position;
+buffer position instead of point are used. The KEYMAPS argument is
+ignored if POSITION is non-nil.
+
+If the optional argument KEYMAPS is non-nil, it should be a list of
+keymaps to search for command remapping. Otherwise, search for the
+remapping in all currently active keymaps. */)
+ (command, position, keymaps)
+ Lisp_Object command, position, keymaps;
{
if (!SYMBOLP (command))
return Qnil;
ASET (command_remapping_vector, 1, command);
- return Fkey_binding (command_remapping_vector, Qnil, Qt, position);
+
+ if (NILP (keymaps))
+ return Fkey_binding (command_remapping_vector, Qnil, Qt, position);
+ else
+ {
+ Lisp_Object maps, binding;
+
+ for (maps = keymaps; !NILP (maps); maps = Fcdr (maps))
+ {
+ binding = Flookup_key (Fcar (maps), command_remapping_vector, Qnil);
+ if (!NILP (binding) && !INTEGERP (binding))
+ return binding;
+ }
+ return Qnil;
+ }
}
/* Value is number if KEY is too long; nil if valid but has no definition. */
static Lisp_Object *cmm_modes = NULL, *cmm_maps = NULL;
static int cmm_size = 0;
-/* Store a pointer to an array of the keymaps of the currently active
- minor modes in *buf, and return the number of maps it contains.
+/* Store a pointer to an array of the currently active minor modes in
+ *modeptr, a pointer to an array of the keymaps of the currently
+ active minor modes in *mapptr, and return the number of maps
+ *mapptr contains.
This function always returns a pointer to the same buffer, and may
free or reallocate it, so if you want to keep it for a long time or
if (NILP (no_remap) && SYMBOLP (value))
{
Lisp_Object value1;
- if (value1 = Fcommand_remapping (value, position), !NILP (value1))
+ if (value1 = Fcommand_remapping (value, position, Qnil), !NILP (value1))
value = value1;
}
/* 1 means ignore all menu bindings entirely. */
int nomenus = !NILP (firstonly) && !EQ (firstonly, Qnon_ascii);
- /* If this command is remapped, then it has no key bindings
- of its own. */
- if (NILP (no_remap) && SYMBOLP (definition))
- {
- Lisp_Object tem;
- if (tem = Fcommand_remapping (definition, Qnil), !NILP (tem))
- return Qnil;
- }
-
found = keymaps;
while (CONSP (found))
{
found = Qnil;
sequences = Qnil;
+ /* If this command is remapped, then it has no key bindings
+ of its own. */
+ if (NILP (no_remap)
+ && SYMBOLP (definition)
+ && !NILP (Fcommand_remapping (definition, Qnil, keymaps)))
+ RETURN_UNGCPRO (Qnil);
+
for (; !NILP (maps); maps = Fcdr (maps))
{
/* Key sequence to reach map, and the map that it reaches */
DEFVAR_LISP ("minor-mode-map-alist", &Vminor_mode_map_alist,
doc: /* Alist of keymaps to use for minor modes.
Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read
-key sequences and look up bindings iff VARIABLE's value is non-nil.
+key sequences and look up bindings if VARIABLE's value is non-nil.
If two active keymaps bind the same key, the keymap appearing earlier
in the list takes precedence. */);
Vminor_mode_map_alist = Qnil;