comparison src/keymap.c @ 272:c5d627a313b1 r21-0b34

Import from CVS: tag r21-0b34
author cvs
date Mon, 13 Aug 2007 10:28:48 +0200
parents 966663fcf606
children c42ec1d1cded
comparison
equal deleted inserted replaced
271:c7b7086b0a39 272:c5d627a313b1
216 216
217 /* Prefixing a key with this character is the same as sending a meta bit. */ 217 /* Prefixing a key with this character is the same as sending a meta bit. */
218 Lisp_Object Vmeta_prefix_char; 218 Lisp_Object Vmeta_prefix_char;
219 219
220 Lisp_Object Qkeymapp; 220 Lisp_Object Qkeymapp;
221
222 Lisp_Object Vsingle_space_string; 221 Lisp_Object Vsingle_space_string;
223
224 Lisp_Object Qsuppress_keymap; 222 Lisp_Object Qsuppress_keymap;
225
226 Lisp_Object Qmodeline_map; 223 Lisp_Object Qmodeline_map;
227 Lisp_Object Qtoolbar_map; 224 Lisp_Object Qtoolbar_map;
225
226 EXFUN (Fkeymap_fullness, 1);
227 EXFUN (Fset_keymap_name, 2);
228 EXFUN (Fsingle_key_description, 1);
228 229
229 static void describe_command (Lisp_Object definition, Lisp_Object buffer); 230 static void describe_command (Lisp_Object definition, Lisp_Object buffer);
230 static void describe_map (Lisp_Object keymap, Lisp_Object elt_prefix, 231 static void describe_map (Lisp_Object keymap, Lisp_Object elt_prefix,
231 void (*elt_describer) (Lisp_Object, Lisp_Object), 232 void (*elt_describer) (Lisp_Object, Lisp_Object),
232 int partial, 233 int partial,
233 Lisp_Object shadow, 234 Lisp_Object shadow,
234 int mice_only_p, 235 int mice_only_p,
235 Lisp_Object buffer); 236 Lisp_Object buffer);
237
236 Lisp_Object Qcontrol, Qctrl, Qmeta, Qsuper, Qhyper, Qalt, Qshift; 238 Lisp_Object Qcontrol, Qctrl, Qmeta, Qsuper, Qhyper, Qalt, Qshift;
237 /* Lisp_Object Qsymbol; defined in general.c */ 239 Lisp_Object Qbutton0, Qbutton1, Qbutton2, Qbutton3;
238 Lisp_Object Qbutton0, Qbutton1, Qbutton2, Qbutton3, Qbutton4, Qbutton5, 240 Lisp_Object Qbutton4, Qbutton5, Qbutton6, Qbutton7;
239 Qbutton6, Qbutton7; 241 Lisp_Object Qbutton0up, Qbutton1up, Qbutton2up, Qbutton3up;
240 Lisp_Object Qbutton0up, Qbutton1up, Qbutton2up, Qbutton3up, Qbutton4up, 242 Lisp_Object Qbutton4up, Qbutton5up, Qbutton6up, Qbutton7up;
241 Qbutton5up, Qbutton6up, Qbutton7up; 243
242 #if defined(HAVE_OFFIX_DND) || defined(HAVE_MS_WINDOWS) 244 #if defined(HAVE_OFFIX_DND) || defined(HAVE_MS_WINDOWS)
243 Lisp_Object Qdrop0, Qdrop1, Qdrop2, Qdrop3, Qdrop4, Qdrop5, Qdrop6, Qdrop7; 245 Lisp_Object Qdrop0, Qdrop1, Qdrop2, Qdrop3, Qdrop4, Qdrop5, Qdrop6, Qdrop7;
244 #endif 246 #endif
245 Lisp_Object Qmenu_selection; 247 Lisp_Object Qmenu_selection;
246 /* Emacs compatibility */ 248 /* Emacs compatibility */
254 256
255 /************************************************************************/ 257 /************************************************************************/
256 /* The keymap Lisp object */ 258 /* The keymap Lisp object */
257 /************************************************************************/ 259 /************************************************************************/
258 260
259 static Lisp_Object mark_keymap (Lisp_Object, void (*) (Lisp_Object));
260 static void print_keymap (Lisp_Object, Lisp_Object, int);
261 /* No need for keymap_equal #### Why not? */
262 DEFINE_LRECORD_IMPLEMENTATION ("keymap", keymap,
263 mark_keymap, print_keymap, 0, 0, 0,
264 struct keymap);
265 static Lisp_Object 261 static Lisp_Object
266 mark_keymap (Lisp_Object obj, void (*markobj) (Lisp_Object)) 262 mark_keymap (Lisp_Object obj, void (*markobj) (Lisp_Object))
267 { 263 {
268 struct keymap *keymap = XKEYMAP (obj); 264 struct keymap *keymap = XKEYMAP (obj);
269 ((markobj) (keymap->parents)); 265 ((markobj) (keymap->parents));
294 ((size == 1) ? "y" : "ies"), 290 ((size == 1) ? "y" : "ies"),
295 keymap->header.uid); 291 keymap->header.uid);
296 write_c_string (buf, printcharfun); 292 write_c_string (buf, printcharfun);
297 } 293 }
298 294
295 /* No need for keymap_equal #### Why not? */
296 DEFINE_LRECORD_IMPLEMENTATION ("keymap", keymap,
297 mark_keymap, print_keymap, 0, 0, 0,
298 struct keymap);
299 299
300 /************************************************************************/ 300 /************************************************************************/
301 /* Traversing keymaps and their parents */ 301 /* Traversing keymaps and their parents */
302 /************************************************************************/ 302 /************************************************************************/
303 303
751 /************************************************************************/ 751 /************************************************************************/
752 752
753 static Lisp_Object 753 static Lisp_Object
754 make_keymap (int size) 754 make_keymap (int size)
755 { 755 {
756 Lisp_Object result = Qnil; 756 Lisp_Object result;
757 struct keymap *keymap = alloc_lcrecord_type (struct keymap, lrecord_keymap); 757 struct keymap *keymap = alloc_lcrecord_type (struct keymap, lrecord_keymap);
758 758
759 XSETKEYMAP (result, keymap); 759 XSETKEYMAP (result, keymap);
760 760
761 keymap->parents = Qnil; 761 keymap->parents = Qnil;
810 Fset_keymap_name (keymap, name); 810 Fset_keymap_name (keymap, name);
811 return keymap; 811 return keymap;
812 } 812 }
813 813
814 DEFUN ("keymap-parents", Fkeymap_parents, 1, 1, 0, /* 814 DEFUN ("keymap-parents", Fkeymap_parents, 1, 1, 0, /*
815 Return the `parent' keymaps of the given keymap, or nil. 815 Return the `parent' keymaps of KEYMAP, or nil.
816 The parents of a keymap are searched for keybindings when a key sequence 816 The parents of a keymap are searched for keybindings when a key sequence
817 isn't bound in this one. `(current-global-map)' is the default parent 817 isn't bound in this one. `(current-global-map)' is the default parent
818 of all keymaps. 818 of all keymaps.
819 */ 819 */
820 (keymap)) 820 (keymap))
830 { 830 {
831 return Qnil; 831 return Qnil;
832 } 832 }
833 833
834 DEFUN ("set-keymap-parents", Fset_keymap_parents, 2, 2, 0, /* 834 DEFUN ("set-keymap-parents", Fset_keymap_parents, 2, 2, 0, /*
835 Sets the `parent' keymaps of the given keymap. 835 Set the `parent' keymaps of KEYMAP to PARENTS.
836 The parents of a keymap are searched for keybindings when a key sequence 836 The parents of a keymap are searched for keybindings when a key sequence
837 isn't bound in this one. `(current-global-map)' is the default parent 837 isn't bound in this one. `(current-global-map)' is the default parent
838 of all keymaps. 838 of all keymaps.
839 */ 839 */
840 (keymap, parents)) 840 (keymap, parents))
895 895
896 return XKEYMAP (keymap)->name; 896 return XKEYMAP (keymap)->name;
897 } 897 }
898 898
899 DEFUN ("set-keymap-prompt", Fset_keymap_prompt, 2, 2, 0, /* 899 DEFUN ("set-keymap-prompt", Fset_keymap_prompt, 2, 2, 0, /*
900 Sets the `prompt' of KEYMAP to string NEW-PROMPT, or `nil' 900 Set the `prompt' of KEYMAP to string NEW-PROMPT, or `nil'
901 if no prompt is desired. The prompt is shown in the echo-area 901 if no prompt is desired. The prompt is shown in the echo-area
902 when reading a key-sequence to be looked-up in this keymap. 902 when reading a key-sequence to be looked-up in this keymap.
903 */ 903 */
904 (keymap, new_prompt)) 904 (keymap, new_prompt))
905 { 905 {
918 return XKEYMAP (keymap)->prompt; 918 return XKEYMAP (keymap)->prompt;
919 } 919 }
920 920
921 921
922 DEFUN ("keymap-prompt", Fkeymap_prompt, 1, 2, 0, /* 922 DEFUN ("keymap-prompt", Fkeymap_prompt, 1, 2, 0, /*
923 Return the `prompt' of the given keymap. 923 Return the `prompt' of KEYMAP.
924 If non-nil, the prompt is shown in the echo-area 924 If non-nil, the prompt is shown in the echo-area
925 when reading a key-sequence to be looked-up in this keymap. 925 when reading a key-sequence to be looked-up in this keymap.
926 */ 926 */
927 (keymap, use_inherited)) 927 (keymap, use_inherited))
928 { 928 {
1873 struct gcpro gcpro1, gcpro2, gcpro3; 1873 struct gcpro gcpro1, gcpro2, gcpro3;
1874 1874
1875 if (VECTORP (keys)) 1875 if (VECTORP (keys))
1876 len = XVECTOR_LENGTH (keys); 1876 len = XVECTOR_LENGTH (keys);
1877 else if (STRINGP (keys)) 1877 else if (STRINGP (keys))
1878 len = string_char_length (XSTRING (keys)); 1878 len = XSTRING_CHAR_LENGTH (keys);
1879 else if (CHAR_OR_CHAR_INTP (keys) || SYMBOLP (keys) || CONSP (keys)) 1879 else if (CHAR_OR_CHAR_INTP (keys) || SYMBOLP (keys) || CONSP (keys))
1880 { 1880 {
1881 if (!CONSP (keys)) keys = list1 (keys); 1881 if (!CONSP (keys)) keys = list1 (keys);
1882 len = 1; 1882 len = 1;
1883 keys = make_vector (1, keys); /* this is kinda sleazy. */ 1883 keys = make_vector (1, keys); /* this is kinda sleazy. */
2223 */ 2223 */
2224 (keymap, keys, accept_default)) 2224 (keymap, keys, accept_default))
2225 { 2225 {
2226 /* This function can GC */ 2226 /* This function can GC */
2227 if (VECTORP (keys)) 2227 if (VECTORP (keys))
2228 { 2228 return lookup_keys (keymap,
2229 return lookup_keys (keymap, 2229 XVECTOR_LENGTH (keys),
2230 XVECTOR_LENGTH (keys), 2230 XVECTOR_DATA (keys),
2231 XVECTOR_DATA (keys), 2231 !NILP (accept_default));
2232 !NILP (accept_default));
2233 }
2234 else if (SYMBOLP (keys) || CHAR_OR_CHAR_INTP (keys) || CONSP (keys)) 2232 else if (SYMBOLP (keys) || CHAR_OR_CHAR_INTP (keys) || CONSP (keys))
2235 { 2233 return lookup_keys (keymap, 1, &keys, !NILP (accept_default));
2236 return lookup_keys (keymap, 1, &keys, 2234 else if (STRINGP (keys))
2237 !NILP (accept_default)); 2235 {
2238 } 2236 int length = XSTRING_CHAR_LENGTH (keys);
2239 else if (!STRINGP (keys))
2240 {
2241 keys = wrong_type_argument (Qsequencep, keys);
2242 return Flookup_key (keymap, keys, accept_default);
2243 }
2244 else /* STRINGP (keys) */
2245 {
2246 int length = string_char_length (XSTRING (keys));
2247 int i; 2237 int i;
2248 struct key_data *raw_keys = alloca_array (struct key_data, length); 2238 struct key_data *raw_keys = alloca_array (struct key_data, length);
2249 if (length == 0) 2239 if (length == 0)
2250 return Qnil; 2240 return Qnil;
2251 2241
2254 Emchar n = string_char (XSTRING (keys), i); 2244 Emchar n = string_char (XSTRING (keys), i);
2255 define_key_parser (make_char (n), &(raw_keys[i])); 2245 define_key_parser (make_char (n), &(raw_keys[i]));
2256 } 2246 }
2257 return raw_lookup_key (keymap, raw_keys, length, 0, 2247 return raw_lookup_key (keymap, raw_keys, length, 0,
2258 !NILP (accept_default)); 2248 !NILP (accept_default));
2249 }
2250 else
2251 {
2252 keys = wrong_type_argument (Qsequencep, keys);
2253 return Flookup_key (keymap, keys, accept_default);
2259 } 2254 }
2260 } 2255 }
2261 2256
2262 /* Given a key sequence, returns a list of keymaps to search for bindings. 2257 /* Given a key sequence, returns a list of keymaps to search for bindings.
2263 Does all manner of semi-hairy heuristics, like looking in the current 2258 Does all manner of semi-hairy heuristics, like looking in the current
3005 the function is unspecified. If the function inserts new elements into 3000 the function is unspecified. If the function inserts new elements into
3006 the keymap, it may or may not be called with them later. No element of 3001 the keymap, it may or may not be called with them later. No element of
3007 the keymap will ever be passed to the function more than once. 3002 the keymap will ever be passed to the function more than once.
3008 3003
3009 The function will not be called on elements of this keymap's parents 3004 The function will not be called on elements of this keymap's parents
3010 (see the function `keymap-parents') or upon keymaps which are contained 3005 \(see the function `keymap-parents') or upon keymaps which are contained
3011 within this keymap (multi-character definitions). 3006 within this keymap (multi-character definitions).
3012 It will be called on "meta" characters since they are not really 3007 It will be called on "meta" characters since they are not really
3013 two-character sequences. 3008 two-character sequences.
3014 3009
3015 If the optional third argument SORT-FIRST is non-nil, then the elements of 3010 If the optional third argument SORT-FIRST is non-nil, then the elements of
3319 */ 3314 */
3320 (chr)) 3315 (chr))
3321 { 3316 {
3322 Bufbyte buf[200]; 3317 Bufbyte buf[200];
3323 Bufbyte *p; 3318 Bufbyte *p;
3324 unsigned int c; 3319 Emchar c;
3325 Lisp_Object ctl_arrow = current_buffer->ctl_arrow; 3320 Lisp_Object ctl_arrow = current_buffer->ctl_arrow;
3326 int ctl_p = !NILP (ctl_arrow); 3321 int ctl_p = !NILP (ctl_arrow);
3327 Emchar printable_min = (CHAR_OR_CHAR_INTP (ctl_arrow) 3322 Emchar printable_min = (CHAR_OR_CHAR_INTP (ctl_arrow)
3328 ? XCHAR_OR_CHAR_INT (ctl_arrow) 3323 ? XCHAR_OR_CHAR_INT (ctl_arrow)
3329 : ((EQ (ctl_arrow, Qt) || NILP (ctl_arrow)) 3324 : ((EQ (ctl_arrow, Qt) || NILP (ctl_arrow))
3939 (struct describe_map_shadow_closure *) arg; 3934 (struct describe_map_shadow_closure *) arg;
3940 3935
3941 if (EQ (map, c->self)) 3936 if (EQ (map, c->self))
3942 return Qzero; /* Not shadowed; terminate search */ 3937 return Qzero; /* Not shadowed; terminate search */
3943 3938
3944 return (!NILP (keymap_lookup_directly (map, 3939 return !NILP (keymap_lookup_directly (map,
3945 c->raw_key->keysym, 3940 c->raw_key->keysym,
3946 c->raw_key->modifiers))) 3941 c->raw_key->modifiers))
3947 ? Qt : Qnil; 3942 ? Qt : Qnil;
3948 } 3943 }
3949 3944
3950 3945
3951 static Lisp_Object 3946 static Lisp_Object