diff options
| author | Jim Blandy | 1992-07-30 20:59:35 +0000 |
|---|---|---|
| committer | Jim Blandy | 1992-07-30 20:59:35 +0000 |
| commit | 253598e46639bfc04c91734671af498b2b1b09a7 (patch) | |
| tree | ac56e27742ec4167e99e9ef1369b94e2d76fe59a /src | |
| parent | e635fdf0c9de935ea84dd912bc98a87b6b084f16 (diff) | |
| download | emacs-253598e46639bfc04c91734671af498b2b1b09a7.tar.gz emacs-253598e46639bfc04c91734671af498b2b1b09a7.zip | |
entered into RCS
Diffstat (limited to 'src')
| -rw-r--r-- | src/keyboard.c | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/src/keyboard.c b/src/keyboard.c index ceab36647fd..96a1e0620b8 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -2545,25 +2545,39 @@ read_key_sequence (keybuf, bufsize, prompt) | |||
| 2545 | int nmaps; | 2545 | int nmaps; |
| 2546 | int nmaps_allocated = 0; | 2546 | int nmaps_allocated = 0; |
| 2547 | 2547 | ||
| 2548 | /* current[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1] | 2548 | /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1] |
| 2549 | in the current keymaps, or nil where it is not a prefix. */ | 2549 | in the current keymaps, or nil where it is not a prefix. */ |
| 2550 | Lisp_Object *current; | 2550 | Lisp_Object *submaps; |
| 2551 | 2551 | ||
| 2552 | /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in | 2552 | /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in |
| 2553 | the current keymaps. */ | 2553 | the current keymaps. */ |
| 2554 | Lisp_Object *defs; | 2554 | Lisp_Object *defs; |
| 2555 | 2555 | ||
| 2556 | /* The lowest i such that defs[i] is non-nil. */ | 2556 | /* The index of the first keymap that has a binding for this key |
| 2557 | sequence. In other words, the lowest i such that defs[i] is | ||
| 2558 | non-nil.*/ | ||
| 2557 | int first_binding; | 2559 | int first_binding; |
| 2558 | 2560 | ||
| 2559 | /* If mock_input > t, then KEYBUF[t] should be read as the next | 2561 | /* If mock_input > t, then KEYBUF[t] should be read as the next |
| 2560 | input key. */ | 2562 | input key. |
| 2563 | |||
| 2564 | We use this to recover after recognizing a function key. Once we | ||
| 2565 | realize that a suffix of the current key sequence is actually a | ||
| 2566 | function key's escape sequence, we replace the suffix with the | ||
| 2567 | function key's binding from Vfunction_key_map. Now keybuf | ||
| 2568 | contains a new and different key sequence, so the echo area and | ||
| 2569 | the submaps and defs arrays are wrong. In this situation, we set | ||
| 2570 | mock_input to t, set t to 0, and jump to restart; the loop will | ||
| 2571 | read keys from keybuf up until mock_input, which rebuilds the | ||
| 2572 | state, and then it will resume reading characters from the keyboard. */ | ||
| 2561 | int mock_input = 0; | 2573 | int mock_input = 0; |
| 2562 | 2574 | ||
| 2563 | /* If the sequence is unbound in current[], keymap[fkey_start..fkey_end-1] | 2575 | /* If the sequence is unbound in submaps[], then |
| 2564 | is a prefix in Vfunction_key_map, and fkey_map is its binding. | 2576 | keymap[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map, |
| 2565 | These might be > t, indicating that all function key scanning should | 2577 | and fkey_map is its binding. If mock_input is in use, these |
| 2578 | might be > t, indicating that all function key scanning should | ||
| 2566 | hold off until t reaches them. */ | 2579 | hold off until t reaches them. */ |
| 2580 | |||
| 2567 | int fkey_start = 0, fkey_end = 0; | 2581 | int fkey_start = 0, fkey_end = 0; |
| 2568 | Lisp_Object fkey_map = Vfunction_key_map; | 2582 | Lisp_Object fkey_map = Vfunction_key_map; |
| 2569 | 2583 | ||
| @@ -2578,7 +2592,7 @@ read_key_sequence (keybuf, bufsize, prompt) | |||
| 2578 | echo_start = echo_length (); | 2592 | echo_start = echo_length (); |
| 2579 | } | 2593 | } |
| 2580 | 2594 | ||
| 2581 | /* If there is no function key map, turn of function key scanning. */ | 2595 | /* If there is no function key map, turn off function key scanning. */ |
| 2582 | if (NILP (Fkeymapp (Vfunction_key_map))) | 2596 | if (NILP (Fkeymapp (Vfunction_key_map))) |
| 2583 | fkey_start = fkey_end = bufsize + 1; | 2597 | fkey_start = fkey_end = bufsize + 1; |
| 2584 | 2598 | ||
| @@ -2592,21 +2606,21 @@ read_key_sequence (keybuf, bufsize, prompt) | |||
| 2592 | nmaps = current_minor_maps (0, &maps) + 2; | 2606 | nmaps = current_minor_maps (0, &maps) + 2; |
| 2593 | if (nmaps > nmaps_allocated) | 2607 | if (nmaps > nmaps_allocated) |
| 2594 | { | 2608 | { |
| 2595 | current = (Lisp_Object *) alloca (nmaps * sizeof (current[0])); | 2609 | submaps = (Lisp_Object *) alloca (nmaps * sizeof (submaps[0])); |
| 2596 | defs = (Lisp_Object *) alloca (nmaps * sizeof (defs[0])); | 2610 | defs = (Lisp_Object *) alloca (nmaps * sizeof (defs[0])); |
| 2597 | nmaps_allocated = nmaps; | 2611 | nmaps_allocated = nmaps; |
| 2598 | } | 2612 | } |
| 2599 | bcopy (maps, current, (nmaps - 2) * sizeof (current[0])); | 2613 | bcopy (maps, submaps, (nmaps - 2) * sizeof (submaps[0])); |
| 2600 | current[nmaps-2] = last_event_buffer->keymap; | 2614 | submaps[nmaps-2] = last_event_buffer->keymap; |
| 2601 | current[nmaps-1] = global_map; | 2615 | submaps[nmaps-1] = global_map; |
| 2602 | } | 2616 | } |
| 2603 | 2617 | ||
| 2604 | /* Find an accurate initial value for first_binding. */ | 2618 | /* Find an accurate initial value for first_binding. */ |
| 2605 | for (first_binding = 0; first_binding < nmaps; first_binding++) | 2619 | for (first_binding = 0; first_binding < nmaps; first_binding++) |
| 2606 | if (! NILP (current[first_binding])) | 2620 | if (! NILP (submaps[first_binding])) |
| 2607 | break; | 2621 | break; |
| 2608 | 2622 | ||
| 2609 | while ((first_binding < nmaps && ! NILP (current[first_binding])) | 2623 | while ((first_binding < nmaps && ! NILP (submaps[first_binding])) |
| 2610 | || (first_binding >= nmaps && fkey_start < t)) | 2624 | || (first_binding >= nmaps && fkey_start < t)) |
| 2611 | { | 2625 | { |
| 2612 | Lisp_Object key; | 2626 | Lisp_Object key; |
| @@ -2614,14 +2628,15 @@ read_key_sequence (keybuf, bufsize, prompt) | |||
| 2614 | if (t >= bufsize) | 2628 | if (t >= bufsize) |
| 2615 | error ("key sequence too long"); | 2629 | error ("key sequence too long"); |
| 2616 | 2630 | ||
| 2617 | /* Are we reading keys stuffed into keybuf? */ | 2631 | /* Are we re-reading a key sequence, as indicated by mock_input? */ |
| 2618 | if (t < mock_input) | 2632 | if (t < mock_input) |
| 2619 | { | 2633 | { |
| 2620 | key = keybuf[t]; | 2634 | key = keybuf[t]; |
| 2621 | add_command_key (key); | 2635 | add_command_key (key); |
| 2622 | echo_char (key); | 2636 | echo_char (key); |
| 2623 | } | 2637 | } |
| 2624 | /* Otherwise, we should actually read a character. */ | 2638 | |
| 2639 | /* If not, we should actually read a character. */ | ||
| 2625 | else | 2640 | else |
| 2626 | { | 2641 | { |
| 2627 | struct buffer *buf; | 2642 | struct buffer *buf; |
| @@ -2681,16 +2696,18 @@ read_key_sequence (keybuf, bufsize, prompt) | |||
| 2681 | 2696 | ||
| 2682 | first_binding = (follow_key (key, | 2697 | first_binding = (follow_key (key, |
| 2683 | nmaps - first_binding, | 2698 | nmaps - first_binding, |
| 2684 | current + first_binding, | 2699 | submaps + first_binding, |
| 2685 | defs + first_binding, | 2700 | defs + first_binding, |
| 2686 | current + first_binding) | 2701 | submaps + first_binding) |
| 2687 | + first_binding); | 2702 | + first_binding); |
| 2688 | keybuf[t++] = key; | 2703 | keybuf[t++] = key; |
| 2689 | 2704 | ||
| 2690 | /* If the sequence is unbound, see if we can hang a function key | 2705 | /* If the sequence is unbound, see if we can hang a function key |
| 2691 | off the end of it. Don't reread the expansion of a function key. */ | 2706 | off the end of it. We only want to scan real keyboard input |
| 2707 | for function key sequences, so if mock_input says that we're | ||
| 2708 | re-scanning after expanding a function key, don't examine it. */ | ||
| 2692 | if (first_binding >= nmaps | 2709 | if (first_binding >= nmaps |
| 2693 | && t > mock_input) | 2710 | && t >= mock_input) |
| 2694 | { | 2711 | { |
| 2695 | Lisp_Object fkey_next; | 2712 | Lisp_Object fkey_next; |
| 2696 | 2713 | ||
| @@ -2699,7 +2716,7 @@ read_key_sequence (keybuf, bufsize, prompt) | |||
| 2699 | { | 2716 | { |
| 2700 | /* Look up meta-characters by prefixing them | 2717 | /* Look up meta-characters by prefixing them |
| 2701 | with meta_prefix_char. I hate this. */ | 2718 | with meta_prefix_char. I hate this. */ |
| 2702 | if (keybuf[fkey_end++] & 0x80) | 2719 | if (keybuf[fkey_end] & 0x80) |
| 2703 | fkey_next = | 2720 | fkey_next = |
| 2704 | get_keymap_1 (get_keyelt | 2721 | get_keymap_1 (get_keyelt |
| 2705 | (access_keymap (fkey_map, meta_prefix_char)), | 2722 | (access_keymap (fkey_map, meta_prefix_char)), |