aboutsummaryrefslogtreecommitdiffstats
path: root/src/keymap.c
diff options
context:
space:
mode:
authorStefan Monnier2009-09-09 02:38:50 +0000
committerStefan Monnier2009-09-09 02:38:50 +0000
commitf9b7b5acb56f3d7a785d079eb13318e33bca9047 (patch)
tree6564d963cca460a212e1168628da92a45be441a1 /src/keymap.c
parent45980501ae85160d9af0988749043df910759fa9 (diff)
downloademacs-f9b7b5acb56f3d7a785d079eb13318e33bca9047.tar.gz
emacs-f9b7b5acb56f3d7a785d079eb13318e33bca9047.zip
(where_is_internal): Filter out shadowed remappings.
Assume that where_is_internal returns unshadowed bindings to simplify the code and get rid of the gotos. Use ASIZE.
Diffstat (limited to 'src/keymap.c')
-rw-r--r--src/keymap.c96
1 files changed, 41 insertions, 55 deletions
diff --git a/src/keymap.c b/src/keymap.c
index 02e93675548..dcf8e19900c 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -2758,30 +2758,6 @@ where_is_internal (definition, keymaps, firstonly, noindirect, no_remap)
2758 sequence = XCAR (sequences); 2758 sequence = XCAR (sequences);
2759 sequences = XCDR (sequences); 2759 sequences = XCDR (sequences);
2760 2760
2761 /* If the current sequence is a command remapping with
2762 format [remap COMMAND], find the key sequences
2763 which run COMMAND, and use those sequences instead. */
2764 remapped = Qnil;
2765 if (NILP (no_remap)
2766 && VECTORP (sequence) && XVECTOR (sequence)->size == 2
2767 && EQ (AREF (sequence, 0), Qremap)
2768 && (function = AREF (sequence, 1), SYMBOLP (function)))
2769 {
2770 Lisp_Object remapped1;
2771
2772 remapped1 = where_is_internal (function, keymaps, firstonly, noindirect, Qt);
2773 if (CONSP (remapped1))
2774 {
2775 /* Verify that this key binding actually maps to the
2776 remapped command (see below). */
2777 if (!EQ (shadow_lookup (keymaps, XCAR (remapped1), Qnil), function))
2778 continue;
2779 sequence = XCAR (remapped1);
2780 remapped = XCDR (remapped1);
2781 goto record_sequence;
2782 }
2783 }
2784
2785 /* Verify that this key binding is not shadowed by another 2761 /* Verify that this key binding is not shadowed by another
2786 binding for the same key, before we say it exists. 2762 binding for the same key, before we say it exists.
2787 2763
@@ -2794,39 +2770,49 @@ where_is_internal (definition, keymaps, firstonly, noindirect, no_remap)
2794 if (!EQ (shadow_lookup (keymaps, sequence, Qnil), definition)) 2770 if (!EQ (shadow_lookup (keymaps, sequence, Qnil), definition))
2795 continue; 2771 continue;
2796 2772
2797 record_sequence: 2773 /* If the current sequence is a command remapping with
2798 /* Don't annoy user with strings from a menu such as 2774 format [remap COMMAND], find the key sequences
2799 Select Paste. Change them all to "(any string)", 2775 which run COMMAND, and use those sequences instead. */
2800 so that there seems to be only one menu item 2776 if (NILP (no_remap)
2801 to report. */ 2777 && VECTORP (sequence) && XVECTOR (sequence)->size == 2
2802 if (! NILP (sequence)) 2778 && EQ (AREF (sequence, 0), Qremap)
2803 { 2779 && (function = AREF (sequence, 1), SYMBOLP (function)))
2804 Lisp_Object tem; 2780 remapped = where_is_internal (function, keymaps, firstonly,
2805 tem = Faref (sequence, make_number (XVECTOR (sequence)->size - 1)); 2781 noindirect, Qt);
2806 if (STRINGP (tem)) 2782 else
2807 Faset (sequence, make_number (XVECTOR (sequence)->size - 1), 2783 remapped = Fcons (sequence, Qnil);
2808 build_string ("(any string)"));
2809 }
2810 2784
2811 /* It is a true unshadowed match. Record it, unless it's already 2785 for (; CONSP (remapped);
2812 been seen (as could happen when inheriting keymaps). */ 2786 sequence = XCAR (remapped), remapped = XCDR (remapped))
2813 if (NILP (Fmember (sequence, found)))
2814 found = Fcons (sequence, found);
2815
2816 /* If firstonly is Qnon_ascii, then we can return the first
2817 binding we find. If firstonly is not Qnon_ascii but not
2818 nil, then we should return the first ascii-only binding
2819 we find. */
2820 if (EQ (firstonly, Qnon_ascii))
2821 RETURN_UNGCPRO (sequence);
2822 else if (!NILP (firstonly) && 2 == preferred_sequence_p (sequence))
2823 RETURN_UNGCPRO (sequence);
2824
2825 if (CONSP (remapped))
2826 { 2787 {
2827 sequence = XCAR (remapped); 2788 /* Don't annoy user with strings from a menu such as the
2828 remapped = XCDR (remapped); 2789 entries from the "Edit => Paste from Kill Menu".
2829 goto record_sequence; 2790 Change them all to "(any string)", so that there
2791 seems to be only one menu item to report. */
2792 if (! NILP (sequence))
2793 {
2794 Lisp_Object tem;
2795 tem = Faref (sequence, make_number (ASIZE (sequence) - 1));
2796 if (STRINGP (tem))
2797 Faset (sequence, make_number (ASIZE (sequence) - 1),
2798 build_string ("(any string)"));
2799 }
2800
2801 /* It is a true unshadowed match. Record it, unless it's already
2802 been seen (as could happen when inheriting keymaps). */
2803 if (NILP (Fmember (sequence, found)))
2804 found = Fcons (sequence, found);
2805
2806 /* If firstonly is Qnon_ascii, then we can return the first
2807 binding we find. If firstonly is not Qnon_ascii but not
2808 nil, then we should return the first ascii-only binding
2809 we find. */
2810 if (EQ (firstonly, Qnon_ascii))
2811 RETURN_UNGCPRO (sequence);
2812 else if (!NILP (firstonly)
2813 && 2 == preferred_sequence_p (sequence))
2814 RETURN_UNGCPRO (sequence);
2815
2830 } 2816 }
2831 } 2817 }
2832 } 2818 }