aboutsummaryrefslogtreecommitdiffstats
path: root/src/keymap.c
diff options
context:
space:
mode:
authorMiles Bader2006-01-16 08:37:27 +0000
committerMiles Bader2006-01-16 08:37:27 +0000
commit41882805d6711e32ac0f066119226d84dbdedc13 (patch)
tree44f756cef3fbc4de2f229e93613a1a326da7f55d /src/keymap.c
parent6a2bd1a5019d2130c87ac5cf17f1322bf614b624 (diff)
parent28f74fdf77eaab2e9daf54e2d5b0b729c5201e4f (diff)
downloademacs-41882805d6711e32ac0f066119226d84dbdedc13.tar.gz
emacs-41882805d6711e32ac0f066119226d84dbdedc13.zip
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-97
Merge from emacs--cvs-trunk--0 Patches applied: * emacs--cvs-trunk--0 (patch 616-696) - Add lisp/mh-e/.arch-inventory - Update from CVS - Merge from gnus--rel--5.10 - Update from CVS: lisp/smerge-mode.el: Add 'tools' to file keywords. - lisp/gnus/ChangeLog: Remove duplicate entry * gnus--rel--5.10 (patch 147-181) - Update from CVS - Merge from emacs--cvs-trunk--0 - Update from CVS: lisp/mml.el (mml-preview): Doc fix. - Update from CVS: texi/message.texi: Fix default values. - Update from CVS: texi/gnus.texi (RSS): Addition.
Diffstat (limited to 'src/keymap.c')
-rw-r--r--src/keymap.c175
1 files changed, 149 insertions, 26 deletions
diff --git a/src/keymap.c b/src/keymap.c
index 271b0672b1e..07bf957cdca 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -66,6 +66,13 @@ Lisp_Object Vminibuffer_local_ns_map;
66/* was MinibufLocalCompletionMap */ 66/* was MinibufLocalCompletionMap */
67Lisp_Object Vminibuffer_local_completion_map; 67Lisp_Object Vminibuffer_local_completion_map;
68 68
69/* keymap used for minibuffers when doing completion in filenames */
70Lisp_Object Vminibuffer_local_filename_completion_map;
71
72/* keymap used for minibuffers when doing completion in filenames
73 with require-match*/
74Lisp_Object Vminibuffer_local_must_match_filename_map;
75
69/* keymap used for minibuffers when doing completion and require a match */ 76/* keymap used for minibuffers when doing completion and require a match */
70/* was MinibufLocalMustMatchMap */ 77/* was MinibufLocalMustMatchMap */
71Lisp_Object Vminibuffer_local_must_match_map; 78Lisp_Object Vminibuffer_local_must_match_map;
@@ -390,6 +397,7 @@ Return PARENT. PARENT should be nil or another keymap. */)
390 if (EQ (XCDR (prev), parent)) 397 if (EQ (XCDR (prev), parent))
391 RETURN_UNGCPRO (parent); 398 RETURN_UNGCPRO (parent);
392 399
400 CHECK_IMPURE (prev);
393 XSETCDR (prev, parent); 401 XSETCDR (prev, parent);
394 break; 402 break;
395 } 403 }
@@ -886,6 +894,7 @@ store_in_keymap (keymap, idx, def)
886 { 894 {
887 if (NATNUMP (idx) && XFASTINT (idx) < ASIZE (elt)) 895 if (NATNUMP (idx) && XFASTINT (idx) < ASIZE (elt))
888 { 896 {
897 CHECK_IMPURE (elt);
889 ASET (elt, XFASTINT (idx), def); 898 ASET (elt, XFASTINT (idx), def);
890 return def; 899 return def;
891 } 900 }
@@ -929,6 +938,7 @@ store_in_keymap (keymap, idx, def)
929 { 938 {
930 if (EQ (idx, XCAR (elt))) 939 if (EQ (idx, XCAR (elt)))
931 { 940 {
941 CHECK_IMPURE (elt);
932 XSETCDR (elt, def); 942 XSETCDR (elt, def);
933 return def; 943 return def;
934 } 944 }
@@ -972,6 +982,7 @@ store_in_keymap (keymap, idx, def)
972 } 982 }
973 else 983 else
974 elt = Fcons (idx, def); 984 elt = Fcons (idx, def);
985 CHECK_IMPURE (insertion_point);
975 XSETCDR (insertion_point, Fcons (elt, XCDR (insertion_point))); 986 XSETCDR (insertion_point, Fcons (elt, XCDR (insertion_point)));
976 } 987 }
977 } 988 }
@@ -1243,7 +1254,7 @@ A number as value means KEY is "too long";
1243that is, characters or symbols in it except for the last one 1254that is, characters or symbols in it except for the last one
1244fail to be a valid sequence of prefix characters in KEYMAP. 1255fail to be a valid sequence of prefix characters in KEYMAP.
1245The number is how many characters at the front of KEY 1256The number is how many characters at the front of KEY
1246it takes to reach a non-prefix command. 1257it takes to reach a non-prefix key.
1247 1258
1248Normally, `lookup-key' ignores bindings for t, which act as default 1259Normally, `lookup-key' ignores bindings for t, which act as default
1249bindings, used when nothing else in the keymap applies; this makes it 1260bindings, used when nothing else in the keymap applies; this makes it
@@ -2368,7 +2379,14 @@ shadow_lookup (shadow, key, flag)
2368 for (tail = shadow; CONSP (tail); tail = XCDR (tail)) 2379 for (tail = shadow; CONSP (tail); tail = XCDR (tail))
2369 { 2380 {
2370 value = Flookup_key (XCAR (tail), key, flag); 2381 value = Flookup_key (XCAR (tail), key, flag);
2371 if (!NILP (value) && !NATNUMP (value)) 2382 if (NATNUMP (value))
2383 {
2384 value = Flookup_key (XCAR (tail),
2385 Fsubstring (key, make_number (0), value), flag);
2386 if (!NILP (value))
2387 return Qnil;
2388 }
2389 else if (!NILP (value))
2372 return value; 2390 return value;
2373 } 2391 }
2374 return Qnil; 2392 return Qnil;
@@ -3175,6 +3193,34 @@ describe_translation (definition, args)
3175 insert_string ("??\n"); 3193 insert_string ("??\n");
3176} 3194}
3177 3195
3196/* describe_map puts all the usable elements of a sparse keymap
3197 into an array of `struct describe_map_elt',
3198 then sorts them by the events. */
3199
3200struct describe_map_elt { Lisp_Object event; Lisp_Object definition; int shadowed; };
3201
3202/* qsort comparison function for sorting `struct describe_map_elt' by
3203 the event field. */
3204
3205static int
3206describe_map_compare (aa, bb)
3207 const void *aa, *bb;
3208{
3209 const struct describe_map_elt *a = aa, *b = bb;
3210 if (INTEGERP (a->event) && INTEGERP (b->event))
3211 return ((XINT (a->event) > XINT (b->event))
3212 - (XINT (a->event) < XINT (b->event)));
3213 if (!INTEGERP (a->event) && INTEGERP (b->event))
3214 return 1;
3215 if (INTEGERP (a->event) && !INTEGERP (b->event))
3216 return -1;
3217 if (SYMBOLP (a->event) && SYMBOLP (b->event))
3218 return (!NILP (Fstring_lessp (a->event, b->event)) ? -1
3219 : !NILP (Fstring_lessp (b->event, a->event)) ? 1
3220 : 0);
3221 return 0;
3222}
3223
3178/* Describe the contents of map MAP, assuming that this map itself is 3224/* Describe the contents of map MAP, assuming that this map itself is
3179 reached by the sequence of prefix keys PREFIX (a string or vector). 3225 reached by the sequence of prefix keys PREFIX (a string or vector).
3180 PARTIAL, SHADOW, NOMENU are as in `describe_map_tree' above. */ 3226 PARTIAL, SHADOW, NOMENU are as in `describe_map_tree' above. */
@@ -3198,6 +3244,13 @@ describe_map (map, prefix, elt_describer, partial, shadow,
3198 int first = 1; 3244 int first = 1;
3199 struct gcpro gcpro1, gcpro2, gcpro3; 3245 struct gcpro gcpro1, gcpro2, gcpro3;
3200 3246
3247 /* These accumulate the values from sparse keymap bindings,
3248 so we can sort them and handle them in order. */
3249 int length_needed = 0;
3250 struct describe_map_elt *vect;
3251 int slots_used = 0;
3252 int i;
3253
3201 suppress = Qnil; 3254 suppress = Qnil;
3202 3255
3203 if (partial) 3256 if (partial)
@@ -3209,6 +3262,12 @@ describe_map (map, prefix, elt_describer, partial, shadow,
3209 kludge = Fmake_vector (make_number (1), Qnil); 3262 kludge = Fmake_vector (make_number (1), Qnil);
3210 definition = Qnil; 3263 definition = Qnil;
3211 3264
3265 for (tail = map; CONSP (tail); tail = XCDR (tail))
3266 length_needed++;
3267
3268 vect = ((struct describe_map_elt *)
3269 alloca (sizeof (struct describe_map_elt) * length_needed));
3270
3212 GCPRO3 (prefix, definition, kludge); 3271 GCPRO3 (prefix, definition, kludge);
3213 3272
3214 for (tail = map; CONSP (tail); tail = XCDR (tail)) 3273 for (tail = map; CONSP (tail); tail = XCDR (tail))
@@ -3223,6 +3282,7 @@ describe_map (map, prefix, elt_describer, partial, shadow,
3223 else if (CONSP (XCAR (tail))) 3282 else if (CONSP (XCAR (tail)))
3224 { 3283 {
3225 int this_shadowed = 0; 3284 int this_shadowed = 0;
3285
3226 event = XCAR (XCAR (tail)); 3286 event = XCAR (XCAR (tail));
3227 3287
3228 /* Ignore bindings whose "prefix" are not really valid events. 3288 /* Ignore bindings whose "prefix" are not really valid events.
@@ -3263,27 +3323,10 @@ describe_map (map, prefix, elt_describer, partial, shadow,
3263 tem = Flookup_key (map, kludge, Qt); 3323 tem = Flookup_key (map, kludge, Qt);
3264 if (!EQ (tem, definition)) continue; 3324 if (!EQ (tem, definition)) continue;
3265 3325
3266 if (first) 3326 vect[slots_used].event = event;
3267 { 3327 vect[slots_used].definition = definition;
3268 previous_description_column = 0; 3328 vect[slots_used].shadowed = this_shadowed;
3269 insert ("\n", 1); 3329 slots_used++;
3270 first = 0;
3271 }
3272
3273 /* THIS gets the string to describe the character EVENT. */
3274 insert1 (Fkey_description (kludge, prefix));
3275
3276 /* Print a description of the definition of this character.
3277 elt_describer will take care of spacing out far enough
3278 for alignment purposes. */
3279 (*elt_describer) (definition, Qnil);
3280
3281 if (this_shadowed)
3282 {
3283 SET_PT (PT - 1);
3284 insert_string (" (binding currently shadowed)");
3285 SET_PT (PT + 1);
3286 }
3287 } 3330 }
3288 else if (EQ (XCAR (tail), Qkeymap)) 3331 else if (EQ (XCAR (tail), Qkeymap))
3289 { 3332 {
@@ -3297,6 +3340,68 @@ describe_map (map, prefix, elt_describer, partial, shadow,
3297 } 3340 }
3298 } 3341 }
3299 3342
3343 /* If we found some sparse map events, sort them. */
3344
3345 qsort (vect, slots_used, sizeof (struct describe_map_elt),
3346 describe_map_compare);
3347
3348 /* Now output them in sorted order. */
3349
3350 for (i = 0; i < slots_used; i++)
3351 {
3352 Lisp_Object start, end;
3353
3354 if (first)
3355 {
3356 previous_description_column = 0;
3357 insert ("\n", 1);
3358 first = 0;
3359 }
3360
3361 ASET (kludge, 0, vect[i].event);
3362 start = vect[i].event;
3363 end = start;
3364
3365 definition = vect[i].definition;
3366
3367 /* Find consecutive chars that are identically defined. */
3368 if (INTEGERP (vect[i].event))
3369 {
3370 while (i + 1 < slots_used
3371 && XINT (vect[i + 1].event) == XINT (vect[i].event) + 1
3372 && !NILP (Fequal (vect[i + 1].definition, definition))
3373 && vect[i].shadowed == vect[i + 1].shadowed)
3374 i++;
3375 end = vect[i].event;
3376 }
3377
3378 /* Now START .. END is the range to describe next. */
3379
3380 /* Insert the string to describe the event START. */
3381 insert1 (Fkey_description (kludge, prefix));
3382
3383 if (!EQ (start, end))
3384 {
3385 insert (" .. ", 4);
3386
3387 ASET (kludge, 0, end);
3388 /* Insert the string to describe the character END. */
3389 insert1 (Fkey_description (kludge, prefix));
3390 }
3391
3392 /* Print a description of the definition of this character.
3393 elt_describer will take care of spacing out far enough
3394 for alignment purposes. */
3395 (*elt_describer) (vect[i].definition, Qnil);
3396
3397 if (vect[i].shadowed)
3398 {
3399 SET_PT (PT - 1);
3400 insert_string (" (binding currently shadowed)");
3401 SET_PT (PT + 1);
3402 }
3403 }
3404
3300 UNGCPRO; 3405 UNGCPRO;
3301} 3406}
3302 3407
@@ -3646,12 +3751,27 @@ don't alter it yourself. */);
3646 Vminibuffer_local_completion_map = Fmake_sparse_keymap (Qnil); 3751 Vminibuffer_local_completion_map = Fmake_sparse_keymap (Qnil);
3647 Fset_keymap_parent (Vminibuffer_local_completion_map, Vminibuffer_local_map); 3752 Fset_keymap_parent (Vminibuffer_local_completion_map, Vminibuffer_local_map);
3648 3753
3754 DEFVAR_LISP ("minibuffer-local-filename-completion-map",
3755 &Vminibuffer_local_filename_completion_map,
3756 doc: /* Local keymap for minibuffer input with completion for filenames. */);
3757 Vminibuffer_local_filename_completion_map = Fmake_sparse_keymap (Qnil);
3758 Fset_keymap_parent (Vminibuffer_local_filename_completion_map,
3759 Vminibuffer_local_completion_map);
3760
3761
3649 DEFVAR_LISP ("minibuffer-local-must-match-map", &Vminibuffer_local_must_match_map, 3762 DEFVAR_LISP ("minibuffer-local-must-match-map", &Vminibuffer_local_must_match_map,
3650 doc: /* Local keymap for minibuffer input with completion, for exact match. */); 3763 doc: /* Local keymap for minibuffer input with completion, for exact match. */);
3651 Vminibuffer_local_must_match_map = Fmake_sparse_keymap (Qnil); 3764 Vminibuffer_local_must_match_map = Fmake_sparse_keymap (Qnil);
3652 Fset_keymap_parent (Vminibuffer_local_must_match_map, 3765 Fset_keymap_parent (Vminibuffer_local_must_match_map,
3653 Vminibuffer_local_completion_map); 3766 Vminibuffer_local_completion_map);
3654 3767
3768 DEFVAR_LISP ("minibuffer-local-must-match-filename-map",
3769 &Vminibuffer_local_must_match_filename_map,
3770 doc: /* Local keymap for minibuffer input with completion for filenames with exact match. */);
3771 Vminibuffer_local_must_match_filename_map = Fmake_sparse_keymap (Qnil);
3772 Fset_keymap_parent (Vminibuffer_local_must_match_filename_map,
3773 Vminibuffer_local_must_match_map);
3774
3655 DEFVAR_LISP ("minor-mode-map-alist", &Vminor_mode_map_alist, 3775 DEFVAR_LISP ("minor-mode-map-alist", &Vminor_mode_map_alist,
3656 doc: /* Alist of keymaps to use for minor modes. 3776 doc: /* Alist of keymaps to use for minor modes.
3657Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read 3777Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read
@@ -3678,9 +3798,9 @@ the same way. The "active" keymaps in each alist are used before
3678 3798
3679 3799
3680 DEFVAR_LISP ("function-key-map", &Vfunction_key_map, 3800 DEFVAR_LISP ("function-key-map", &Vfunction_key_map,
3681 doc: /* Keymap mapping ASCII function key sequences onto their preferred forms. 3801 doc: /* Keymap that translates key sequences to key sequences during input.
3682This allows Emacs to recognize function keys sent from ASCII 3802This is used mainly for mapping ASCII function key sequences into
3683terminals at any point in a key sequence. 3803real Emacs function key events (symbols).
3684 3804
3685The `read-key-sequence' function replaces any subsequence bound by 3805The `read-key-sequence' function replaces any subsequence bound by
3686`function-key-map' with its binding. More precisely, when the active 3806`function-key-map' with its binding. More precisely, when the active
@@ -3689,6 +3809,9 @@ keymaps have no binding for the current key sequence but
3689`read-key-sequence' replaces the matching suffix with its binding, and 3809`read-key-sequence' replaces the matching suffix with its binding, and
3690continues with the new sequence. 3810continues with the new sequence.
3691 3811
3812If the binding is a function, it is called with one argument (the prompt)
3813and its return value (a key sequence) is used.
3814
3692The events that come from bindings in `function-key-map' are not 3815The events that come from bindings in `function-key-map' are not
3693themselves looked up in `function-key-map'. 3816themselves looked up in `function-key-map'.
3694 3817