Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port command-remapping #1477

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions rust_src/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,4 +773,46 @@ pub fn apropos_internal(regexp: LispStringRef, predicate: LispObject) -> LispObj
}
}

// This function may GC (it calls Fkey_binding)
/// 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. 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.
#[lisp_fn(min = "1")]
pub fn command_remapping(
command: LispObject,
position: EmacsUInt,
keymaps: LispObject,
) -> LispObject {
let c = match command.as_symbol() {
None => return Qnil,
Some(c) => c,
};

unsafe {
c.set(position.into(), command_remapping_vector);
}

let remapped_command = if keymaps.is_nil() {
key_binding(command_remapping_vector, false, t, position.into());
} else {
lookup_key((Qkeymap, keymaps).into(), command_remapping_vector, Qnil);
};

if remapped_command.is_integer() {
Qnil
} else {
remapped_command
}
}

include!(concat!(env!("OUT_DIR"), "/keymap_exports.rs"));
35 changes: 0 additions & 35 deletions src/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ Lisp_Object apropos_accumulate;
/* Alist of elements like (DEL . "\d"). */
static Lisp_Object exclude_keys;

/* Pre-allocated 2-element vector for Fcommand_remapping to use. */
static Lisp_Object command_remapping_vector;

static Lisp_Object store_in_keymap (Lisp_Object, Lisp_Object, Lisp_Object);

static Lisp_Object define_as_prefix (Lisp_Object, Lisp_Object);
Expand Down Expand Up @@ -778,37 +775,6 @@ binding KEY to DEF is added at the front of KEYMAP. */)
}
}

/* This function may GC (it calls Fkey_binding). */

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. 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. */)
(Lisp_Object command, Lisp_Object position, Lisp_Object keymaps)
{
if (!SYMBOLP (command))
return Qnil;

ASET (command_remapping_vector, 1, command);

if (NILP (keymaps))
command = Fkey_binding (command_remapping_vector, Qnil, Qt, position);
else
command = Flookup_key (Fcons (Qkeymap, keymaps),
command_remapping_vector, Qnil);
return INTEGERP (command) ? Qnil : command;
}

/* Make KEYMAP define event C as a keymap (i.e., as a prefix).
Assume that currently it does not define C at all.
Return the keymap. */
Expand Down Expand Up @@ -3054,7 +3020,6 @@ be preferred. */);
command_remapping_vector = Fmake_vector (make_number (2), Qremap);
staticpro (&command_remapping_vector);

defsubr (&Scommand_remapping);
defsubr (&Sminor_mode_key_binding);
defsubr (&Sdefine_key);
defsubr (&Scurrent_minor_mode_maps);
Expand Down
2 changes: 2 additions & 0 deletions src/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,6 @@ extern void apropos_accum (Lisp_Object symbol, Lisp_Object string);
/* Apropos - finding all symbols whose names match a regexp. */
extern Lisp_Object apropos_predicate;
extern Lisp_Object apropos_accumulate;
/* Pre-allocated 2-element vector for Fcommand_remapping to use. */
extern Lisp_Object command_remapping_vector;
#endif