comparison src/keymap.c @ 96675:d45acf0c8d23

merging Emacs.app (NeXTstep port)
author Adrian Robert <Adrian.B.Robert@gmail.com>
date Tue, 15 Jul 2008 18:15:18 +0000
parents d34a432d5863
children ebf3bd5f0017
comparison
equal deleted inserted replaced
96674:ff312a846b25 96675:d45acf0c8d23
108 in a string key sequence is equivalent to prefixing with this 108 in a string key sequence is equivalent to prefixing with this
109 character. */ 109 character. */
110 extern Lisp_Object meta_prefix_char; 110 extern Lisp_Object meta_prefix_char;
111 111
112 extern Lisp_Object Voverriding_local_map; 112 extern Lisp_Object Voverriding_local_map;
113
114 #ifdef HAVE_NS
115 extern Lisp_Object Qalt, Qcontrol, Qhyper, Qmeta, Qsuper;
116 #endif
113 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. */
117 static Lisp_Object where_is_cache_keymaps; 121 static Lisp_Object where_is_cache_keymaps;
2619 } 2623 }
2620 2624
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
2627 static Lisp_Object where_is_internal (); 2666 static Lisp_Object where_is_internal ();
2628 static void where_is_internal_1 P_ ((Lisp_Object key, Lisp_Object binding, 2667 static void where_is_internal_1 P_ ((Lisp_Object key, Lisp_Object binding,
2801 binding we find. If firstonly is not Qnon_ascii but not 2840 binding we find. If firstonly is not Qnon_ascii but not
2802 nil, then we should return the first ascii-only binding 2841 nil, then we should return the first ascii-only binding
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
2809 if (CONSP (remapped)) 2856 if (CONSP (remapped))
2810 { 2857 {
2834 If KEYMAP is nil, search all the currently active keymaps. 2881 If KEYMAP is nil, search all the currently active keymaps.
2835 If KEYMAP is a list of keymaps, search only those keymaps. 2882 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
2842 \(or their meta variants) and entirely reject menu bindings. 2893 \(or their meta variants) and entirely reject menu bindings.
2843 2894
2907 result = Qnil; 2958 result = Qnil;
2908 j = -1; 2959 j = -1;
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);
2919 UNGCPRO; 2979 UNGCPRO;
2920 } 2980 }