comparison src/event-stream.c @ 2828:a25c824ed558

[xemacs-hg @ 2005-06-26 18:04:49 by aidan] Rename the ascii-character property, support more keysyms.
author aidan
date Sun, 26 Jun 2005 18:05:05 +0000
parents 6fa9919a9a0b
children d7505a1267a4
comparison
equal deleted inserted replaced
2827:936a6576c655 2828:a25c824ed558
126 /* When true, modifier keys are sticky. */ 126 /* When true, modifier keys are sticky. */
127 int modifier_keys_are_sticky; 127 int modifier_keys_are_sticky;
128 /* Modifier keys are sticky for this many milliseconds. */ 128 /* Modifier keys are sticky for this many milliseconds. */
129 Lisp_Object Vmodifier_keys_sticky_time; 129 Lisp_Object Vmodifier_keys_sticky_time;
130 130
131 /* If true, "Russian C-x processing" is enabled. */
132 int try_alternate_layouts_for_commands;
133
131 /* Here FSF Emacs 20.7 defines Vpost_command_idle_hook, 134 /* Here FSF Emacs 20.7 defines Vpost_command_idle_hook,
132 post_command_idle_delay, Vdeferred_action_list, and 135 post_command_idle_delay, Vdeferred_action_list, and
133 Vdeferred_action_function, but we don't because that stuff is crap, 136 Vdeferred_action_function, but we don't because that stuff is crap,
134 and we're smarter than them, and their mommas are fat. */ 137 and we're smarter than them, and their mommas are fat. */
135 138
212 Lisp_Object Vkeyboard_translate_table; 215 Lisp_Object Vkeyboard_translate_table;
213 216
214 /* If control-meta-super-shift-X is undefined, try control-meta-super-x */ 217 /* If control-meta-super-shift-X is undefined, try control-meta-super-x */
215 Lisp_Object Vretry_undefined_key_binding_unshifted; 218 Lisp_Object Vretry_undefined_key_binding_unshifted;
216 Lisp_Object Qretry_undefined_key_binding_unshifted; 219 Lisp_Object Qretry_undefined_key_binding_unshifted;
217
218 #ifdef MULE
219 /* If composed input is undefined, use self-insert-char */
220 Lisp_Object Vcomposed_character_default_binding;
221 #endif
222 220
223 /* Console that corresponds to our controlling terminal */ 221 /* Console that corresponds to our controlling terminal */
224 Lisp_Object Vcontrolling_terminal; 222 Lisp_Object Vcontrolling_terminal;
225 223
226 /* An event (actually an event chain linked through event_next) or Qnil. 224 /* An event (actually an event chain linked through event_next) or Qnil.
2362 /* last-input-char and last-input-time are derived from 2360 /* last-input-char and last-input-time are derived from
2363 last-input-event. 2361 last-input-event.
2364 Note that last-input-char will never have its high-bit set, in an 2362 Note that last-input-char will never have its high-bit set, in an
2365 effort to sidestep the ambiguity between M-x and oslash. 2363 effort to sidestep the ambiguity between M-x and oslash.
2366 */ 2364 */
2367 Vlast_input_char = Fevent_to_character (Vlast_input_event, Qnil, Qnil, Qnil); 2365 Vlast_input_char = Fevent_to_character (Vlast_input_event, Qnil, Qnil);
2368 { 2366 {
2369 EMACS_TIME t; 2367 EMACS_TIME t;
2370 EMACS_GET_TIME (t); 2368 EMACS_GET_TIME (t);
2371 if (!CONSP (Vlast_input_time)) 2369 if (!CONSP (Vlast_input_time))
2372 Vlast_input_time = Fcons (Qnil, Qnil); 2370 Vlast_input_time = Fcons (Qnil, Qnil);
3167 if (!HASH_TABLEP (Vkeyboard_translate_table)) 3165 if (!HASH_TABLEP (Vkeyboard_translate_table))
3168 return; 3166 return;
3169 if (EQ (Fhash_table_count (Vkeyboard_translate_table), Qzero)) 3167 if (EQ (Fhash_table_count (Vkeyboard_translate_table), Qzero))
3170 return; 3168 return;
3171 3169
3172 c = event_to_character (event, 0, 0, 0); 3170 c = event_to_character (event, 0, 0);
3173 if (c != -1) 3171 if (c != -1)
3174 { 3172 {
3175 Lisp_Object traduit = Fgethash (make_char (c), Vkeyboard_translate_table, 3173 Lisp_Object traduit = Fgethash (make_char (c), Vkeyboard_translate_table,
3176 Qnil); 3174 Qnil);
3177 if (!NILP (traduit) && SYMBOLP (traduit)) 3175 if (!NILP (traduit) && SYMBOLP (traduit))
3313 } 3311 }
3314 3312
3315 return Qnil; 3313 return Qnil;
3316 } 3314 }
3317 3315
3318 /* Same as command_builder_find_leaf() below but no Russian C-x 3316 /* Same as command_builder_find_leaf() below, but without offering the
3319 processing and no defaulting to self-insert-command. 3317 platform-specific event code the opportunity to give a default binding of
3320 */ 3318 an unseen keysym to self-insert-command, and without the fallback to
3319 other keymaps for lookups that allows someone with a Cyrillic keyboard
3320 to pretend it's Qwerty for C-x C-f, for example. */
3321 3321
3322 static Lisp_Object 3322 static Lisp_Object
3323 command_builder_find_leaf_no_mule_processing (struct command_builder *builder, 3323 command_builder_find_leaf_no_jit_binding (struct command_builder *builder,
3324 int allow_misc_user_events_p, 3324 int allow_misc_user_events_p,
3325 int *did_munge) 3325 int *did_munge)
3326 { 3326 {
3327 /* This function can GC */ 3327 /* This function can GC */
3328 Lisp_Object result; 3328 Lisp_Object result;
3395 struct gcpro gcpro1; 3395 struct gcpro gcpro1;
3396 3396
3397 GCPRO1 (neubauten); 3397 GCPRO1 (neubauten);
3398 downshift_event (event_chain_tail (neub->current_events)); 3398 downshift_event (event_chain_tail (neub->current_events));
3399 result = 3399 result =
3400 command_builder_find_leaf_no_mule_processing 3400 command_builder_find_leaf_no_jit_binding
3401 (neub, allow_misc_user_events_p, did_munge); 3401 (neub, allow_misc_user_events_p, did_munge);
3402 3402
3403 if (!NILP (result)) 3403 if (!NILP (result))
3404 { 3404 {
3405 copy_command_builder (neub, builder); 3405 copy_command_builder (neub, builder);
3440 -- "Russian C-x problem" changes (see definition of struct key_data, 3440 -- "Russian C-x problem" changes (see definition of struct key_data,
3441 events.h) 3441 events.h)
3442 3442
3443 DID_MUNGE must be initialized before calling this function. If munging 3443 DID_MUNGE must be initialized before calling this function. If munging
3444 happened, DID_MUNGE will be non-zero; otherwise, it will be left alone. 3444 happened, DID_MUNGE will be non-zero; otherwise, it will be left alone.
3445 */ 3445
3446 (The above was Ben, I think.)
3447
3448 It might be nice to have lookup-key call this function, directly or
3449 indirectly. Though it is arguably the right thing if lookup-key fails on
3450 a keysym that the X11 event code hasn't seen. There's no way to know if
3451 that keysym is generatable by the keyboard until it's generated,
3452 therefore there's no reasonable expectation that it be bound before it's
3453 generated--all the other default bindings depend on our knowing the
3454 keyboard layout and relying on it. And describe-key works without it, so
3455 I think we're fine.
3456
3457 Some weirdness with this code--try this on a keyboard where X11 will
3458 produce ediaeresis with dead-diaeresis and e, but it's not produced by
3459 any other combination of keys on the keyboard;
3460
3461 (defun ding-command ()
3462 (interactive)
3463 (ding))
3464
3465 (define-key global-map 'ediaeresis 'ding-command)
3466
3467 Now, pressing dead-diaeresis and then e will ding. Next;
3468
3469 (define-key global-map 'ediaeresis 'self-insert-command)
3470
3471 and press dead-diaeresis and then e. It'll give you "Invalid argument:
3472 typed key has no ASCII equivalent" Then;
3473
3474 (define-key global-map 'ediaeresis nil)
3475
3476 and press the combination again; it'll self-insert. The moral of the
3477 story is, if you want to suppress all bindings to a non-ASCII X11 key,
3478 bind it to a trivial no-op command, because the automatic mapping to
3479 self-insert-command will happen if there's no existing binding for the
3480 symbol. I can't see a way around this. -- Aidan Kehoe, 2005-05-14 */
3446 3481
3447 static Lisp_Object 3482 static Lisp_Object
3448 command_builder_find_leaf (struct command_builder *builder, 3483 command_builder_find_leaf (struct command_builder *builder,
3449 int allow_misc_user_events_p, 3484 int allow_misc_user_events_p,
3450 int *did_munge) 3485 int *did_munge)
3451 { 3486 {
3452 Lisp_Object result = 3487 Lisp_Object result =
3453 command_builder_find_leaf_no_mule_processing 3488 command_builder_find_leaf_no_jit_binding
3454 (builder, allow_misc_user_events_p, did_munge); 3489 (builder, allow_misc_user_events_p, did_munge);
3490 Lisp_Object event, console, channel, lookup_res;
3491 int redolookup = 0, i;
3455 3492
3456 if (!NILP (result)) 3493 if (!NILP (result))
3457 return result; 3494 return result;
3458 3495
3459 #ifdef MULE 3496 /* If some of the events are keyboard events, and this is the first time
3460 /* #### Do Russian C-x processing here */ 3497 the platform event code has seen their keysyms--which will be the case
3461 3498 the first time we see a composed keysym on X11, for example--offer it
3462 /* If keysym is a non-ASCII char, bind it to self-insert-char by default. */ 3499 the chance to define them as a self-insert-command, and do the lookup
3463 if (XEVENT_TYPE (builder->most_current_event) == key_press_event 3500 again.
3464 && !NILP (Vcomposed_character_default_binding)) 3501
3465 { 3502 This isn't Mule-specific; in a world where x-iso8859-1.el is gone, it's
3466 Lisp_Object keysym = XEVENT_KEY_KEYSYM (builder->most_current_event); 3503 needed for non-Mule too.
3467 if (CHARP (keysym) && !ichar_ascii_p (XCHAR (keysym))) 3504
3468 return Vcomposed_character_default_binding; 3505 Probably this can just be limited to the checking the last
3469 } 3506 keypress. */
3470 #endif 3507
3508 EVENT_CHAIN_LOOP (event, builder->current_events)
3509 {
3510 /* We can ignore key release events because the preceding presses will
3511 have initiated the mapping. */
3512 if (key_press_event != XEVENT_TYPE (event))
3513 continue;
3514
3515 channel = XEVENT_CHANNEL (event);
3516 if (object_dead_p (channel))
3517 continue;
3518
3519 console = CDFW_CONSOLE (channel);
3520 if (NILP (console))
3521 console = Vselected_console;
3522
3523 if (CONSOLE_LIVE_P(XCONSOLE(console)))
3524 {
3525 lookup_res = MAYBE_LISP_CONMETH(XCONSOLE(console),
3526 perhaps_init_unseen_key_defaults,
3527 (XCONSOLE(console),
3528 XEVENT_KEY_KEYSYM(event)));
3529 if (EQ(lookup_res, Qt))
3530 {
3531 redolookup += 1;
3532 }
3533 }
3534 }
3535
3536 if (redolookup)
3537 {
3538 result = command_builder_find_leaf_no_jit_binding
3539 (builder, allow_misc_user_events_p, did_munge);
3540 if (!NILP (result))
3541 {
3542 return result;
3543 }
3544 }
3545
3546 /* The old composed-character-default-binding handling that used to be
3547 here was wrong--if a user wants to bind a given key to something other
3548 than self-insert-command, then they should go ahead and do it, we won't
3549 override it, and the sane thing to do with any key that has a known
3550 character correspondence is _always_ to default it to
3551 self-insert-command, nothing else.
3552
3553 I'm adding the variable to control whether "Russian C-x processing" is
3554 used because I have a feeling that it's not always the most appropriate
3555 thing to do--in cases where people are using a non-Qwerty
3556 Roman-alphabet layout, do they really want C-x with some random letter
3557 to call `switch-to-buffer'? I can imagine that being very confusing,
3558 certainly for new users, and it might be that defaulting the value for
3559 `try-alternate-layouts-for-commands' as part of the language
3560 environment is the right thing to do, only defaulting to `t' for those
3561 languages that don't use the Roman alphabet.
3562
3563 Much of that reasoning is tentative on my part, and feel free to change
3564 this code if you have more experience with the problem and an intuition
3565 that differs from mine. (Aidan Kehoe, 2005-05-29)*/
3566
3567 if (!try_alternate_layouts_for_commands)
3568 {
3569 return Qnil;
3570 }
3571
3572 if (key_press_event == XEVENT_TYPE (builder->most_current_event))
3573 {
3574 Lisp_Object ev = builder->most_current_event, newbuilder;
3575 Ichar this_alternative;
3576
3577 struct command_builder *newb;
3578 struct gcpro gcpro1;
3579
3580 /* Ignore the value for CURRENT_LANGENV, because we've checked it
3581 already, above. */
3582 for (i = KEYCHAR_CURRENT_LANGENV, ++i; i < KEYCHAR_LAST; ++i)
3583 {
3584 this_alternative = XEVENT_KEY_ALT_KEYCHARS(ev, i);
3585
3586 if (0 == this_alternative)
3587 continue;
3588
3589 newbuilder = copy_command_builder(builder, 0);
3590 GCPRO1(newbuilder);
3591
3592 newb = XCOMMAND_BUILDER(newbuilder);
3593
3594 XSET_EVENT_KEY_KEYSYM(event_chain_tail (newbuilder->current_events),
3595 make_char(this_alternative));
3596
3597 result = command_builder_find_leaf_no_jit_binding
3598 (newb, allow_misc_user_events_p, did_munge);
3599
3600 if (!NILP (result))
3601 {
3602 copy_command_builder (newb, builder);
3603 *did_munge = 1;
3604 }
3605 else if (event_upshifted_p (newbuilder->most_current_event) &&
3606 !NILP (Vretry_undefined_key_binding_unshifted)
3607 && isascii(this_alternative))
3608 {
3609 downshift_event (event_chain_tail (newbuilder->current_events));
3610 XSET_EVENT_KEY_KEYSYM(event_chain_tail (newb->current_events),
3611 make_char(tolower(this_alternative)));
3612 result = command_builder_find_leaf_no_jit_binding
3613 (newb, allow_misc_user_events_p, did_munge);
3614 }
3615
3616 free_command_builder (newb);
3617 UNGCPRO;
3618
3619 if (!NILP (result))
3620 return result;
3621 }
3622 }
3471 3623
3472 return Qnil; 3624 return Qnil;
3473 } 3625 }
3474 3626
3475 /* Like command_builder_find_leaf but update this-command-keys and the 3627 /* Like command_builder_find_leaf but update this-command-keys and the
4094 Fcopy_event (event, Vlast_command_event); 4246 Fcopy_event (event, Vlast_command_event);
4095 4247
4096 /* Note that last-command-char will never have its high-bit set, in 4248 /* Note that last-command-char will never have its high-bit set, in
4097 an effort to sidestep the ambiguity between M-x and oslash. */ 4249 an effort to sidestep the ambiguity between M-x and oslash. */
4098 Vlast_command_char = Fevent_to_character (Vlast_command_event, 4250 Vlast_command_char = Fevent_to_character (Vlast_command_event,
4099 Qnil, Qnil, Qnil); 4251 Qnil, Qnil);
4100 4252
4101 /* Actually call the command, with all sorts of hair to preserve or clear 4253 /* Actually call the command, with all sorts of hair to preserve or clear
4102 the echo-area and region as appropriate and call the pre- and post- 4254 the echo-area and region as appropriate and call the pre- and post-
4103 command-hooks. */ 4255 command-hooks. */
4104 { 4256 {
5060 This variable has no effect when `modifier-keys-are-sticky' is nil. 5212 This variable has no effect when `modifier-keys-are-sticky' is nil.
5061 Currently only implemented under X Window System. 5213 Currently only implemented under X Window System.
5062 */ ); 5214 */ );
5063 Vmodifier_keys_sticky_time = make_int (500); 5215 Vmodifier_keys_sticky_time = make_int (500);
5064 5216
5065 #ifdef MULE
5066 DEFVAR_LISP ("composed-character-default-binding",
5067 &Vcomposed_character_default_binding /*
5068 The default keybinding to use for key events from composed input.
5069 Window systems frequently have ways to allow the user to compose
5070 single characters in a language using multiple keystrokes.
5071 XEmacs sees these as single character keypress events.
5072 */ );
5073 Vcomposed_character_default_binding = Qself_insert_command;
5074 #endif
5075
5076 Vcontrolling_terminal = Qnil; 5217 Vcontrolling_terminal = Qnil;
5077 staticpro (&Vcontrolling_terminal); 5218 staticpro (&Vcontrolling_terminal);
5078 5219
5079 Vdribble_file = Qnil; 5220 Vdribble_file = Qnil;
5080 staticpro (&Vdribble_file); 5221 staticpro (&Vdribble_file);
5116 explicitly sent to the XEmacs process). 5257 explicitly sent to the XEmacs process).
5117 */ ); 5258 */ );
5118 debug_emacs_events = 0; 5259 debug_emacs_events = 0;
5119 #endif 5260 #endif
5120 5261
5121 DEFVAR_BOOL ("inhibit-input-event-recording", &inhibit_input_event_recording /* 5262 DEFVAR_BOOL ("inhibit-input-event-recording",
5263 &inhibit_input_event_recording /*
5122 Non-nil inhibits recording of input-events to recent-keys ring. 5264 Non-nil inhibits recording of input-events to recent-keys ring.
5123 */ ); 5265 */ );
5124 inhibit_input_event_recording = 0; 5266 inhibit_input_event_recording = 0;
5125 5267
5126 Vkeyboard_translate_table = 5268 Vkeyboard_translate_table =
5127 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ); 5269 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
5270
5271 DEFVAR_BOOL ("try-alternate-layouts-for-commands",
5272 &try_alternate_layouts_for_commands /*
5273 Non-nil means that if looking up a command from a sequence of keys typed by
5274 the user would otherwise fail, try it again with some other keyboard
5275 layout. On X11, the only alternative to the default mapping is American
5276 QWERTY; on Windows, other mappings may be available, depending on things
5277 like the default language environment for the current user, for the system,
5278 &c.
5279
5280 With a Russian keyboard layout on X11, for example, this means that
5281 C-Cyrillic_che C-Cyrillic_a, if you haven't given that sequence a binding
5282 yourself, will invoke `find-file.' This is because `Cyrillic_che' is
5283 physically where `x' is, and `Cyrillic_a' is where `f' is, on an American
5284 Qwerty layout, and, of course, C-x C-f is a default emacs binding for that
5285 command.
5286 */ );
5287 try_alternate_layouts_for_commands = 1;
5128 } 5288 }
5129 5289
5130 void 5290 void
5131 init_event_stream (void) 5291 init_event_stream (void)
5132 { 5292 {