From 1ab8293c369c39375d17e50b0664b2d20f7b7871 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Mon, 31 May 2010 15:35:04 -0400 Subject: [PATCH] * src/keymap.c (Fwhere_is_internal): Fix handling of remapping (in thread of bug#6305). --- src/ChangeLog | 5 +++++ src/keymap.c | 36 ++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 2bf7617b4e8..4e0b04def0c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-05-31 Stefan Monnier + + * keymap.c (Fwhere_is_internal): Fix handling of remapping (in thread + of bug#6305). + 2010-05-27 Chong Yidong * xdisp.c (redisplay_window): After redisplay, check if point is diff --git a/src/keymap.c b/src/keymap.c index 88e0687272f..53b6795d623 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -2829,16 +2829,16 @@ remapped command in the returned list. */) Lisp_Object found = Qnil; /* 1 means ignore all menu bindings entirely. */ int nomenus = !NILP (firstonly) && !EQ (firstonly, Qnon_ascii); - struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; + 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 non-remapped binding. */ Lisp_Object remapped_sequences = Qnil; /* Whether or not we're handling remapped sequences. This is needed because remapping is not done recursively by Fcommand_remapping: you - can't remap and remapped command. */ + can't remap a remapped command. */ int remapped = 0; - Lisp_Object tem; + Lisp_Object tem = Qnil; /* Refresh the C version of the modifier preference. */ where_is_preferred_modifier @@ -2852,17 +2852,25 @@ remapped command in the returned list. */) else keymaps = Fcurrent_active_maps (Qnil, Qnil); - GCPRO5 (definition, keymaps, found, sequences, remapped_sequences); - - /* If this command is remapped, then it has no key bindings of its own. - FIXME: Actually, this is not quite right: if A is remapped to - `definition', then bindings to A will actually bind the key to - `definition' despite the remapping from `definition' to something else. - Another corner case is if `definition' is remapped to itself. */ - if (NILP (no_remap) - && SYMBOLP (definition) - && !NILP (Fcommand_remapping (definition, Qnil, keymaps))) - RETURN_UNGCPRO (Qnil); + GCPRO6 (definition, keymaps, found, sequences, remapped_sequences, tem); + + tem = Fcommand_remapping (definition, Qnil, keymaps); + /* If `definition' is remapped to tem', then OT1H no key will run + that command (since they will run `tem' instead), so we should + return nil; but OTOH all keys bound to `definition' (or to `tem') + will run the same command. + So for menu-shortcut purposes, we want to find all the keys bound (maybe + via remapping) to `tem'. But for the purpose of finding the keys that + run `definition', then we'd want to just return nil. + We choose to make it work right for menu-shortcuts, since it's the most + common use. + Known bugs: if you remap switch-to-buffer to toto, C-h f switch-to-buffer + will tell you that switch-to-buffer is bound to C-x b even though C-x b + will run toto instead. And if `toto' is itself remapped to forward-char, + then C-h f toto will tell you that it's bound to C-f even though C-f does + not run toto and it won't tell you that C-x b does run toto. */ + if (NILP (no_remap) && !NILP (tem)) + definition = tem; if (SYMBOLP (definition) && !NILP (firstonly) -- 2.39.2