comparison src/event-stream.c @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children b82b59fe008d
comparison
equal deleted inserted replaced
1:c0c6a60d29db 2:ac2d302a0011
810 } 810 }
811 811
812 redisplay (); 812 redisplay ();
813 if (event_matches_key_specifier_p (XEVENT (event), make_char (' '))) 813 if (event_matches_key_specifier_p (XEVENT (event), make_char (' ')))
814 { 814 {
815 /* Discard next key if is is a space */ 815 /* Discard next key if it is a space */
816 reset_key_echo (command_builder, 1); 816 reset_key_echo (command_builder, 1);
817 Fnext_command_event (event, Qnil); 817 Fnext_command_event (event, Qnil);
818 } 818 }
819 819
820 command_builder->echo_buf_index = buf_index; 820 command_builder->echo_buf_index = buf_index;
2967 return Qnil; 2967 return Qnil;
2968 } 2968 }
2969 2969
2970 /* Compare the current state of the command builder against the local and 2970 /* Compare the current state of the command builder against the local and
2971 global keymaps, and return the binding. If there is no match, try again, 2971 global keymaps, and return the binding. If there is no match, try again,
2972 case-insensitively. The return value will be 2972 case-insensitively. The return value will be one of:
2973
2974 -- nil (there is no binding) 2973 -- nil (there is no binding)
2975 -- a keymap (part of a command has been specified) 2974 -- a keymap (part of a command has been specified)
2976 -- a command (anything that satisfies `commandp'; this includes 2975 -- a command (anything that satisfies `commandp'; this includes
2977 some symbols, lists, subrs, strings, vectors, and 2976 some symbols, lists, subrs, strings, vectors, and
2978 compiled-function objects) 2977 compiled-function objects)
2987 2986
2988 if (allow_misc_user_events_p 2987 if (allow_misc_user_events_p
2989 && (NILP (XEVENT_NEXT (evee))) 2988 && (NILP (XEVENT_NEXT (evee)))
2990 && (XEVENT_TYPE (evee) == misc_user_event)) 2989 && (XEVENT_TYPE (evee) == misc_user_event))
2991 { 2990 {
2992 Lisp_Object fn = XEVENT (evee)->event.eval.function; 2991 Lisp_Object fn = XEVENT (evee)->event.eval.function;
2993 Lisp_Object arg = XEVENT (evee)->event.eval.object; 2992 Lisp_Object arg = XEVENT (evee)->event.eval.object;
2994 return (list2 (fn, arg)); 2993 return (list2 (fn, arg));
2995 } 2994 }
2996 2995
2997 else if (XEVENT_TYPE (evee) == misc_user_event) 2996 else if (XEVENT_TYPE (evee) == misc_user_event)
3020 if (!NILP (result)) 3019 if (!NILP (result))
3021 return result; 3020 return result;
3022 3021
3023 /* If key-sequence wasn't bound, we'll try some fallbacks. */ 3022 /* If key-sequence wasn't bound, we'll try some fallbacks. */
3024 3023
3025 {
3026 Lisp_Object terminal = builder->most_current_event;
3027
3028 /* If we didn't find a binding, and the last event in the sequence is 3024 /* If we didn't find a binding, and the last event in the sequence is
3029 a shifted character, then try again with the lowercase version. */ 3025 a shifted character, then try again with the lowercase version. */
3030 3026
3031 if (!NILP (Vretry_undefined_key_binding_unshifted) 3027 if (XEVENT_TYPE (builder->most_current_event) == key_press_event
3032 && XEVENT_TYPE (terminal) == key_press_event 3028 && !NILP (Vretry_undefined_key_binding_unshifted))
3033 && ((XEVENT (terminal)->event.key.modifiers & MOD_SHIFT) 3029 {
3034 || (CHAR_OR_CHAR_INTP (XEVENT (terminal)->event.key.keysym) 3030 Lisp_Object terminal = builder->most_current_event;
3035 && XCHAR_OR_CHAR_INT (XEVENT (terminal)->event.key.keysym) 3031 struct key_data* key = & XEVENT (terminal)->event.key;
3036 >= 'A' 3032 Emchar c;
3037 && XCHAR_OR_CHAR_INT (XEVENT (terminal)->event.key.keysym) 3033 if ((key->modifiers & MOD_SHIFT)
3038 <= 'Z'))) 3034 || (CHAR_OR_CHAR_INTP (key->keysym)
3039 { 3035 && ((c = XCHAR_OR_CHAR_INT (key->keysym)), c >= 'A' && c <= 'Z')))
3040 struct Lisp_Event terminal_copy; 3036 {
3041 terminal_copy = *XEVENT (terminal); 3037 struct Lisp_Event terminal_copy;
3042 3038 terminal_copy = *XEVENT (terminal);
3043 if (XEVENT (terminal)->event.key.modifiers & MOD_SHIFT) 3039
3044 XEVENT (terminal)->event.key.modifiers &= (~ MOD_SHIFT); 3040 if (key->modifiers & MOD_SHIFT)
3045 else 3041 key->modifiers &= (~ MOD_SHIFT);
3046 XEVENT (terminal)->event.key.keysym 3042 else
3047 = make_char (XCHAR_OR_CHAR_INT (XEVENT (terminal)-> 3043 key->keysym = make_char (c + 'a' - 'A');
3048 event.key.keysym) 3044
3049 + 'a' - 'A'); 3045 result = command_builder_find_leaf (builder, allow_misc_user_events_p);
3050 3046 if (!NILP (result))
3051 result = command_builder_find_leaf (builder, allow_misc_user_events_p); 3047 return (result);
3052 if (!NILP (result)) 3048 /* If there was no match with the lower-case version either,
3053 return (result); 3049 then put back the upper-case event for the error
3054 /* If there was no match with the lower-case version either, then 3050 message. But make sure that function-key-map didn't
3055 put back the upper-case event for the error message. 3051 change things out from under us. */
3056 But make sure that function-key-map didn't change things out 3052 if (EQ (terminal, builder->most_current_event))
3057 from under us. */ 3053 *XEVENT (terminal) = terminal_copy;
3058 if (EQ (terminal, builder->most_current_event)) 3054 }
3059 *XEVENT (terminal) = terminal_copy; 3055 }
3060 } 3056
3061 } 3057 /* help-char is `auto-bound' in every keymap */
3062
3063 if (!NILP (Vprefix_help_command) && 3058 if (!NILP (Vprefix_help_command) &&
3064 event_matches_key_specifier_p (XEVENT (builder->most_current_event), 3059 event_matches_key_specifier_p (XEVENT (builder->most_current_event),
3065 Vhelp_char)) 3060 Vhelp_char))
3066 return (Vprefix_help_command); 3061 return (Vprefix_help_command);
3067 3062
3155 return (val); 3150 return (val);
3156 } 3151 }
3157 3152
3158 /* Vthis_command_keys having value Qnil means that the next time 3153 /* Vthis_command_keys having value Qnil means that the next time
3159 push_this_command_keys is called, it should start over. 3154 push_this_command_keys is called, it should start over.
3160 The times at which the the command-keys are reset 3155 The times at which the command-keys are reset
3161 (instead of merely being augmented) are pretty conterintuitive. 3156 (instead of merely being augmented) are pretty conterintuitive.
3162 (More specifically: 3157 (More specifically:
3163 3158
3164 -- We do not reset this-command-keys when we finish reading a 3159 -- We do not reset this-command-keys when we finish reading a
3165 command. This is because some commands (e.g. C-u) act 3160 command. This is because some commands (e.g. C-u) act
3292 Given the current state of the command builder and a new command event 3287 Given the current state of the command builder and a new command event
3293 that has just been dispatched: 3288 that has just been dispatched:
3294 3289
3295 -- add the event to the event chain forming the current command 3290 -- add the event to the event chain forming the current command
3296 (doing meta-translation as necessary) 3291 (doing meta-translation as necessary)
3297 -- return the binding of the this event chain; this will be one of 3292 -- return the binding of this event chain; this will be one of:
3298 -- nil (there is no binding) 3293 -- nil (there is no binding)
3299 -- a keymap (part of a command has been specified) 3294 -- a keymap (part of a command has been specified)
3300 -- a command (anything that satisfies `commandp'; this includes 3295 -- a command (anything that satisfies `commandp'; this includes
3301 some symbols, lists, subrs, strings, vectors, and 3296 some symbols, lists, subrs, strings, vectors, and
3302 compiled-function objects) 3297 compiled-function objects)
3303
3304 */ 3298 */
3305 static Lisp_Object 3299 static Lisp_Object
3306 lookup_command_event (struct command_builder *command_builder, 3300 lookup_command_event (struct command_builder *command_builder,
3307 Lisp_Object event, int allow_misc_user_events_p) 3301 Lisp_Object event, int allow_misc_user_events_p)
3308 { 3302 {
3450 int old_kbd_macro = con->kbd_macro_end; 3444 int old_kbd_macro = con->kbd_macro_end;
3451 struct window *w; 3445 struct window *w;
3452 3446
3453 w = XWINDOW (Fselected_window (Qnil)); 3447 w = XWINDOW (Fselected_window (Qnil));
3454 3448
3455 /* We're executing a new command, so the old value of is irrelevant. */ 3449 /* We're executing a new command, so the old value is irrelevant. */
3456 zmacs_region_stays = 0; 3450 zmacs_region_stays = 0;
3457 3451
3458 /* If the previous command tried to force a specific window-start, 3452 /* If the previous command tried to force a specific window-start,
3459 reset the flag in case this command moves point far away from 3453 reset the flag in case this command moves point far away from
3460 that position. Also, reset the window's buffer's change 3454 that position. Also, reset the window's buffer's change
3538 still work! 3532 still work!
3539 3533
3540 This could be done via a function on the post-command-hook, but 3534 This could be done via a function on the post-command-hook, but
3541 we don't want the user to accidentally remove it. 3535 we don't want the user to accidentally remove it.
3542 */ 3536 */
3537
3538 Lisp_Object win = Fselected_window (Qnil);
3539
3540 #if 0
3541 /* If the last command deleted the frame, `win' might be nil.
3542 It seems safest to do nothing in this case. */
3543 /* ### This doesn't really fix the problem,
3544 if delete-frame is called by some hook */
3545 if (NILP (win))
3546 return;
3547 #endif
3548
3543 if (! zmacs_region_stays 3549 if (! zmacs_region_stays
3544 && (!MINI_WINDOW_P (XWINDOW (Fselected_window (Qnil))) 3550 && (!MINI_WINDOW_P (XWINDOW (win))
3545 /* but don't leave the region around if it's in the 3551 || EQ (zmacs_region_buffer (), WINDOW_BUFFER (XWINDOW (win)))))
3546 minibuffer. */
3547 || EQ (zmacs_region_buffer (),
3548 WINDOW_BUFFER (XWINDOW (Fselected_window (Qnil))))))
3549 zmacs_deactivate_region (); 3552 zmacs_deactivate_region ();
3550 else 3553 else
3551 zmacs_update_region (); 3554 zmacs_update_region ();
3552 3555
3553 safe_run_hook_trapping_errors 3556 safe_run_hook_trapping_errors
3731 Fsignal (Qundefined_keystroke_sequence, list1 (keys)); 3734 Fsignal (Qundefined_keystroke_sequence, list1 (keys));
3732 } 3735 }
3733 /* Reset the command builder for reading the next sequence. */ 3736 /* Reset the command builder for reading the next sequence. */
3734 reset_this_command_keys (console, 1); 3737 reset_this_command_keys (console, 1);
3735 } 3738 }
3736 else 3739 else /* key sequence is bound to a command */
3737 { 3740 {
3738 Vthis_command = leaf; 3741 Vthis_command = leaf;
3739 /* Don't push an undo boundary if the command set the prefix arg, 3742 /* Don't push an undo boundary if the command set the prefix arg,
3740 or if we are executing a keyboard macro, or if in the 3743 or if we are executing a keyboard macro, or if in the
3741 minibuffer. If the command we are about to execute is 3744 minibuffer. If the command we are about to execute is
3760 if (EQ (leaf, Qself_insert_command)) 3763 if (EQ (leaf, Qself_insert_command))
3761 { 3764 {
3762 if (--command_builder->self_insert_countdown < 0) 3765 if (--command_builder->self_insert_countdown < 0)
3763 command_builder->self_insert_countdown = 20; 3766 command_builder->self_insert_countdown = 20;
3764 } 3767 }
3765 execute_command_event (command_builder, 3768 execute_command_event
3766 !NILP (Fequal (event, 3769 (command_builder,
3767 command_builder-> 3770 !NILP (Fequal (event, command_builder-> most_current_event))
3768 most_current_event)) 3771 ? event
3769 ? event 3772 /* Use the translated event that was most recently seen.
3770 /* Use the translated event that 3773 This way, last-command-event becomes f1 instead of
3771 was most recently seen. This way, 3774 the P from ESC O P. But we must copy it, else we'll
3772 last-command-event becomes f1 3775 lose when the command-builder events are deallocated. */
3773 instead of the P from ESC O P. 3776 : Fcopy_event (command_builder-> most_current_event, Qnil));
3774 But must copy it, else we'll lose
3775 when the command-builder events
3776 are deallocated. */
3777 : Fcopy_event (command_builder->
3778 most_current_event, Qnil));
3779 } 3777 }
3780 break; 3778 break;
3781 } 3779 }
3782 case misc_user_event: 3780 case misc_user_event:
3783 { 3781 {
4205 */ ); 4203 */ );
4206 Vlast_command_event = Qnil; 4204 Vlast_command_event = Qnil;
4207 4205
4208 DEFVAR_LISP ("last-command-char", &Vlast_command_char /* 4206 DEFVAR_LISP ("last-command-char", &Vlast_command_char /*
4209 If the value of `last-command-event' is a keyboard event, then 4207 If the value of `last-command-event' is a keyboard event, then
4210 this is the nearest ASCII equivalent to it. This the the value that 4208 this is the nearest ASCII equivalent to it. This is the value that
4211 `self-insert-command' will put in the buffer. Remember that there is 4209 `self-insert-command' will put in the buffer. Remember that there is
4212 NOT a 1:1 mapping between keyboard events and ASCII characters: the set 4210 NOT a 1:1 mapping between keyboard events and ASCII characters: the set
4213 of keyboard events is much larger, so writing code that examines this 4211 of keyboard events is much larger, so writing code that examines this
4214 variable to determine what key has been typed is bad practice, unless 4212 variable to determine what key has been typed is bad practice, unless
4215 you are certain that it will be one of a small set of characters. 4213 you are certain that it will be one of a small set of characters.
4330 Vcontrolling_terminal = Qnil; 4328 Vcontrolling_terminal = Qnil;
4331 staticpro (&Vcontrolling_terminal); 4329 staticpro (&Vcontrolling_terminal);
4332 4330
4333 Vdribble_file = Qnil; 4331 Vdribble_file = Qnil;
4334 staticpro (&Vdribble_file); 4332 staticpro (&Vdribble_file);
4333
4335 4334
4336 #ifdef DEBUG_XEMACS 4335 #ifdef DEBUG_XEMACS
4337 DEFVAR_INT ("debug-emacs-events", &debug_emacs_events /* 4336 DEFVAR_INT ("debug-emacs-events", &debug_emacs_events /*
4338 If non-zero, display debug information about Emacs events that XEmacs sees. 4337 If non-zero, display debug information about Emacs events that XEmacs sees.
4339 Information is displayed on stderr. 4338 Information is displayed on stderr.