comparison src/keymap.c @ 109235:d53d2e9bef4f

Merge from mainline.
author Katsumi Yamaoka <katsumi@flagship2>
date Mon, 05 Jul 2010 11:22:19 +0000
parents 18f8e88d3829
children 750db9f3e6d8
comparison
equal deleted inserted replaced
109234:810852b2385b 109235:d53d2e9bef4f
181 For example: 181 For example:
182 182
183 initial_define_key (control_x_map, Ctl('X'), "exchange-point-and-mark"); */ 183 initial_define_key (control_x_map, Ctl('X'), "exchange-point-and-mark"); */
184 184
185 void 185 void
186 initial_define_key (keymap, key, defname) 186 initial_define_key (Lisp_Object keymap, int key, char *defname)
187 Lisp_Object keymap;
188 int key;
189 char *defname;
190 { 187 {
191 store_in_keymap (keymap, make_number (key), intern_c_string (defname)); 188 store_in_keymap (keymap, make_number (key), intern_c_string (defname));
192 } 189 }
193 190
194 void 191 void
195 initial_define_lispy_key (keymap, keyname, defname) 192 initial_define_lispy_key (Lisp_Object keymap, char *keyname, char *defname)
196 Lisp_Object keymap;
197 char *keyname;
198 char *defname;
199 { 193 {
200 store_in_keymap (keymap, intern_c_string (keyname), intern_c_string (defname)); 194 store_in_keymap (keymap, intern_c_string (keyname), intern_c_string (defname));
201 } 195 }
202 196
203 DEFUN ("keymapp", Fkeymapp, Skeymapp, 1, 1, 0, 197 DEFUN ("keymapp", Fkeymapp, Skeymapp, 1, 1, 0,
253 247
254 This function can GC when AUTOLOAD is non-zero, because it calls 248 This function can GC when AUTOLOAD is non-zero, because it calls
255 do_autoload which can GC. */ 249 do_autoload which can GC. */
256 250
257 Lisp_Object 251 Lisp_Object
258 get_keymap (object, error, autoload) 252 get_keymap (Lisp_Object object, int error, int autoload)
259 Lisp_Object object;
260 int error, autoload;
261 { 253 {
262 Lisp_Object tem; 254 Lisp_Object tem;
263 255
264 autoload_retry: 256 autoload_retry:
265 if (NILP (object)) 257 if (NILP (object))
307 299
308 /* Return the parent map of KEYMAP, or nil if it has none. 300 /* Return the parent map of KEYMAP, or nil if it has none.
309 We assume that KEYMAP is a valid keymap. */ 301 We assume that KEYMAP is a valid keymap. */
310 302
311 Lisp_Object 303 Lisp_Object
312 keymap_parent (keymap, autoload) 304 keymap_parent (Lisp_Object keymap, int autoload)
313 Lisp_Object keymap;
314 int autoload;
315 { 305 {
316 Lisp_Object list; 306 Lisp_Object list;
317 307
318 keymap = get_keymap (keymap, 1, autoload); 308 keymap = get_keymap (keymap, 1, autoload);
319 309
338 return keymap_parent (keymap, 1); 328 return keymap_parent (keymap, 1);
339 } 329 }
340 330
341 /* Check whether MAP is one of MAPS parents. */ 331 /* Check whether MAP is one of MAPS parents. */
342 int 332 int
343 keymap_memberp (map, maps) 333 keymap_memberp (Lisp_Object map, Lisp_Object maps)
344 Lisp_Object map, maps;
345 { 334 {
346 if (NILP (map)) return 0; 335 if (NILP (map)) return 0;
347 while (KEYMAPP (maps) && !EQ (map, maps)) 336 while (KEYMAPP (maps) && !EQ (map, maps))
348 maps = keymap_parent (maps, 0); 337 maps = keymap_parent (maps, 0);
349 return (EQ (map, maps)); 338 return (EQ (map, maps));
435 /* EVENT is defined in MAP as a prefix, and SUBMAP is its definition. 424 /* EVENT is defined in MAP as a prefix, and SUBMAP is its definition.
436 if EVENT is also a prefix in MAP's parent, 425 if EVENT is also a prefix in MAP's parent,
437 make sure that SUBMAP inherits that definition as its own parent. */ 426 make sure that SUBMAP inherits that definition as its own parent. */
438 427
439 static void 428 static void
440 fix_submap_inheritance (map, event, submap) 429 fix_submap_inheritance (Lisp_Object map, Lisp_Object event, Lisp_Object submap)
441 Lisp_Object map, event, submap;
442 { 430 {
443 Lisp_Object map_parent, parent_entry; 431 Lisp_Object map_parent, parent_entry;
444 432
445 /* SUBMAP is a cons that we found as a key binding. 433 /* SUBMAP is a cons that we found as a key binding.
446 Discard the other things found in a menu key binding. */ 434 Discard the other things found in a menu key binding. */
498 If T_OK is zero, bindings for Qt are not treated specially. 486 If T_OK is zero, bindings for Qt are not treated specially.
499 487
500 If NOINHERIT, don't accept a subkeymap found in an inherited keymap. */ 488 If NOINHERIT, don't accept a subkeymap found in an inherited keymap. */
501 489
502 Lisp_Object 490 Lisp_Object
503 access_keymap (map, idx, t_ok, noinherit, autoload) 491 access_keymap (Lisp_Object map, Lisp_Object idx, int t_ok, int noinherit, int autoload)
504 Lisp_Object map;
505 Lisp_Object idx;
506 int t_ok;
507 int noinherit;
508 int autoload;
509 { 492 {
510 Lisp_Object val; 493 Lisp_Object val;
511 494
512 /* Qunbound in VAL means we have found no binding yet. */ 495 /* Qunbound in VAL means we have found no binding yet. */
513 val = Qunbound; 496 val = Qunbound;
632 return get_keyelt (t_binding, autoload); 615 return get_keyelt (t_binding, autoload);
633 } 616 }
634 } 617 }
635 618
636 static void 619 static void
637 map_keymap_item (fun, args, key, val, data) 620 map_keymap_item (map_keymap_function_t fun, Lisp_Object args, Lisp_Object key, Lisp_Object val, void *data)
638 map_keymap_function_t fun;
639 Lisp_Object args, key, val;
640 void *data;
641 { 621 {
642 /* We should maybe try to detect bindings shadowed by previous 622 /* We should maybe try to detect bindings shadowed by previous
643 ones and things like that. */ 623 ones and things like that. */
644 if (EQ (val, Qt)) 624 if (EQ (val, Qt))
645 val = Qnil; 625 val = Qnil;
646 (*fun) (key, val, args, data); 626 (*fun) (key, val, args, data);
647 } 627 }
648 628
649 static void 629 static void
650 map_keymap_char_table_item (args, key, val) 630 map_keymap_char_table_item (Lisp_Object args, Lisp_Object key, Lisp_Object val)
651 Lisp_Object args, key, val;
652 { 631 {
653 if (!NILP (val)) 632 if (!NILP (val))
654 { 633 {
655 map_keymap_function_t fun = XSAVE_VALUE (XCAR (args))->pointer; 634 map_keymap_function_t fun = XSAVE_VALUE (XCAR (args))->pointer;
656 args = XCDR (args); 635 args = XCDR (args);
705 UNGCPRO; 684 UNGCPRO;
706 return tail; 685 return tail;
707 } 686 }
708 687
709 static void 688 static void
710 map_keymap_call (key, val, fun, dummy) 689 map_keymap_call (Lisp_Object key, Lisp_Object val, Lisp_Object fun, void *dummy)
711 Lisp_Object key, val, fun;
712 void *dummy;
713 { 690 {
714 call2 (fun, key, val); 691 call2 (fun, key, val);
715 } 692 }
716 693
717 /* Same as map_keymap_internal, but doesn't traverses parent keymaps as well. 694 /* Same as map_keymap_internal, but doesn't traverses parent keymaps as well.
718 A non-zero AUTOLOAD indicates that autoloaded keymaps should be loaded. */ 695 A non-zero AUTOLOAD indicates that autoloaded keymaps should be loaded. */
719 void 696 void
720 map_keymap (map, fun, args, data, autoload) 697 map_keymap (Lisp_Object map, map_keymap_function_t fun, Lisp_Object args, void *data, int autoload)
721 map_keymap_function_t fun;
722 Lisp_Object map, args;
723 void *data;
724 int autoload;
725 { 698 {
726 struct gcpro gcpro1; 699 struct gcpro gcpro1;
727 GCPRO1 (args); 700 GCPRO1 (args);
728 map = get_keymap (map, 1, autoload); 701 map = get_keymap (map, 1, autoload);
729 while (CONSP (map)) 702 while (CONSP (map))
737 Lisp_Object Qkeymap_canonicalize; 710 Lisp_Object Qkeymap_canonicalize;
738 711
739 /* Same as map_keymap, but does it right, properly eliminating duplicate 712 /* Same as map_keymap, but does it right, properly eliminating duplicate
740 bindings due to inheritance. */ 713 bindings due to inheritance. */
741 void 714 void
742 map_keymap_canonical (map, fun, args, data) 715 map_keymap_canonical (Lisp_Object map, map_keymap_function_t fun, Lisp_Object args, void *data)
743 map_keymap_function_t fun;
744 Lisp_Object map, args;
745 void *data;
746 { 716 {
747 struct gcpro gcpro1; 717 struct gcpro gcpro1;
748 GCPRO1 (args); 718 GCPRO1 (args);
749 /* map_keymap_canonical may be used from redisplay (e.g. when building menus) 719 /* map_keymap_canonical may be used from redisplay (e.g. when building menus)
750 so be careful to ignore errors and to inhibit redisplay. */ 720 so be careful to ignore errors and to inhibit redisplay. */
802 that are referred to with indirection. 772 that are referred to with indirection.
803 773
804 This can GC because menu_item_eval_property calls Feval. */ 774 This can GC because menu_item_eval_property calls Feval. */
805 775
806 Lisp_Object 776 Lisp_Object
807 get_keyelt (object, autoload) 777 get_keyelt (Lisp_Object object, int autoload)
808 Lisp_Object object;
809 int autoload;
810 { 778 {
811 while (1) 779 while (1)
812 { 780 {
813 if (!(CONSP (object))) 781 if (!(CONSP (object)))
814 /* This is really the value. */ 782 /* This is really the value. */
884 } 852 }
885 } 853 }
886 } 854 }
887 855
888 static Lisp_Object 856 static Lisp_Object
889 store_in_keymap (keymap, idx, def) 857 store_in_keymap (Lisp_Object keymap, register Lisp_Object idx, Lisp_Object def)
890 Lisp_Object keymap;
891 register Lisp_Object idx;
892 Lisp_Object def;
893 { 858 {
894 /* Flush any reverse-map cache. */ 859 /* Flush any reverse-map cache. */
895 where_is_cache = Qnil; 860 where_is_cache = Qnil;
896 where_is_cache_keymaps = Qt; 861 where_is_cache_keymaps = Qt;
897 862
1042 } 1007 }
1043 1008
1044 EXFUN (Fcopy_keymap, 1); 1009 EXFUN (Fcopy_keymap, 1);
1045 1010
1046 Lisp_Object 1011 Lisp_Object
1047 copy_keymap_item (elt) 1012 copy_keymap_item (Lisp_Object elt)
1048 Lisp_Object elt;
1049 { 1013 {
1050 Lisp_Object res, tem; 1014 Lisp_Object res, tem;
1051 1015
1052 if (!CONSP (elt)) 1016 if (!CONSP (elt))
1053 return elt; 1017 return elt;
1116 } 1080 }
1117 return res; 1081 return res;
1118 } 1082 }
1119 1083
1120 static void 1084 static void
1121 copy_keymap_1 (chartable, idx, elt) 1085 copy_keymap_1 (Lisp_Object chartable, Lisp_Object idx, Lisp_Object elt)
1122 Lisp_Object chartable, idx, elt;
1123 { 1086 {
1124 Fset_char_table_range (chartable, idx, copy_keymap_item (elt)); 1087 Fset_char_table_range (chartable, idx, copy_keymap_item (elt));
1125 } 1088 }
1126 1089
1127 DEFUN ("copy-keymap", Fcopy_keymap, Scopy_keymap, 1, 1, 0, 1090 DEFUN ("copy-keymap", Fcopy_keymap, Scopy_keymap, 1, 1, 0,
1410 /* Make KEYMAP define event C as a keymap (i.e., as a prefix). 1373 /* Make KEYMAP define event C as a keymap (i.e., as a prefix).
1411 Assume that currently it does not define C at all. 1374 Assume that currently it does not define C at all.
1412 Return the keymap. */ 1375 Return the keymap. */
1413 1376
1414 static Lisp_Object 1377 static Lisp_Object
1415 define_as_prefix (keymap, c) 1378 define_as_prefix (Lisp_Object keymap, Lisp_Object c)
1416 Lisp_Object keymap, c;
1417 { 1379 {
1418 Lisp_Object cmd; 1380 Lisp_Object cmd;
1419 1381
1420 cmd = Fmake_sparse_keymap (Qnil); 1382 cmd = Fmake_sparse_keymap (Qnil);
1421 /* If this key is defined as a prefix in an inherited keymap, 1383 /* If this key is defined as a prefix in an inherited keymap,
1428 } 1390 }
1429 1391
1430 /* Append a key to the end of a key sequence. We always make a vector. */ 1392 /* Append a key to the end of a key sequence. We always make a vector. */
1431 1393
1432 Lisp_Object 1394 Lisp_Object
1433 append_key (key_sequence, key) 1395 append_key (Lisp_Object key_sequence, Lisp_Object key)
1434 Lisp_Object key_sequence, key;
1435 { 1396 {
1436 Lisp_Object args[2]; 1397 Lisp_Object args[2];
1437 1398
1438 args[0] = key_sequence; 1399 args[0] = key_sequence;
1439 1400
1443 1404
1444 /* Given a event type C which is a symbol, 1405 /* Given a event type C which is a symbol,
1445 signal an error if is a mistake such as RET or M-RET or C-DEL, etc. */ 1406 signal an error if is a mistake such as RET or M-RET or C-DEL, etc. */
1446 1407
1447 static void 1408 static void
1448 silly_event_symbol_error (c) 1409 silly_event_symbol_error (Lisp_Object c)
1449 Lisp_Object c;
1450 { 1410 {
1451 Lisp_Object parsed, base, name, assoc; 1411 Lisp_Object parsed, base, name, assoc;
1452 int modifiers; 1412 int modifiers;
1453 1413
1454 parsed = parse_modifiers (c); 1414 parsed = parse_modifiers (c);
1513 which would call this function again, resulting in an infinite 1473 which would call this function again, resulting in an infinite
1514 loop. Instead, we'll use realloc/malloc and silently truncate the 1474 loop. Instead, we'll use realloc/malloc and silently truncate the
1515 list, let the key sequence be read, and hope some other piece of 1475 list, let the key sequence be read, and hope some other piece of
1516 code signals the error. */ 1476 code signals the error. */
1517 int 1477 int
1518 current_minor_maps (modeptr, mapptr) 1478 current_minor_maps (Lisp_Object **modeptr, Lisp_Object **mapptr)
1519 Lisp_Object **modeptr, **mapptr;
1520 { 1479 {
1521 int i = 0; 1480 int i = 0;
1522 int list_number = 0; 1481 int list_number = 0;
1523 Lisp_Object alist, assoc, var, val; 1482 Lisp_Object alist, assoc, var, val;
1524 Lisp_Object emulation_alists; 1483 Lisp_Object emulation_alists;
2126 /* Does the current sequence end in the meta-prefix-char? */ 2085 /* Does the current sequence end in the meta-prefix-char? */
2127 int is_metized; 2086 int is_metized;
2128 }; 2087 };
2129 2088
2130 static void 2089 static void
2131 accessible_keymaps_1 (key, cmd, args, data) 2090 accessible_keymaps_1 (Lisp_Object key, Lisp_Object cmd, Lisp_Object args, void *data)
2132 Lisp_Object key, cmd, args; 2091 /* Use void* data to be compatible with map_keymap_function_t. */
2133 /* Use void* to be compatible with map_keymap_function_t. */
2134 void *data;
2135 { 2092 {
2136 struct accessible_keymaps_data *d = data; /* Cast! */ 2093 struct accessible_keymaps_data *d = data; /* Cast! */
2137 Lisp_Object maps = d->maps; 2094 Lisp_Object maps = d->maps;
2138 Lisp_Object tail = d->tail; 2095 Lisp_Object tail = d->tail;
2139 Lisp_Object thisseq = d->thisseq; 2096 Lisp_Object thisseq = d->thisseq;
2387 goto next_list; 2344 goto next_list;
2388 } 2345 }
2389 2346
2390 2347
2391 char * 2348 char *
2392 push_key_description (c, p, force_multibyte) 2349 push_key_description (register unsigned int c, register char *p, int force_multibyte)
2393 register unsigned int c;
2394 register char *p;
2395 int force_multibyte;
2396 { 2350 {
2397 unsigned c2; 2351 unsigned c2;
2398 2352
2399 /* Clear all the meaningless bits above the meta bit. */ 2353 /* Clear all the meaningless bits above the meta bit. */
2400 c &= meta_modifier | ~ - meta_modifier; 2354 c &= meta_modifier | ~ - meta_modifier;
2547 error ("KEY must be an integer, cons, symbol, or string"); 2501 error ("KEY must be an integer, cons, symbol, or string");
2548 return Qnil; 2502 return Qnil;
2549 } 2503 }
2550 2504
2551 char * 2505 char *
2552 push_text_char_description (c, p) 2506 push_text_char_description (register unsigned int c, register char *p)
2553 register unsigned int c;
2554 register char *p;
2555 { 2507 {
2556 if (c >= 0200) 2508 if (c >= 0200)
2557 { 2509 {
2558 *p++ = 'M'; 2510 *p++ = 'M';
2559 *p++ = '-'; 2511 *p++ = '-';
2609 2561
2610 /* Return 0 if SEQ uses non-preferred modifiers or non-char events. 2562 /* Return 0 if SEQ uses non-preferred modifiers or non-char events.
2611 Else, return 2 if SEQ uses the where_is_preferred_modifier, 2563 Else, return 2 if SEQ uses the where_is_preferred_modifier,
2612 and 1 otherwise. */ 2564 and 1 otherwise. */
2613 static int 2565 static int
2614 preferred_sequence_p (seq) 2566 preferred_sequence_p (Lisp_Object seq)
2615 Lisp_Object seq;
2616 { 2567 {
2617 int i; 2568 int i;
2618 int len = XINT (Flength (seq)); 2569 int len = XINT (Flength (seq));
2619 int result = 1; 2570 int result = 1;
2620 2571
2980 } 2931 }
2981 2932
2982 /* This function can GC because get_keyelt can. */ 2933 /* This function can GC because get_keyelt can. */
2983 2934
2984 static void 2935 static void
2985 where_is_internal_1 (key, binding, args, data) 2936 where_is_internal_1 (Lisp_Object key, Lisp_Object binding, Lisp_Object args, void *data)
2986 Lisp_Object key, binding, args;
2987 void *data;
2988 { 2937 {
2989 struct where_is_internal_data *d = data; /* Cast! */ 2938 struct where_is_internal_data *d = data; /* Cast! */
2990 Lisp_Object definition = d->definition; 2939 Lisp_Object definition = d->definition;
2991 int noindirect = d->noindirect; 2940 int noindirect = d->noindirect;
2992 Lisp_Object this = d->this; 2941 Lisp_Object this = d->this;
3340 } 3289 }
3341 3290
3342 static int previous_description_column; 3291 static int previous_description_column;
3343 3292
3344 static void 3293 static void
3345 describe_command (definition, args) 3294 describe_command (Lisp_Object definition, Lisp_Object args)
3346 Lisp_Object definition, args;
3347 { 3295 {
3348 register Lisp_Object tem1; 3296 register Lisp_Object tem1;
3349 int column = (int) current_column (); /* iftc */ 3297 int column = (int) current_column (); /* iftc */
3350 int description_column; 3298 int description_column;
3351 3299
3377 else 3325 else
3378 insert_string ("??\n"); 3326 insert_string ("??\n");
3379 } 3327 }
3380 3328
3381 static void 3329 static void
3382 describe_translation (definition, args) 3330 describe_translation (Lisp_Object definition, Lisp_Object args)
3383 Lisp_Object definition, args;
3384 { 3331 {
3385 register Lisp_Object tem1; 3332 register Lisp_Object tem1;
3386 3333
3387 Findent_to (make_number (16), make_number (1)); 3334 Findent_to (make_number (16), make_number (1));
3388 3335
3411 3358
3412 /* qsort comparison function for sorting `struct describe_map_elt' by 3359 /* qsort comparison function for sorting `struct describe_map_elt' by
3413 the event field. */ 3360 the event field. */
3414 3361
3415 static int 3362 static int
3416 describe_map_compare (aa, bb) 3363 describe_map_compare (const void *aa, const void *bb)
3417 const void *aa, *bb;
3418 { 3364 {
3419 const struct describe_map_elt *a = aa, *b = bb; 3365 const struct describe_map_elt *a = aa, *b = bb;
3420 if (INTEGERP (a->event) && INTEGERP (b->event)) 3366 if (INTEGERP (a->event) && INTEGERP (b->event))
3421 return ((XINT (a->event) > XINT (b->event)) 3367 return ((XINT (a->event) > XINT (b->event))
3422 - (XINT (a->event) < XINT (b->event))); 3368 - (XINT (a->event) < XINT (b->event)));
3622 3568
3623 UNGCPRO; 3569 UNGCPRO;
3624 } 3570 }
3625 3571
3626 static void 3572 static void
3627 describe_vector_princ (elt, fun) 3573 describe_vector_princ (Lisp_Object elt, Lisp_Object fun)
3628 Lisp_Object elt, fun;
3629 { 3574 {
3630 Findent_to (make_number (16), make_number (1)); 3575 Findent_to (make_number (16), make_number (1));
3631 call1 (fun, elt); 3576 call1 (fun, elt);
3632 Fterpri (Qnil); 3577 Fterpri (Qnil);
3633 } 3578 }
3891 /* Apropos - finding all symbols whose names match a regexp. */ 3836 /* Apropos - finding all symbols whose names match a regexp. */
3892 static Lisp_Object apropos_predicate; 3837 static Lisp_Object apropos_predicate;
3893 static Lisp_Object apropos_accumulate; 3838 static Lisp_Object apropos_accumulate;
3894 3839
3895 static void 3840 static void
3896 apropos_accum (symbol, string) 3841 apropos_accum (Lisp_Object symbol, Lisp_Object string)
3897 Lisp_Object symbol, string;
3898 { 3842 {
3899 register Lisp_Object tem; 3843 register Lisp_Object tem;
3900 3844
3901 tem = Fstring_match (string, Fsymbol_name (symbol), Qnil); 3845 tem = Fstring_match (string, Fsymbol_name (symbol), Qnil);
3902 if (!NILP (tem) && !NILP (apropos_predicate)) 3846 if (!NILP (tem) && !NILP (apropos_predicate))
3923 apropos_predicate = Qnil; 3867 apropos_predicate = Qnil;
3924 return tem; 3868 return tem;
3925 } 3869 }
3926 3870
3927 void 3871 void
3928 syms_of_keymap () 3872 syms_of_keymap (void)
3929 { 3873 {
3930 Qkeymap = intern_c_string ("keymap"); 3874 Qkeymap = intern_c_string ("keymap");
3931 staticpro (&Qkeymap); 3875 staticpro (&Qkeymap);
3932 staticpro (&apropos_predicate); 3876 staticpro (&apropos_predicate);
3933 staticpro (&apropos_accumulate); 3877 staticpro (&apropos_accumulate);
4117 defsubr (&Sdescribe_buffer_bindings); 4061 defsubr (&Sdescribe_buffer_bindings);
4118 defsubr (&Sapropos_internal); 4062 defsubr (&Sapropos_internal);
4119 } 4063 }
4120 4064
4121 void 4065 void
4122 keys_of_keymap () 4066 keys_of_keymap (void)
4123 { 4067 {
4124 initial_define_key (global_map, 033, "ESC-prefix"); 4068 initial_define_key (global_map, 033, "ESC-prefix");
4125 initial_define_key (global_map, Ctl ('X'), "Control-X-prefix"); 4069 initial_define_key (global_map, Ctl ('X'), "Control-X-prefix");
4126 } 4070 }
4127 4071