comparison src/event-stream.c @ 771:943eaba38521

[xemacs-hg @ 2002-03-13 08:51:24 by ben] The big ben-mule-21-5 check-in! Various files were added and deleted. See CHANGES-ben-mule. There are still some test suite failures. No crashes, though. Many of the failures have to do with problems in the test suite itself rather than in the actual code. I'll be addressing these in the next day or so -- none of the test suite failures are at all critical. Meanwhile I'll be trying to address the biggest issues -- i.e. build or run failures, which will almost certainly happen on various platforms. All comments should be sent to ben@xemacs.org -- use a Cc: if necessary when sending to mailing lists. There will be pre- and post- tags, something like pre-ben-mule-21-5-merge-in, and post-ben-mule-21-5-merge-in.
author ben
date Wed, 13 Mar 2002 08:54:06 +0000
parents 516c347c4479
children 026c5bf9c134
comparison
equal deleted inserted replaced
770:336a418893b5 771:943eaba38521
1 /* The portable interface to event streams. 1 /* The portable interface to event streams.
2 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. 2 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
3 Copyright (C) 1995 Board of Trustees, University of Illinois. 3 Copyright (C) 1995 Board of Trustees, University of Illinois.
4 Copyright (C) 1995 Sun Microsystems, Inc. 4 Copyright (C) 1995 Sun Microsystems, Inc.
5 Copyright (C) 1995, 1996 Ben Wing. 5 Copyright (C) 1995, 1996, 2001, 2002 Ben Wing.
6 6
7 This file is part of XEmacs. 7 This file is part of XEmacs.
8 8
9 XEmacs is free software; you can redistribute it and/or modify it 9 XEmacs is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the 10 under the terms of the GNU General Public License as published by the
90 #include "sysdep.h" /* init_poll_for_quit() */ 90 #include "sysdep.h" /* init_poll_for_quit() */
91 #include "syssignal.h" /* SIGCHLD, etc. */ 91 #include "syssignal.h" /* SIGCHLD, etc. */
92 #include "sysfile.h" 92 #include "sysfile.h"
93 #include "systime.h" /* to set Vlast_input_time */ 93 #include "systime.h" /* to set Vlast_input_time */
94 94
95 #ifdef FILE_CODING
96 #include "file-coding.h" 95 #include "file-coding.h"
97 #endif
98 96
99 #include <errno.h> 97 #include <errno.h>
100 98
101 /* The number of keystrokes between auto-saves. */ 99 /* The number of keystrokes between auto-saves. */
102 static Fixnum auto_save_interval; 100 static Fixnum auto_save_interval;
214 212
215 /* If control-meta-super-shift-X is undefined, try control-meta-super-x */ 213 /* If control-meta-super-shift-X is undefined, try control-meta-super-x */
216 Lisp_Object Vretry_undefined_key_binding_unshifted; 214 Lisp_Object Vretry_undefined_key_binding_unshifted;
217 Lisp_Object Qretry_undefined_key_binding_unshifted; 215 Lisp_Object Qretry_undefined_key_binding_unshifted;
218 216
219 #ifdef HAVE_XIM 217 #ifdef MULE
220 /* If composed input is undefined, use self-insert-char */ 218 /* If composed input is undefined, use self-insert-char */
221 Lisp_Object Vcomposed_character_default_binding; 219 Lisp_Object Vcomposed_character_default_binding;
222 #endif /* HAVE_XIM */ 220 #endif
223 221
224 /* Console that corresponds to our controlling terminal */ 222 /* Console that corresponds to our controlling terminal */
225 Lisp_Object Vcontrolling_terminal; 223 Lisp_Object Vcontrolling_terminal;
226 224
227 /* An event (actually an event chain linked through event_next) or Qnil. 225 /* An event (actually an event chain linked through event_next) or Qnil.
312 /**********************************************************************/ 310 /**********************************************************************/
313 311
314 #define XCOMMAND_BUILDER(x) \ 312 #define XCOMMAND_BUILDER(x) \
315 XRECORD (x, command_builder, struct command_builder) 313 XRECORD (x, command_builder, struct command_builder)
316 #define XSETCOMMAND_BUILDER(x, p) XSETRECORD (x, p, command_builder) 314 #define XSETCOMMAND_BUILDER(x, p) XSETRECORD (x, p, command_builder)
315 #define wrap_command_builder(p) wrap_record (p, command_builder)
317 #define COMMAND_BUILDERP(x) RECORDP (x, command_builder) 316 #define COMMAND_BUILDERP(x) RECORDP (x, command_builder)
318 #define CHECK_COMMAND_BUILDER(x) CHECK_RECORD (x, command_builder) 317 #define CHECK_COMMAND_BUILDER(x) CHECK_RECORD (x, command_builder)
318 #define CONCHECK_COMMAND_BUILDER(x) CONCHECK_RECORD (x, command_builder)
319
320 static Lisp_Object Vcommand_builder_free_list;
319 321
320 static Lisp_Object 322 static Lisp_Object
321 mark_command_builder (Lisp_Object obj) 323 mark_command_builder (Lisp_Object obj)
322 { 324 {
323 struct command_builder *builder = XCOMMAND_BUILDER (obj); 325 struct command_builder *builder = XCOMMAND_BUILDER (obj);
324 mark_object (builder->prefix_events);
325 mark_object (builder->current_events); 326 mark_object (builder->current_events);
326 mark_object (builder->most_current_event); 327 mark_object (builder->most_current_event);
327 mark_object (builder->last_non_munged_event); 328 mark_object (builder->last_non_munged_event);
328 mark_object (builder->munge_me[0].first_mungeable_event); 329 mark_object (builder->munge_me[0].first_mungeable_event);
329 mark_object (builder->munge_me[1].first_mungeable_event); 330 mark_object (builder->munge_me[1].first_mungeable_event);
333 static void 334 static void
334 finalize_command_builder (void *header, int for_disksave) 335 finalize_command_builder (void *header, int for_disksave)
335 { 336 {
336 if (!for_disksave) 337 if (!for_disksave)
337 { 338 {
338 xfree (((struct command_builder *) header)->echo_buf); 339 struct command_builder *b = (struct command_builder *) header;
339 ((struct command_builder *) header)->echo_buf = 0; 340 if (b->echo_buf)
341 {
342 xfree (b->echo_buf);
343 b->echo_buf = 0;
344 }
340 } 345 }
341 } 346 }
342 347
343 DEFINE_LRECORD_IMPLEMENTATION ("command-builder", command_builder, 348 DEFINE_LRECORD_IMPLEMENTATION ("command-builder", command_builder,
344 mark_command_builder, internal_object_printer, 349 mark_command_builder, internal_object_printer,
345 finalize_command_builder, 0, 0, 0, 350 finalize_command_builder, 0, 0, 0,
346 struct command_builder); 351 struct command_builder);
347 352
348 static void 353 static void
349 reset_command_builder_event_chain (struct command_builder *builder) 354 reset_command_builder_event_chain (struct command_builder *builder)
350 { 355 {
351 builder->prefix_events = Qnil;
352 builder->current_events = Qnil; 356 builder->current_events = Qnil;
353 builder->most_current_event = Qnil; 357 builder->most_current_event = Qnil;
354 builder->last_non_munged_event = Qnil; 358 builder->last_non_munged_event = Qnil;
355 builder->munge_me[0].first_mungeable_event = Qnil; 359 builder->munge_me[0].first_mungeable_event = Qnil;
356 builder->munge_me[1].first_mungeable_event = Qnil; 360 builder->munge_me[1].first_mungeable_event = Qnil;
357 } 361 }
358 362
359 Lisp_Object 363 Lisp_Object
360 allocate_command_builder (Lisp_Object console) 364 allocate_command_builder (Lisp_Object console, int with_echo_buf)
361 { 365 {
362 Lisp_Object builder_obj; 366 Lisp_Object builder_obj =
363 struct command_builder *builder = 367 allocate_managed_lcrecord (Vcommand_builder_free_list);
364 alloc_lcrecord_type (struct command_builder, &lrecord_command_builder); 368 struct command_builder *builder = XCOMMAND_BUILDER (builder_obj);
365 369
366 builder->console = console; 370 builder->console = console;
367 reset_command_builder_event_chain (builder); 371 reset_command_builder_event_chain (builder);
368 builder->echo_buf_length = 300; /* #### Kludge */ 372 if (with_echo_buf)
369 builder->echo_buf = xnew_array (Intbyte, builder->echo_buf_length); 373 {
370 builder->echo_buf[0] = 0; 374 /* #### This badly needs to be turned into a Dynarr */
371 builder->echo_buf_index = -1; 375 builder->echo_buf_length = 300; /* #### Kludge */
376 builder->echo_buf = xnew_array (Intbyte, builder->echo_buf_length);
377 builder->echo_buf[0] = 0;
378 }
379 else
380 {
381 builder->echo_buf_length = 0;
382 builder->echo_buf = NULL;
383 }
372 builder->echo_buf_index = -1; 384 builder->echo_buf_index = -1;
373 builder->self_insert_countdown = 0; 385 builder->self_insert_countdown = 0;
374 386
375 XSETCOMMAND_BUILDER (builder_obj, builder);
376 return builder_obj; 387 return builder_obj;
388 }
389
390 /* Copy or clone COLLAPSING (copy to NEW_BUILDINGS if non-zero,
391 otherwise clone); but don't copy the echo-buf stuff. (The calling
392 routines don't need it and will reset it, and we would rather avoid
393 malloc.) */
394
395 static Lisp_Object
396 copy_command_builder (struct command_builder *collapsing,
397 struct command_builder *new_buildings)
398 {
399 if (!new_buildings)
400 new_buildings = XCOMMAND_BUILDER (allocate_command_builder (Qnil, 0));
401
402 new_buildings->self_insert_countdown = collapsing->self_insert_countdown;
403
404 deallocate_event_chain (new_buildings->current_events);
405 new_buildings->current_events =
406 copy_event_chain (collapsing->current_events);
407
408 new_buildings->most_current_event =
409 transfer_event_chain_pointer (collapsing->most_current_event,
410 collapsing->current_events,
411 new_buildings->current_events);
412 new_buildings->last_non_munged_event =
413 transfer_event_chain_pointer (collapsing->last_non_munged_event,
414 collapsing->current_events,
415 new_buildings->current_events);
416 new_buildings->munge_me[0].first_mungeable_event =
417 transfer_event_chain_pointer (collapsing->munge_me[0].
418 first_mungeable_event,
419 collapsing->current_events,
420 new_buildings->current_events);
421 new_buildings->munge_me[1].first_mungeable_event =
422 transfer_event_chain_pointer (collapsing->munge_me[1].
423 first_mungeable_event,
424 collapsing->current_events,
425 new_buildings->current_events);
426
427 return wrap_command_builder (new_buildings);
428 }
429
430 static void
431 free_command_builder (struct command_builder *builder)
432 {
433 if (builder->echo_buf)
434 {
435 xfree (builder->echo_buf);
436 builder->echo_buf = NULL;
437 }
438 free_managed_lcrecord (Vcommand_builder_free_list,
439 wrap_command_builder (builder));
377 } 440 }
378 441
379 static void 442 static void
380 command_builder_append_event (struct command_builder *builder, 443 command_builder_append_event (struct command_builder *builder,
381 Lisp_Object event) 444 Lisp_Object event)
382 { 445 {
383 assert (EVENTP (event)); 446 assert (EVENTP (event));
384 447
448 event = Fcopy_event (event, Qnil);
385 if (EVENTP (builder->most_current_event)) 449 if (EVENTP (builder->most_current_event))
386 XSET_EVENT_NEXT (builder->most_current_event, event); 450 XSET_EVENT_NEXT (builder->most_current_event, event);
387 else 451 else
388 builder->current_events = event; 452 builder->current_events = event;
389 453
440 { 504 {
441 return event_stream && event_stream->event_pending_p (user); 505 return event_stream && event_stream->event_pending_p (user);
442 } 506 }
443 507
444 static void 508 static void
445 event_stream_force_event_pending (struct frame* f) 509 event_stream_force_event_pending (struct frame *f)
446 { 510 {
447 if (event_stream->force_event_pending) 511 if (event_stream->force_event_pending)
448 event_stream->force_event_pending (f); 512 event_stream->force_event_pending (f);
449 } 513 }
450 514
467 { 531 {
468 int ch = CONSOLE_QUIT_CHAR (con); 532 int ch = CONSOLE_QUIT_CHAR (con);
469 sigint_happened = 0; 533 sigint_happened = 0;
470 Vquit_flag = Qnil; 534 Vquit_flag = Qnil;
471 character_to_event (ch, event, con, 1, 1); 535 character_to_event (ch, event, con, 1, 1);
472 event->channel = make_console (con); 536 event->channel = wrap_console (con);
473 return 1; 537 return 1;
474 } 538 }
475 return 0; 539 return 0;
476 } 540 }
477 541
575 set_process_selected_p (proc, 0); 639 set_process_selected_p (proc, 0);
576 } 640 }
577 } 641 }
578 642
579 USID 643 USID
580 event_stream_create_stream_pair (void* inhandle, void* outhandle, 644 event_stream_create_stream_pair (void *inhandle, void *outhandle,
581 Lisp_Object* instream, Lisp_Object* outstream, int flags) 645 Lisp_Object *instream, Lisp_Object *outstream, int flags)
582 { 646 {
583 check_event_stream_ok (EVENT_STREAM_PROCESS); 647 check_event_stream_ok (EVENT_STREAM_PROCESS);
584 return event_stream->create_stream_pair_cb 648 return event_stream->create_stream_pair_cb
585 (inhandle, outhandle, instream, outstream, flags); 649 (inhandle, outhandle, instream, outstream, flags);
586 } 650 }
849 if (STRINGP (help)) 913 if (STRINGP (help))
850 internal_with_output_to_temp_buffer (build_string ("*Help*"), 914 internal_with_output_to_temp_buffer (build_string ("*Help*"),
851 print_help, help, Qnil); 915 print_help, help, Qnil);
852 Fnext_command_event (event, Qnil); 916 Fnext_command_event (event, Qnil);
853 /* Remove the help from the frame */ 917 /* Remove the help from the frame */
854 unbind_to (speccount, Qnil); 918 unbind_to (speccount);
855 /* Hmmmm. Tricky. The unbind restores an old window configuration, 919 /* Hmmmm. Tricky. The unbind restores an old window configuration,
856 apparently bypassing any setting of windows_structure_changed. 920 apparently bypassing any setting of windows_structure_changed.
857 So we need to set it so that things get redrawn properly. */ 921 So we need to set it so that things get redrawn properly. */
858 /* #### This is massive overkill. Look at doing it better once the 922 /* #### This is massive overkill. Look at doing it better once the
859 new redisplay is fully in place. */ 923 new redisplay is fully in place. */
1856 /* Do an unwind-protect in case an error occurs in 1920 /* Do an unwind-protect in case an error occurs in
1857 the deselect-frame-hook */ 1921 the deselect-frame-hook */
1858 count = specpdl_depth (); 1922 count = specpdl_depth ();
1859 record_unwind_protect (cleanup_after_missed_defocusing, frame); 1923 record_unwind_protect (cleanup_after_missed_defocusing, frame);
1860 run_deselect_frame_hook (); 1924 run_deselect_frame_hook ();
1861 unbind_to (count, Qnil); 1925 unbind_to (count);
1862 /* the cleanup method changed the focus frame to nil, so 1926 /* the cleanup method changed the focus frame to nil, so
1863 we need to reflect this */ 1927 we need to reflect this */
1864 focus_frame = Qnil; 1928 focus_frame = Qnil;
1865 } 1929 }
1866 else 1930 else
2632 break; 2696 break;
2633 } 2697 }
2634 } 2698 }
2635 } 2699 }
2636 2700
2637 unbind_to (count, timeout_enabled ? make_int (timeout_id) : Qnil); 2701 unbind_to_1 (count, timeout_enabled ? make_int (timeout_id) : Qnil);
2638 2702
2639 Fdeallocate_event (event); 2703 Fdeallocate_event (event);
2640 UNGCPRO; 2704 UNGCPRO;
2641 current_buffer = old_buffer; 2705 current_buffer = old_buffer;
2642 return result; 2706 return result;
2701 break; 2765 break;
2702 } 2766 }
2703 } 2767 }
2704 } 2768 }
2705 DONE_LABEL: 2769 DONE_LABEL:
2706 unbind_to (count, make_int (id)); 2770 unbind_to_1 (count, make_int (id));
2707 Fdeallocate_event (event); 2771 Fdeallocate_event (event);
2708 UNGCPRO; 2772 UNGCPRO;
2709 return Qnil; 2773 return Qnil;
2710 } 2774 }
2711 2775
2838 } 2902 }
2839 } 2903 }
2840 } 2904 }
2841 2905
2842 DONE_LABEL: 2906 DONE_LABEL:
2843 unbind_to (count, make_int (id)); 2907 unbind_to_1 (count, make_int (id));
2844 2908
2845 /* Put back the event (if any) that made Fsit_for() exit before the 2909 /* Put back the event (if any) that made Fsit_for() exit before the
2846 timeout. Note that it is being added to the back of the queue, which 2910 timeout. Note that it is being added to the back of the queue, which
2847 would be inappropriate if there were any user events on the queue 2911 would be inappropriate if there were any user events on the queue
2848 already: we would be misordering them. But we know that there are 2912 already: we would be misordering them. But we know that there are
3073 return event_binding (event0, 1); 3137 return event_binding (event0, 1);
3074 } 3138 }
3075 3139
3076 /* See if we can do function-key-map or key-translation-map translation 3140 /* See if we can do function-key-map or key-translation-map translation
3077 on the current events in the command builder. If so, do this, and 3141 on the current events in the command builder. If so, do this, and
3078 return the resulting binding, if any. */ 3142 return the resulting binding, if any.
3143
3144 DID_MUNGE must be initialized before calling this function. If munging
3145 happened, DID_MUNGE will be non-zero; otherwise, it will be left alone.
3146 */
3079 3147
3080 static Lisp_Object 3148 static Lisp_Object
3081 munge_keymap_translate (struct command_builder *builder, 3149 munge_keymap_translate (struct command_builder *builder,
3082 enum munge_me_out_the_door munge, 3150 enum munge_me_out_the_door munge,
3083 int has_normal_binding_p) 3151 int has_normal_binding_p, int *did_munge)
3084 { 3152 {
3085 Lisp_Object suffix; 3153 Lisp_Object suffix;
3086 3154
3087 EVENT_CHAIN_LOOP (suffix, builder->munge_me[munge].first_mungeable_event) 3155 EVENT_CHAIN_LOOP (suffix, builder->munge_me[munge].first_mungeable_event)
3088 { 3156 {
3117 3185
3118 if (VECTORP (result) || STRINGP (result)) 3186 if (VECTORP (result) || STRINGP (result))
3119 { 3187 {
3120 Lisp_Object new_chain = key_sequence_to_event_chain (result); 3188 Lisp_Object new_chain = key_sequence_to_event_chain (result);
3121 Lisp_Object tempev; 3189 Lisp_Object tempev;
3122 int n, tckn; 3190 int n;
3123 3191
3124 /* If the first_mungeable_event of the other munger is 3192 /* If the first_mungeable_event of the other munger is
3125 within the events we're munging, then it will point to 3193 within the events we're munging, then it will point to
3126 deallocated events afterwards, which is bad -- so make it 3194 deallocated events afterwards, which is bad -- so make it
3127 point at the beginning of the munged events. */ 3195 point at the beginning of the munged events. */
3134 *mungeable_event = new_chain; 3202 *mungeable_event = new_chain;
3135 break; 3203 break;
3136 } 3204 }
3137 } 3205 }
3138 3206
3207 /* Now munge the current event chain in the command builder. */
3139 n = event_chain_count (suffix); 3208 n = event_chain_count (suffix);
3140 command_builder_replace_suffix (builder, suffix, new_chain); 3209 command_builder_replace_suffix (builder, suffix, new_chain);
3141 builder->munge_me[munge].first_mungeable_event = Qnil; 3210 builder->munge_me[munge].first_mungeable_event = Qnil;
3142 /* Now hork this-command-keys as well. */ 3211
3143 3212 *did_munge = 1;
3144 /* We just assume that the events we just replaced are
3145 sitting in copied form at the end of this-command-keys.
3146 If the user did weird things with `dispatch-event' this
3147 may not be the case, but at least we make sure we won't
3148 crash. */
3149 new_chain = copy_event_chain (new_chain);
3150 tckn = event_chain_count (Vthis_command_keys);
3151 if (tckn >= n)
3152 {
3153 this_command_keys_replace_suffix
3154 (event_chain_nth (Vthis_command_keys, tckn - n),
3155 new_chain);
3156 }
3157 3213
3158 result = command_builder_find_leaf_1 (builder); 3214 result = command_builder_find_leaf_1 (builder);
3159 return result; 3215 return result;
3160 } 3216 }
3161 3217
3167 } 3223 }
3168 3224
3169 return Qnil; 3225 return Qnil;
3170 } 3226 }
3171 3227
3172 /* Compare the current state of the command builder against the local and 3228 /* Same as command_builder_find_leaf() below but no Russian C-x
3173 global keymaps, and return the binding. If there is no match, try again, 3229 processing and no defaulting to self-insert-command.
3174 case-insensitively. The return value will be one of:
3175 -- nil (there is no binding)
3176 -- a keymap (part of a command has been specified)
3177 -- a command (anything that satisfies `commandp'; this includes
3178 some symbols, lists, subrs, strings, vectors, and
3179 compiled-function objects)
3180 */ 3230 */
3231
3181 static Lisp_Object 3232 static Lisp_Object
3182 command_builder_find_leaf (struct command_builder *builder, 3233 command_builder_find_leaf_no_mule_processing (struct command_builder *builder,
3183 int allow_misc_user_events_p) 3234 int allow_misc_user_events_p,
3235 int *did_munge)
3184 { 3236 {
3185 /* This function can GC */ 3237 /* This function can GC */
3186 Lisp_Object result; 3238 Lisp_Object result;
3187 Lisp_Object evee = builder->current_events; 3239 Lisp_Object evee = builder->current_events;
3188 3240
3196 } 3248 }
3197 3249
3198 /* if we're currently in a menu accelerator, check there for further 3250 /* if we're currently in a menu accelerator, check there for further
3199 events */ 3251 events */
3200 /* #### fuck me! who wrote this crap? think "abstraction", baby. */ 3252 /* #### fuck me! who wrote this crap? think "abstraction", baby. */
3253 /* #### this horribly-written crap can mess with global state, which
3254 this function should not do. i'm not fixing it now. someone
3255 needs to go and rewrite that shit correctly. --ben */
3201 #if defined(HAVE_X_WINDOWS) && defined(LWLIB_MENUBARS_LUCID) 3256 #if defined(HAVE_X_WINDOWS) && defined(LWLIB_MENUBARS_LUCID)
3202 if (x_kludge_lw_menu_active ()) 3257 if (x_kludge_lw_menu_active ())
3203 { 3258 {
3204 return command_builder_operate_menu_accelerator (builder); 3259 return command_builder_operate_menu_accelerator (builder);
3205 } 3260 }
3218 } 3273 }
3219 #endif 3274 #endif
3220 3275
3221 /* Check to see if we have a potential function-key-map match. */ 3276 /* Check to see if we have a potential function-key-map match. */
3222 if (NILP (result)) 3277 if (NILP (result))
3223 { 3278 result = munge_keymap_translate (builder, MUNGE_ME_FUNCTION_KEY, 0,
3224 result = munge_keymap_translate (builder, MUNGE_ME_FUNCTION_KEY, 0); 3279 did_munge);
3225 regenerate_echo_keys_from_this_command_keys (builder); 3280
3226 }
3227 /* Check to see if we have a potential key-translation-map match. */ 3281 /* Check to see if we have a potential key-translation-map match. */
3228 { 3282 {
3229 Lisp_Object key_translate_result = 3283 Lisp_Object key_translate_result =
3230 munge_keymap_translate (builder, MUNGE_ME_KEY_TRANSLATION, 3284 munge_keymap_translate (builder, MUNGE_ME_KEY_TRANSLATION,
3231 !NILP (result)); 3285 !NILP (result), did_munge);
3232 if (!NILP (key_translate_result)) 3286 if (!NILP (key_translate_result))
3233 { 3287 result = key_translate_result;
3234 result = key_translate_result;
3235 regenerate_echo_keys_from_this_command_keys (builder);
3236 }
3237 } 3288 }
3238 3289
3239 if (!NILP (result)) 3290 if (!NILP (result))
3240 return result; 3291 return result;
3241 3292
3246 3297
3247 if (XEVENT_TYPE (builder->most_current_event) == key_press_event 3298 if (XEVENT_TYPE (builder->most_current_event) == key_press_event
3248 && !NILP (Vretry_undefined_key_binding_unshifted)) 3299 && !NILP (Vretry_undefined_key_binding_unshifted))
3249 { 3300 {
3250 Lisp_Object terminal = builder->most_current_event; 3301 Lisp_Object terminal = builder->most_current_event;
3251 struct key_data* key = & XEVENT (terminal)->event.key; 3302 struct key_data *key = &XEVENT (terminal)->event.key;
3252 Emchar c = 0; 3303 Emchar c = 0;
3253 if ((key->modifiers & XEMACS_MOD_SHIFT) 3304 if ((key->modifiers & XEMACS_MOD_SHIFT)
3254 || (CHAR_OR_CHAR_INTP (key->keysym) 3305 || (CHAR_OR_CHAR_INTP (key->keysym)
3255 && ((c = XCHAR_OR_CHAR_INT (key->keysym)), c >= 'A' && c <= 'Z'))) 3306 && ((c = XCHAR_OR_CHAR_INT (key->keysym)),
3307 c >= 'A' && c <= 'Z')))
3256 { 3308 {
3257 Lisp_Event terminal_copy = *XEVENT (terminal); 3309 Lisp_Object neubauten = copy_command_builder (builder, 0);
3310 struct command_builder *neub = XCOMMAND_BUILDER (neubauten);
3311 struct gcpro gcpro1;
3312
3313 GCPRO1 (neubauten);
3314 terminal = event_chain_tail (neub->current_events);
3315 key = &XEVENT (terminal)->event.key;
3258 3316
3259 if (key->modifiers & XEMACS_MOD_SHIFT) 3317 if (key->modifiers & XEMACS_MOD_SHIFT)
3260 key->modifiers &= (~ XEMACS_MOD_SHIFT); 3318 key->modifiers &= (~ XEMACS_MOD_SHIFT);
3261 else 3319 else
3262 key->keysym = make_char (c + 'a' - 'A'); 3320 key->keysym = make_char (c + 'a' - 'A');
3263 3321
3264 result = command_builder_find_leaf (builder, allow_misc_user_events_p); 3322 result =
3323 command_builder_find_leaf_no_mule_processing
3324 (neub, allow_misc_user_events_p, did_munge);
3325
3265 if (!NILP (result)) 3326 if (!NILP (result))
3327 {
3328 copy_command_builder (neub, builder);
3329 *did_munge = 1;
3330 }
3331 free_command_builder (neub);
3332 UNGCPRO;
3333 if (!NILP (result))
3266 return result; 3334 return result;
3267 /* If there was no match with the lower-case version either,
3268 then put back the upper-case event for the error
3269 message. But make sure that function-key-map didn't
3270 change things out from under us. */
3271 if (EQ (terminal, builder->most_current_event))
3272 *XEVENT (terminal) = terminal_copy;
3273 } 3335 }
3274 } 3336 }
3275 3337
3276 /* help-char is `auto-bound' in every keymap */ 3338 /* help-char is `auto-bound' in every keymap */
3277 if (!NILP (Vprefix_help_command) && 3339 if (!NILP (Vprefix_help_command) &&
3278 event_matches_key_specifier_p (XEVENT (builder->most_current_event), 3340 event_matches_key_specifier_p (XEVENT (builder->most_current_event),
3279 Vhelp_char)) 3341 Vhelp_char))
3280 return Vprefix_help_command; 3342 return Vprefix_help_command;
3281 3343
3282 #ifdef HAVE_XIM 3344 return Qnil;
3345 }
3346
3347 /* Compare the current state of the command builder against the local and
3348 global keymaps, and return the binding. If there is no match, try again,
3349 case-insensitively. The return value will be one of:
3350 -- nil (there is no binding)
3351 -- a keymap (part of a command has been specified)
3352 -- a command (anything that satisfies `commandp'; this includes
3353 some symbols, lists, subrs, strings, vectors, and
3354 compiled-function objects)
3355
3356 This may "munge" the current event chain in the command builder;
3357 i.e. the sequence might be mutated into a different sequence,
3358 which we then pretend is what the user actually typed instead of
3359 the passed-in sequence. This happens as a result of:
3360
3361 -- key-translation-map changes
3362 -- function-key-map changes
3363 -- retry-undefined-key-binding-unshifted (q.v.)
3364 -- "Russian C-x problem" changes (see definition of struct key_data,
3365 events.h)
3366
3367 DID_MUNGE must be initialized before calling this function. If munging
3368 happened, DID_MUNGE will be non-zero; otherwise, it will be left alone.
3369 */
3370
3371 static Lisp_Object
3372 command_builder_find_leaf (struct command_builder *builder,
3373 int allow_misc_user_events_p,
3374 int *did_munge)
3375 {
3376 Lisp_Object result =
3377 command_builder_find_leaf_no_mule_processing
3378 (builder, allow_misc_user_events_p, did_munge);
3379
3380 if (!NILP (result))
3381 return result;
3382
3383 #ifdef MULE
3384 /* #### Do Russian C-x processing here */
3385
3283 /* If keysym is a non-ASCII char, bind it to self-insert-char by default. */ 3386 /* If keysym is a non-ASCII char, bind it to self-insert-char by default. */
3284 if (XEVENT_TYPE (builder->most_current_event) == key_press_event 3387 if (XEVENT_TYPE (builder->most_current_event) == key_press_event
3285 && !NILP (Vcomposed_character_default_binding)) 3388 && !NILP (Vcomposed_character_default_binding))
3286 { 3389 {
3287 Lisp_Object keysym = XEVENT (builder->most_current_event)->event.key.keysym; 3390 Lisp_Object keysym =
3391 XEVENT (builder->most_current_event)->event.key.keysym;
3288 if (CHARP (keysym) && !CHAR_ASCII_P (XCHAR (keysym))) 3392 if (CHARP (keysym) && !CHAR_ASCII_P (XCHAR (keysym)))
3289 return Vcomposed_character_default_binding; 3393 return Vcomposed_character_default_binding;
3290 } 3394 }
3291 #endif /* HAVE_XIM */ 3395 #endif
3292
3293 /* If we read extra events attempting to match a function key but end
3294 up failing, then we release those events back to the command loop
3295 and fail on the original lookup. The released events will then be
3296 reprocessed in the context of the first part having failed. */
3297 if (!NILP (builder->last_non_munged_event))
3298 {
3299 Lisp_Object event0 = builder->last_non_munged_event;
3300
3301 /* Put the commands back on the event queue. */
3302 enqueue_event_chain (XEVENT_NEXT (event0),
3303 &command_event_queue,
3304 &command_event_queue_tail);
3305
3306 /* Then remove them from the command builder. */
3307 XSET_EVENT_NEXT (event0, Qnil);
3308 builder->most_current_event = event0;
3309 builder->last_non_munged_event = Qnil;
3310 }
3311 3396
3312 return Qnil; 3397 return Qnil;
3313 } 3398 }
3314 3399
3400 /* Like command_builder_find_leaf but update this-command-keys and the
3401 echo area as necessary when the current event chain was munged. */
3402
3403 static Lisp_Object
3404 command_builder_find_leaf_and_update_global_state (struct command_builder *
3405 builder,
3406 int
3407 allow_misc_user_events_p)
3408 {
3409 int did_munge = 0;
3410 int orig_length = event_chain_count (builder->current_events);
3411 Lisp_Object result = command_builder_find_leaf (builder,
3412 allow_misc_user_events_p,
3413 &did_munge);
3414
3415 if (did_munge)
3416 {
3417 int tck_length = event_chain_count (Vthis_command_keys);
3418
3419 /* We just assume that the events we just replaced are
3420 sitting in copied form at the end of this-command-keys.
3421 If the user did weird things with `dispatch-event' this
3422 may not be the case, but at least we make sure we won't
3423 crash. */
3424
3425 if (tck_length >= orig_length)
3426 {
3427 Lisp_Object new_chain =
3428 copy_event_chain (builder->current_events);
3429 this_command_keys_replace_suffix
3430 (event_chain_nth (Vthis_command_keys, tck_length - orig_length),
3431 new_chain);
3432
3433 regenerate_echo_keys_from_this_command_keys (builder);
3434 }
3435 }
3436
3437 if (NILP (result))
3438 {
3439 /* If we read extra events attempting to match a function key but end
3440 up failing, then we release those events back to the command loop
3441 and fail on the original lookup. The released events will then be
3442 reprocessed in the context of the first part having failed. */
3443 if (!NILP (builder->last_non_munged_event))
3444 {
3445 Lisp_Object event0 = builder->last_non_munged_event;
3446
3447 /* Put the commands back on the event queue. */
3448 enqueue_event_chain (XEVENT_NEXT (event0),
3449 &command_event_queue,
3450 &command_event_queue_tail);
3451
3452 /* Then remove them from the command builder. */
3453 XSET_EVENT_NEXT (event0, Qnil);
3454 builder->most_current_event = event0;
3455 builder->last_non_munged_event = Qnil;
3456 }
3457 }
3458
3459 return result;
3460 }
3315 3461
3316 /* Every time a command-event (a key, button, or menu selection) is read by 3462 /* Every time a command-event (a key, button, or menu selection) is read by
3317 Fnext_event(), it is stored in the recent_keys_ring, in Vlast_input_event, 3463 Fnext_event(), it is stored in the recent_keys_ring, in Vlast_input_event,
3318 and in Vthis_command_keys. (Eval-events are not stored there.) 3464 and in Vthis_command_keys. (Eval-events are not stored there.)
3319 3465
3683 } 3829 }
3684 3830
3685 regenerate_echo_keys_from_this_command_keys (command_builder); 3831 regenerate_echo_keys_from_this_command_keys (command_builder);
3686 } 3832 }
3687 else 3833 else
3688 { 3834 command_builder_append_event (command_builder, event);
3689 event = Fcopy_event (event, Fmake_event (Qnil, Qnil));
3690
3691 command_builder_append_event (command_builder, event);
3692 }
3693 } 3835 }
3694 3836
3695 { 3837 {
3696 Lisp_Object leaf = command_builder_find_leaf (command_builder, 3838 Lisp_Object leaf =
3697 allow_misc_user_events_p); 3839 command_builder_find_leaf_and_update_global_state
3840 (command_builder,
3841 allow_misc_user_events_p);
3698 struct gcpro gcpro1; 3842 struct gcpro gcpro1;
3699 GCPRO1 (leaf); 3843 GCPRO1 (leaf);
3700 3844
3701 if (KEYMAPP (leaf)) 3845 if (KEYMAPP (leaf))
3702 { 3846 {
3731 /* if quit happened during menu acceleration, pretend we read it */ 3875 /* if quit happened during menu acceleration, pretend we read it */
3732 struct console *con = XCONSOLE (Fselected_console ()); 3876 struct console *con = XCONSOLE (Fselected_console ());
3733 int ch = CONSOLE_QUIT_CHAR (con); 3877 int ch = CONSOLE_QUIT_CHAR (con);
3734 3878
3735 character_to_event (ch, e, con, 1, 1); 3879 character_to_event (ch, e, con, 1, 1);
3736 e->channel = make_console (con); 3880 e->channel = wrap_console (con);
3737 3881
3738 enqueue_command_event (quit_event); 3882 enqueue_command_event (quit_event);
3739 Vquit_flag = Qnil; 3883 Vquit_flag = Qnil;
3740 } 3884 }
3741 } 3885 }
3920 reset the echoing state, and don't go into keyboard macros unless 4064 reset the echoing state, and don't go into keyboard macros unless
3921 followed by another command. Also don't quit here. */ 4065 followed by another command. Also don't quit here. */
3922 int speccount = specpdl_depth (); 4066 int speccount = specpdl_depth ();
3923 specbind (Qinhibit_quit, Qt); 4067 specbind (Qinhibit_quit, Qt);
3924 maybe_echo_keys (command_builder, 0); 4068 maybe_echo_keys (command_builder, 0);
3925 unbind_to (speccount, Qnil); 4069 unbind_to (speccount);
3926 4070
3927 /* If we're recording a keyboard macro, and the last command 4071 /* If we're recording a keyboard macro, and the last command
3928 executed set a prefix argument, then decrement the pointer to 4072 executed set a prefix argument, then decrement the pointer to
3929 the "last character really in the macro" to be just before this 4073 the "last character really in the macro" to be just before this
3930 command. This is so that the ^U in "^U ^X )" doesn't go onto 4074 command. This is so that the ^U in "^U ^X )" doesn't go onto
3941 4085
3942 /* Emacs 18 doesn't unconditionally clear the echoed keystrokes, 4086 /* Emacs 18 doesn't unconditionally clear the echoed keystrokes,
3943 so we don't either */ 4087 so we don't either */
3944 4088
3945 if (!is_scrollbar_event (event)) 4089 if (!is_scrollbar_event (event))
3946 reset_this_command_keys (CONSOLE_LIVE_P (con) ? make_console (con) 4090 reset_this_command_keys (CONSOLE_LIVE_P (con) ? wrap_console (con)
3947 : Qnil, 0); 4091 : Qnil, 0);
3948 } 4092 }
3949 } 4093 }
3950 4094
3951 UNGCPRO; 4095 UNGCPRO;
4100 /* Temporarily pretend the last event was an "up" instead of a 4244 /* Temporarily pretend the last event was an "up" instead of a
4101 "down", and look up its binding. */ 4245 "down", and look up its binding. */
4102 XEVENT_TYPE (terminal) = button_release_event; 4246 XEVENT_TYPE (terminal) = button_release_event;
4103 /* If the "up" version is bound, don't complain. */ 4247 /* If the "up" version is bound, don't complain. */
4104 no_bitching 4248 no_bitching
4105 = !NILP (command_builder_find_leaf (command_builder, 0)); 4249 = !NILP (command_builder_find_leaf_and_update_global_state
4250 (command_builder, 0));
4106 /* Undo the temporary changes we just made. */ 4251 /* Undo the temporary changes we just made. */
4107 XEVENT_TYPE (terminal) = button_press_event; 4252 XEVENT_TYPE (terminal) = button_press_event;
4108 if (no_bitching) 4253 if (no_bitching)
4109 { 4254 {
4110 /* Pretend this press was not seen (treat as a prefix) */ 4255 /* Pretend this press was not seen (treat as a prefix) */
4306 CHECK_STRING (prompt); 4451 CHECK_STRING (prompt);
4307 /* else prompt = Fkeymap_prompt (current_buffer->keymap); may GC */ 4452 /* else prompt = Fkeymap_prompt (current_buffer->keymap); may GC */
4308 QUIT; 4453 QUIT;
4309 4454
4310 if (NILP (continue_echo)) 4455 if (NILP (continue_echo))
4311 reset_this_command_keys (make_console (con), 1); 4456 reset_this_command_keys (wrap_console (con), 1);
4312 4457
4313 specbind (Qinhibit_quit, Qt); 4458 specbind (Qinhibit_quit, Qt);
4314 4459
4315 if (!NILP (dont_downcase_last)) 4460 if (!NILP (dont_downcase_last))
4316 specbind (Qretry_undefined_key_binding_unshifted, Qnil); 4461 specbind (Qretry_undefined_key_binding_unshifted, Qnil);
4338 } 4483 }
4339 } 4484 }
4340 4485
4341 Vquit_flag = Qnil; /* In case we read a ^G; do not call check_quit() here */ 4486 Vquit_flag = Qnil; /* In case we read a ^G; do not call check_quit() here */
4342 Fdeallocate_event (event); 4487 Fdeallocate_event (event);
4343 RETURN_UNGCPRO (unbind_to (speccount, result)); 4488 RETURN_UNGCPRO (unbind_to_1 (speccount, result));
4344 } 4489 }
4345 4490
4346 DEFUN ("this-command-keys", Fthis_command_keys, 0, 0, 0, /* 4491 DEFUN ("this-command-keys", Fthis_command_keys, 0, 0, 0, /*
4347 Return a vector of the keyboard or mouse button events that were used 4492 Return a vector of the keyboard or mouse button events that were used
4348 to invoke this command. This copies the vector and the events; it is safe 4493 to invoke this command. This copies the vector and the events; it is safe
4437 if (!NILP (filename)) 4582 if (!NILP (filename))
4438 { 4583 {
4439 int fd; 4584 int fd;
4440 4585
4441 filename = Fexpand_file_name (filename, Qnil); 4586 filename = Fexpand_file_name (filename, Qnil);
4442 fd = open ((char*) XSTRING_DATA (filename), 4587 fd = qxe_open (XSTRING_DATA (filename),
4443 O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY, 4588 O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY,
4444 CREAT_MODE); 4589 CREAT_MODE);
4445 if (fd < 0) 4590 if (fd < 0)
4446 report_file_error ("Unable to create dribble file", filename); 4591 report_file_error ("Unable to create dribble file", filename);
4447 Vdribble_file = make_filedesc_output_stream (fd, 0, 0, LSTR_CLOSING); 4592 Vdribble_file = make_filedesc_output_stream (fd, 0, 0, LSTR_CLOSING);
4448 #ifdef MULE 4593 #ifdef MULE
4449 Vdribble_file = 4594 Vdribble_file =
4450 make_encoding_output_stream (XLSTREAM (Vdribble_file), 4595 make_coding_output_stream
4451 Fget_coding_system (Qescape_quoted)); 4596 (XLSTREAM (Vdribble_file),
4597 Qescape_quoted, CODING_ENCODE);
4452 #endif 4598 #endif
4453 } 4599 }
4454 return Qnil; 4600 return Qnil;
4455 } 4601 }
4456 4602
4532 recent_keys_ring_size = 100; 4678 recent_keys_ring_size = 100;
4533 num_input_chars = 0; 4679 num_input_chars = 0;
4534 Vtimeout_free_list = make_lcrecord_list (sizeof (Lisp_Timeout), 4680 Vtimeout_free_list = make_lcrecord_list (sizeof (Lisp_Timeout),
4535 &lrecord_timeout); 4681 &lrecord_timeout);
4536 staticpro_nodump (&Vtimeout_free_list); 4682 staticpro_nodump (&Vtimeout_free_list);
4683 Vcommand_builder_free_list =
4684 make_lcrecord_list (sizeof (struct command_builder),
4685 &lrecord_command_builder);
4686 staticpro_nodump (&Vcommand_builder_free_list);
4537 the_low_level_timeout_blocktype = 4687 the_low_level_timeout_blocktype =
4538 Blocktype_new (struct low_level_timeout_blocktype); 4688 Blocktype_new (struct low_level_timeout_blocktype);
4539 something_happened = 0; 4689 something_happened = 0;
4540 recursive_sit_for = Qnil; 4690 recursive_sit_for = Qnil;
4541 } 4691 }
4806 This variable has no effect when `modifier-keys-are-sticky' is nil. 4956 This variable has no effect when `modifier-keys-are-sticky' is nil.
4807 Currently only implemented under X Window System. 4957 Currently only implemented under X Window System.
4808 */ ); 4958 */ );
4809 Vmodifier_keys_sticky_time = make_int (500); 4959 Vmodifier_keys_sticky_time = make_int (500);
4810 4960
4811 #ifdef HAVE_XIM 4961 #ifdef MULE
4812 DEFVAR_LISP ("composed-character-default-binding", 4962 DEFVAR_LISP ("composed-character-default-binding",
4813 &Vcomposed_character_default_binding /* 4963 &Vcomposed_character_default_binding /*
4814 The default keybinding to use for key events from composed input. 4964 The default keybinding to use for key events from composed input.
4815 Window systems frequently have ways to allow the user to compose 4965 Window systems frequently have ways to allow the user to compose
4816 single characters in a language using multiple keystrokes. 4966 single characters in a language using multiple keystrokes.
4817 XEmacs sees these as single character keypress events. 4967 XEmacs sees these as single character keypress events.
4818 */ ); 4968 */ );
4819 Vcomposed_character_default_binding = Qself_insert_command; 4969 Vcomposed_character_default_binding = Qself_insert_command;
4820 #endif /* HAVE_XIM */ 4970 #endif
4821 4971
4822 Vcontrolling_terminal = Qnil; 4972 Vcontrolling_terminal = Qnil;
4823 staticpro (&Vcontrolling_terminal); 4973 staticpro (&Vcontrolling_terminal);
4824 4974
4825 Vdribble_file = Qnil; 4975 Vdribble_file = Qnil;
4866 5016
4867 DEFVAR_BOOL ("inhibit-input-event-recording", &inhibit_input_event_recording /* 5017 DEFVAR_BOOL ("inhibit-input-event-recording", &inhibit_input_event_recording /*
4868 Non-nil inhibits recording of input-events to recent-keys ring. 5018 Non-nil inhibits recording of input-events to recent-keys ring.
4869 */ ); 5019 */ );
4870 inhibit_input_event_recording = 0; 5020 inhibit_input_event_recording = 0;
4871 } 5021
4872
4873 void
4874 complex_vars_of_event_stream (void)
4875 {
4876 Vkeyboard_translate_table = 5022 Vkeyboard_translate_table =
4877 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ); 5023 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
4878 } 5024 }
4879 5025
4880 void 5026 void