comparison src/keymap.c @ 108678:46728260f484

* src/keymap.c (Fwhere_is_internal): Fix handling of remapping (in thread of bug#6305).
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 31 May 2010 15:35:04 -0400
parents e09a216f2aab
children 8e26c16cde27 d657dd1ad387
comparison
equal deleted inserted replaced
108677:7a38217041bb 108678:46728260f484
2827 Lisp_Object sequences = Qnil; 2827 Lisp_Object sequences = Qnil;
2828 /* Actually relevant bindings. */ 2828 /* Actually relevant bindings. */
2829 Lisp_Object found = Qnil; 2829 Lisp_Object found = Qnil;
2830 /* 1 means ignore all menu bindings entirely. */ 2830 /* 1 means ignore all menu bindings entirely. */
2831 int nomenus = !NILP (firstonly) && !EQ (firstonly, Qnon_ascii); 2831 int nomenus = !NILP (firstonly) && !EQ (firstonly, Qnon_ascii);
2832 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 2832 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
2833 /* List of sequences found via remapping. Keep them in a separate 2833 /* List of sequences found via remapping. Keep them in a separate
2834 variable, so as to push them later, since we prefer 2834 variable, so as to push them later, since we prefer
2835 non-remapped binding. */ 2835 non-remapped binding. */
2836 Lisp_Object remapped_sequences = Qnil; 2836 Lisp_Object remapped_sequences = Qnil;
2837 /* Whether or not we're handling remapped sequences. This is needed 2837 /* Whether or not we're handling remapped sequences. This is needed
2838 because remapping is not done recursively by Fcommand_remapping: you 2838 because remapping is not done recursively by Fcommand_remapping: you
2839 can't remap and remapped command. */ 2839 can't remap a remapped command. */
2840 int remapped = 0; 2840 int remapped = 0;
2841 Lisp_Object tem; 2841 Lisp_Object tem = Qnil;
2842 2842
2843 /* Refresh the C version of the modifier preference. */ 2843 /* Refresh the C version of the modifier preference. */
2844 where_is_preferred_modifier 2844 where_is_preferred_modifier
2845 = parse_solitary_modifier (Vwhere_is_preferred_modifier); 2845 = parse_solitary_modifier (Vwhere_is_preferred_modifier);
2846 2846
2850 else if (!NILP (keymap)) 2850 else if (!NILP (keymap))
2851 keymaps = Fcons (keymap, Fcons (current_global_map, Qnil)); 2851 keymaps = Fcons (keymap, Fcons (current_global_map, Qnil));
2852 else 2852 else
2853 keymaps = Fcurrent_active_maps (Qnil, Qnil); 2853 keymaps = Fcurrent_active_maps (Qnil, Qnil);
2854 2854
2855 GCPRO5 (definition, keymaps, found, sequences, remapped_sequences); 2855 GCPRO6 (definition, keymaps, found, sequences, remapped_sequences, tem);
2856 2856
2857 /* If this command is remapped, then it has no key bindings of its own. 2857 tem = Fcommand_remapping (definition, Qnil, keymaps);
2858 FIXME: Actually, this is not quite right: if A is remapped to 2858 /* If `definition' is remapped to tem', then OT1H no key will run
2859 `definition', then bindings to A will actually bind the key to 2859 that command (since they will run `tem' instead), so we should
2860 `definition' despite the remapping from `definition' to something else. 2860 return nil; but OTOH all keys bound to `definition' (or to `tem')
2861 Another corner case is if `definition' is remapped to itself. */ 2861 will run the same command.
2862 if (NILP (no_remap) 2862 So for menu-shortcut purposes, we want to find all the keys bound (maybe
2863 && SYMBOLP (definition) 2863 via remapping) to `tem'. But for the purpose of finding the keys that
2864 && !NILP (Fcommand_remapping (definition, Qnil, keymaps))) 2864 run `definition', then we'd want to just return nil.
2865 RETURN_UNGCPRO (Qnil); 2865 We choose to make it work right for menu-shortcuts, since it's the most
2866 common use.
2867 Known bugs: if you remap switch-to-buffer to toto, C-h f switch-to-buffer
2868 will tell you that switch-to-buffer is bound to C-x b even though C-x b
2869 will run toto instead. And if `toto' is itself remapped to forward-char,
2870 then C-h f toto will tell you that it's bound to C-f even though C-f does
2871 not run toto and it won't tell you that C-x b does run toto. */
2872 if (NILP (no_remap) && !NILP (tem))
2873 definition = tem;
2866 2874
2867 if (SYMBOLP (definition) 2875 if (SYMBOLP (definition)
2868 && !NILP (firstonly) 2876 && !NILP (firstonly)
2869 && !NILP (tem = Fget (definition, QCadvertised_binding))) 2877 && !NILP (tem = Fget (definition, QCadvertised_binding)))
2870 { 2878 {