diff options
Diffstat (limited to 'src/keymap.c')
| -rw-r--r-- | src/keymap.c | 68 |
1 files changed, 64 insertions, 4 deletions
diff --git a/src/keymap.c b/src/keymap.c index 7a9b5949151..545ab3de81e 100644 --- a/src/keymap.c +++ b/src/keymap.c | |||
| @@ -111,6 +111,10 @@ extern Lisp_Object meta_prefix_char; | |||
| 111 | 111 | ||
| 112 | extern Lisp_Object Voverriding_local_map; | 112 | extern Lisp_Object Voverriding_local_map; |
| 113 | 113 | ||
| 114 | #ifdef HAVE_NS | ||
| 115 | extern Lisp_Object Qalt, Qcontrol, Qhyper, Qmeta, Qsuper; | ||
| 116 | #endif | ||
| 117 | |||
| 114 | /* Hash table used to cache a reverse-map to speed up calls to where-is. */ | 118 | /* Hash table used to cache a reverse-map to speed up calls to where-is. */ |
| 115 | static Lisp_Object where_is_cache; | 119 | static Lisp_Object where_is_cache; |
| 116 | /* Which keymaps are reverse-stored in the cache. */ | 120 | /* Which keymaps are reverse-stored in the cache. */ |
| @@ -2621,6 +2625,41 @@ ascii_sequence_p (seq) | |||
| 2621 | return 1; | 2625 | return 1; |
| 2622 | } | 2626 | } |
| 2623 | 2627 | ||
| 2628 | #ifdef HAVE_NS | ||
| 2629 | int lisp_to_mod(Lisp_Object lmod) | ||
| 2630 | /* ------------------------------------------------------------------------- | ||
| 2631 | Convert lisp symbol to emacs modifier code. | ||
| 2632 | ------------------------------------------------------------------------- */ | ||
| 2633 | { | ||
| 2634 | if (EQ(lmod, Qmeta)) | ||
| 2635 | return meta_modifier; | ||
| 2636 | else if (EQ(lmod, Qsuper)) | ||
| 2637 | return super_modifier; | ||
| 2638 | else if (EQ(lmod, Qcontrol)) | ||
| 2639 | return ctrl_modifier; | ||
| 2640 | else if (EQ(lmod, Qalt)) | ||
| 2641 | return alt_modifier; | ||
| 2642 | else if (EQ(lmod, Qhyper)) | ||
| 2643 | return hyper_modifier; | ||
| 2644 | return 0; | ||
| 2645 | } | ||
| 2646 | |||
| 2647 | /* Return non-zero if SEQ starts w/a char modified by given modifier only. */ | ||
| 2648 | static int | ||
| 2649 | modifier_sequence_p (Lisp_Object seq, Lisp_Object modifier) | ||
| 2650 | { | ||
| 2651 | Lisp_Object idx, elt; | ||
| 2652 | |||
| 2653 | if (XINT (Flength (seq)) == 0) | ||
| 2654 | return 0; | ||
| 2655 | XSETFASTINT(idx, 0); | ||
| 2656 | elt = Faref(seq, idx); | ||
| 2657 | |||
| 2658 | return (XUINT(elt) & (CHAR_MODIFIER_MASK ^ shift_modifier)) | ||
| 2659 | == lisp_to_mod(modifier); | ||
| 2660 | } | ||
| 2661 | #endif | ||
| 2662 | |||
| 2624 | 2663 | ||
| 2625 | /* where-is - finding a command in a set of keymaps. */ | 2664 | /* where-is - finding a command in a set of keymaps. */ |
| 2626 | 2665 | ||
| @@ -2803,6 +2842,14 @@ where_is_internal (definition, keymaps, firstonly, noindirect, no_remap) | |||
| 2803 | we find. */ | 2842 | we find. */ |
| 2804 | if (EQ (firstonly, Qnon_ascii)) | 2843 | if (EQ (firstonly, Qnon_ascii)) |
| 2805 | RETURN_UNGCPRO (sequence); | 2844 | RETURN_UNGCPRO (sequence); |
| 2845 | #ifdef HAVE_NS | ||
| 2846 | /* respond to modifier preference */ | ||
| 2847 | else if ((EQ (firstonly, Qalt) || EQ (firstonly, Qcontrol) | ||
| 2848 | || EQ (firstonly, Qhyper) || EQ (firstonly, Qmeta) | ||
| 2849 | || EQ (firstonly, Qsuper))) | ||
| 2850 | if (modifier_sequence_p(sequence, firstonly)) | ||
| 2851 | RETURN_UNGCPRO (sequence); | ||
| 2852 | #endif | ||
| 2806 | else if (!NILP (firstonly) && ascii_sequence_p (sequence)) | 2853 | else if (!NILP (firstonly) && ascii_sequence_p (sequence)) |
| 2807 | RETURN_UNGCPRO (sequence); | 2854 | RETURN_UNGCPRO (sequence); |
| 2808 | 2855 | ||
| @@ -2836,6 +2883,10 @@ If KEYMAP is a list of keymaps, search only those keymaps. | |||
| 2836 | 2883 | ||
| 2837 | If optional 3rd arg FIRSTONLY is non-nil, return the first key sequence found, | 2884 | If optional 3rd arg FIRSTONLY is non-nil, return the first key sequence found, |
| 2838 | rather than a list of all possible key sequences. | 2885 | rather than a list of all possible key sequences. |
| 2886 | #ifdef HAVE_NS | ||
| 2887 | If FIRSTONLY is the symbol for a modifier key, return the first binding found, | ||
| 2888 | that is modified by that modifier only. | ||
| 2889 | #endif | ||
| 2839 | If FIRSTONLY is the symbol `non-ascii', return the first binding found, | 2890 | If FIRSTONLY is the symbol `non-ascii', return the first binding found, |
| 2840 | no matter what it is. | 2891 | no matter what it is. |
| 2841 | If FIRSTONLY has another non-nil value, prefer sequences of ASCII characters | 2892 | If FIRSTONLY has another non-nil value, prefer sequences of ASCII characters |
| @@ -2909,10 +2960,19 @@ remapped command in the returned list. */) | |||
| 2909 | for (i = n - 1; i >= 0; --i) | 2960 | for (i = n - 1; i >= 0; --i) |
| 2910 | if (EQ (shadow_lookup (keymaps, defns[i], Qnil), definition)) | 2961 | if (EQ (shadow_lookup (keymaps, defns[i], Qnil), definition)) |
| 2911 | { | 2962 | { |
| 2912 | if (ascii_sequence_p (defns[i])) | 2963 | #ifdef HAVE_NS |
| 2913 | break; | 2964 | if ((EQ (firstonly, Qalt) || EQ (firstonly, Qcontrol) |
| 2914 | else if (j < 0) | 2965 | || EQ (firstonly, Qhyper) || EQ (firstonly, Qmeta) |
| 2915 | j = i; | 2966 | || EQ (firstonly, Qsuper)) |
| 2967 | && modifier_sequence_p(defns[i], firstonly)) | ||
| 2968 | break; | ||
| 2969 | else if (EQ (firstonly, Qt) && ascii_sequence_p (defns[i])) | ||
| 2970 | #else | ||
| 2971 | if (ascii_sequence_p (defns[i])) | ||
| 2972 | #endif | ||
| 2973 | break; | ||
| 2974 | else if (j < 0) | ||
| 2975 | j = i; | ||
| 2916 | } | 2976 | } |
| 2917 | 2977 | ||
| 2918 | result = i >= 0 ? defns[i] : (j >= 0 ? defns[j] : Qnil); | 2978 | result = i >= 0 ? defns[i] : (j >= 0 ? defns[j] : Qnil); |