comparison src/event-stream.c @ 108:360340f9fd5f r20-1b6

Import from CVS: tag r20-1b6
author cvs
date Mon, 13 Aug 2007 09:18:39 +0200
parents 4be1180a9e89
children fe104dbd9147
comparison
equal deleted inserted replaced
107:523141596bda 108:360340f9fd5f
260 keyboard and mouse events by pushing them here. 260 keyboard and mouse events by pushing them here.
261 261
262 Chained through event_next() 262 Chained through event_next()
263 command_event_queue_tail is a pointer to the last-added element. 263 command_event_queue_tail is a pointer to the last-added element.
264 */ 264 */
265 static Lisp_Object process_event_queue;
266 static Lisp_Object process_event_queue_tail;
267 static Lisp_Object command_event_queue; 265 static Lisp_Object command_event_queue;
268 static Lisp_Object command_event_queue_tail; 266 static Lisp_Object command_event_queue_tail;
269 267
270 /* Nonzero means echo unfinished commands after this many seconds of pause. */ 268 /* Nonzero means echo unfinished commands after this many seconds of pause. */
271 static int echo_keystrokes; 269 static int echo_keystrokes;
277 when waiting for an event. Otherwise holding down C-g could 275 when waiting for an event. Otherwise holding down C-g could
278 cause a suspension back to the shell, which is generally 276 cause a suspension back to the shell, which is generally
279 undesirable. (#### This doesn't fully work.) */ 277 undesirable. (#### This doesn't fully work.) */
280 278
281 int emacs_is_blocking; 279 int emacs_is_blocking;
280
281 /* Handlers which run during sit-for, sleep-for and accept-process-output
282 are not allowed to recursively call these routines. We record here
283 if we are in that situation. */
284
285 static Lisp_Object recursive_sit_for;
286
282 287
283 288
284 /**********************************************************************/ 289 /**********************************************************************/
285 /* Command-builder object */ 290 /* Command-builder object */
286 /**********************************************************************/ 291 /**********************************************************************/
1452 1457
1453 /**********************************************************************/ 1458 /**********************************************************************/
1454 /* enqueuing and dequeuing events */ 1459 /* enqueuing and dequeuing events */
1455 /**********************************************************************/ 1460 /**********************************************************************/
1456 1461
1457 /* Add an event to the back of the process_event_queue */
1458 void
1459 enqueue_process_event (Lisp_Object event)
1460 {
1461 enqueue_event (event, &process_event_queue, &process_event_queue_tail);
1462 }
1463
1464 Lisp_Object
1465 dequeue_process_event (void)
1466 {
1467 return dequeue_event (&process_event_queue, &process_event_queue_tail);
1468 }
1469
1470 /* Add an event to the back of the command-event queue: it will be the next 1462 /* Add an event to the back of the command-event queue: it will be the next
1471 event read after all pending events. This only works on keyboard, 1463 event read after all pending events. This only works on keyboard,
1472 mouse-click, misc-user, and eval events. 1464 mouse-click, misc-user, and eval events.
1473 */ 1465 */
1474 void 1466 void
1854 /* the number of keyboard characters read. callint.c wants this. 1846 /* the number of keyboard characters read. callint.c wants this.
1855 */ 1847 */
1856 Charcount num_input_chars; 1848 Charcount num_input_chars;
1857 1849
1858 static void 1850 static void
1859 next_event_internal (Lisp_Object target_event, int allow_queued, 1851 next_event_internal (Lisp_Object target_event, int allow_queued)
1860 int allow_deferred)
1861 { 1852 {
1862 struct gcpro gcpro1; 1853 struct gcpro gcpro1;
1863 /* QUIT; This is incorrect - the caller must do this because some 1854 /* QUIT; This is incorrect - the caller must do this because some
1864 callers (ie, Fnext_event()) do not want to QUIT. */ 1855 callers (ie, Fnext_event()) do not want to QUIT. */
1865 1856
1875 Fdeallocate_event (event); 1866 Fdeallocate_event (event);
1876 #ifdef DEBUG_XEMACS 1867 #ifdef DEBUG_XEMACS
1877 if (debug_emacs_events) 1868 if (debug_emacs_events)
1878 { 1869 {
1879 write_c_string ("(command event queue) ", 1870 write_c_string ("(command event queue) ",
1880 Qexternal_debugging_output);
1881 print_internal (target_event, Qexternal_debugging_output, 1);
1882 write_c_string ("\n", Qexternal_debugging_output);
1883 }
1884 #endif
1885 }
1886 else if (allow_deferred && !NILP (process_event_queue))
1887 {
1888 Lisp_Object event = dequeue_process_event ();
1889 Fcopy_event (event, target_event);
1890 Fdeallocate_event (event);
1891 #ifdef DEBUG_EMACS
1892 if (debug_emacs_events)
1893 {
1894 write_c_string ("(process event queue) ",
1895 Qexternal_debugging_output); 1871 Qexternal_debugging_output);
1896 print_internal (target_event, Qexternal_debugging_output, 1); 1872 print_internal (target_event, Qexternal_debugging_output, 1);
1897 write_c_string ("\n", Qexternal_debugging_output); 1873 write_c_string ("\n", Qexternal_debugging_output);
1898 } 1874 }
1899 #endif 1875 #endif
2132 recent-keys. */ 2108 recent-keys. */
2133 else 2109 else
2134 { 2110 {
2135 run_pre_idle_hook (); 2111 run_pre_idle_hook ();
2136 redisplay (); 2112 redisplay ();
2137 next_event_internal (event, 1, 1); 2113 next_event_internal (event, 1);
2138 Vquit_flag = Qnil; /* Read C-g as an event. */ 2114 Vquit_flag = Qnil; /* Read C-g as an event. */
2139 store_this_key = 1; 2115 store_this_key = 1;
2140 } 2116 }
2141 } 2117 }
2142 2118
2333 || event_stream_event_pending_p (1)) 2309 || event_stream_event_pending_p (1))
2334 { 2310 {
2335 /* This will take stuff off the command_event_queue, or read it 2311 /* This will take stuff off the command_event_queue, or read it
2336 from the event_stream, but it will not block. 2312 from the event_stream, but it will not block.
2337 */ 2313 */
2338 next_event_internal (event, 1, 1); 2314 next_event_internal (event, 1);
2339 Vquit_flag = Qnil; /* Treat C-g as a user event (ignore it). 2315 Vquit_flag = Qnil; /* Treat C-g as a user event (ignore it).
2340 It is vitally important that we reset 2316 It is vitally important that we reset
2341 Vquit_flag here. Otherwise, if we're 2317 Vquit_flag here. Otherwise, if we're
2342 reading from a TTY console, 2318 reading from a TTY console,
2343 maybe_read_quit_event() will notice 2319 maybe_read_quit_event() will notice
2387 2363
2388 /**********************************************************************/ 2364 /**********************************************************************/
2389 /* pausing until an action occurs */ 2365 /* pausing until an action occurs */
2390 /**********************************************************************/ 2366 /**********************************************************************/
2391 2367
2368 /* This is used in accept-process-output, sleep-for and sit-for.
2369 Before running any process_events in these routines, we set
2370 recursive_sit_for to Qt, and use this unwind protect to reset it to
2371 Qnil upon exit. When recursive_sit_for is Qt, calling any of these
2372 three routines will cause them to return immediately no matter what
2373 their arguments were.
2374
2375 All of these routines install timeouts, so we clear the installed
2376 timeout as well.
2377
2378 Note: It's very easy to break the desired behaviours of these
2379 3 routines. If you make any changes to anything in this area, run
2380 the regression tests at the bottom of the file. -- dmoore */
2381
2382
2383 static Lisp_Object
2384 sit_for_unwind (Lisp_Object timeout_id)
2385 {
2386 if (!NILP(timeout_id))
2387 Fdisable_timeout (timeout_id);
2388
2389 recursive_sit_for = Qnil;
2390 return Qnil;
2391 }
2392
2392 /* #### Is (accept-process-output nil 3) supposed to be like (sleep-for 3)? 2393 /* #### Is (accept-process-output nil 3) supposed to be like (sleep-for 3)?
2393 */ 2394 */
2394 2395
2395 DEFUN ("accept-process-output", Faccept_process_output, 0, 3, 0, /* 2396 DEFUN ("accept-process-output", Faccept_process_output, 0, 3, 0, /*
2396 Allow any pending output from subprocesses to be read by Emacs. 2397 Allow any pending output from subprocesses to be read by Emacs.
2403 from PROCESS. This argument may be a float, meaning wait some fractional 2404 from PROCESS. This argument may be a float, meaning wait some fractional
2404 part of a second. 2405 part of a second.
2405 If the third arg is non-nil, it is a number of milliseconds that is added 2406 If the third arg is non-nil, it is a number of milliseconds that is added
2406 to the second arg. (This exists only for compatibility.) 2407 to the second arg. (This exists only for compatibility.)
2407 Return non-nil iff we received any output before the timeout expired. 2408 Return non-nil iff we received any output before the timeout expired.
2409
2410 If a filter function or timeout handler (such as installed by `add-timeout')
2411 calls any of accept-process-output, sleep-for, or sit-for, those calls
2412 will return nil immediately (regardless of their arguments) in recursive
2413 situations. It is recommended that you never call accept-process-output
2414 from inside of a process filter function or timer event (either synchronous
2415 or asynchronous).
2408 */ 2416 */
2409 (process, timeout_secs, timeout_msecs)) 2417 (process, timeout_secs, timeout_msecs))
2410 { 2418 {
2411 /* This function can GC */ 2419 /* This function can GC */
2412 struct gcpro gcpro1, gcpro2; 2420 struct gcpro gcpro1, gcpro2;
2414 Lisp_Object result = Qnil; 2422 Lisp_Object result = Qnil;
2415 int timeout_id; 2423 int timeout_id;
2416 int timeout_enabled = 0; 2424 int timeout_enabled = 0;
2417 int done = 0; 2425 int done = 0;
2418 struct buffer *old_buffer = current_buffer; 2426 struct buffer *old_buffer = current_buffer;
2427 int count;
2428
2429 /* Recusive call from a filter function or timeout handler. */
2430 if (!NILP(recursive_sit_for))
2431 return Qnil;
2419 2432
2420 /* We preserve the current buffer but nothing else. If a focus 2433 /* We preserve the current buffer but nothing else. If a focus
2421 change alters the selected window then the top level event loop 2434 change alters the selected window then the top level event loop
2422 will eventually alter current_buffer to match. In the mean time 2435 will eventually alter current_buffer to match. In the mean time
2423 we don't want to mess up whatever called this function. */ 2436 we don't want to mess up whatever called this function. */
2444 } 2457 }
2445 } 2458 }
2446 2459
2447 event = Fmake_event (); 2460 event = Fmake_event ();
2448 2461
2462 count = specpdl_depth ();
2463 record_unwind_protect (sit_for_unwind,
2464 timeout_enabled ? make_int (timeout_id) : Qnil);
2465 recursive_sit_for = Qt;
2466
2449 while (!done && 2467 while (!done &&
2450 ((NILP (process) && timeout_enabled) || 2468 ((NILP (process) && timeout_enabled) ||
2451 (NILP (process) && event_stream_event_pending_p (0)) || 2469 (NILP (process) && event_stream_event_pending_p (0)) ||
2452 (!NILP (process)))) 2470 (!NILP (process))))
2453 /* Calling detect_input_pending() is the wrong thing here, because 2471 /* Calling detect_input_pending() is the wrong thing here, because
2476 QUIT; /* next_event_internal() does not QUIT, so check for ^G 2494 QUIT; /* next_event_internal() does not QUIT, so check for ^G
2477 before reading output from the process - this makes it 2495 before reading output from the process - this makes it
2478 less likely that the filter will actually be aborted. 2496 less likely that the filter will actually be aborted.
2479 */ 2497 */
2480 2498
2481 next_event_internal (event, 0, 1); 2499 next_event_internal (event, 0);
2482 /* If C-g was pressed while we were waiting, Vquit_flag got 2500 /* If C-g was pressed while we were waiting, Vquit_flag got
2483 set and next_event_internal() also returns C-g. When 2501 set and next_event_internal() also returns C-g. When
2484 we enqueue the C-g below, it will get discarded. The 2502 we enqueue the C-g below, it will get discarded. The
2485 next time through, QUIT will be called and will signal a quit. */ 2503 next time through, QUIT will be called and will signal a quit. */
2486 switch (XEVENT_TYPE (event)) 2504 switch (XEVENT_TYPE (event))
2515 break; 2533 break;
2516 } 2534 }
2517 } 2535 }
2518 } 2536 }
2519 2537
2520 /* If our timeout has not been signalled yet, disable it. */ 2538 unbind_to (count, timeout_enabled ? make_int (timeout_id) : Qnil);
2521 if (timeout_enabled)
2522 event_stream_disable_wakeup (timeout_id, 0);
2523 2539
2524 Fdeallocate_event (event); 2540 Fdeallocate_event (event);
2525 UNGCPRO; 2541 UNGCPRO;
2526 current_buffer = old_buffer; 2542 current_buffer = old_buffer;
2527 return result; 2543 return result;
2528 } 2544 }
2529 2545
2530 DEFUN ("sleep-for", Fsleep_for, 1, 1, 0, /* 2546 DEFUN ("sleep-for", Fsleep_for, 1, 1, 0, /*
2531 Pause, without updating display, for ARG seconds. 2547 Pause, without updating display, for ARG seconds.
2532 ARG may be a float, meaning pause for some fractional part of a second. 2548 ARG may be a float, meaning pause for some fractional part of a second.
2549
2550 If a filter function or timeout handler (such as installed by `add-timeout')
2551 calls any of accept-process-output, sleep-for, or sit-for, those calls
2552 will return nil immediately (regardless of their arguments) in recursive
2553 situations. It is recommended that you never call sleep-for from inside
2554 of a process filter function or timer event (either synchronous or
2555 asynchronous).
2533 */ 2556 */
2534 (seconds)) 2557 (seconds))
2535 { 2558 {
2536 /* This function can GC */ 2559 /* This function can GC */
2537 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1); 2560 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1);
2538 int id; 2561 int id;
2539 Lisp_Object event = Qnil; 2562 Lisp_Object event = Qnil;
2563 int count;
2540 struct gcpro gcpro1; 2564 struct gcpro gcpro1;
2565
2566 /* Recusive call from a filter function or timeout handler. */
2567 if (!NILP(recursive_sit_for))
2568 return Qnil;
2541 2569
2542 GCPRO1 (event); 2570 GCPRO1 (event);
2543 2571
2544 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0); 2572 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0);
2545 event = Fmake_event (); 2573 event = Fmake_event ();
2574
2575 count = specpdl_depth ();
2576 record_unwind_protect (sit_for_unwind, make_int (id));
2577 recursive_sit_for = Qt;
2578
2546 while (1) 2579 while (1)
2547 { 2580 {
2548 /* If our timeout has arrived, we move along. */ 2581 /* If our timeout has arrived, we move along. */
2549 if (!event_stream_wakeup_pending_p (id, 0)) 2582 if (!event_stream_wakeup_pending_p (id, 0))
2550 goto DONE_LABEL; 2583 goto DONE_LABEL;
2555 */ 2588 */
2556 /* We're a generator of the command_event_queue, so we can't be a 2589 /* We're a generator of the command_event_queue, so we can't be a
2557 consumer as well. We don't care about command and eval-events 2590 consumer as well. We don't care about command and eval-events
2558 anyway. 2591 anyway.
2559 */ 2592 */
2560 next_event_internal (event, 0, 0); /* blocks */ 2593 next_event_internal (event, 0); /* blocks */
2561 /* See the comment in accept-process-output about Vquit_flag */ 2594 /* See the comment in accept-process-output about Vquit_flag */
2562 switch (XEVENT_TYPE (event)) 2595 switch (XEVENT_TYPE (event))
2563 { 2596 {
2564 case process_event:
2565 {
2566 /* Avoid calling filter functions recursively by squirreling
2567 away process events */
2568 enqueue_process_event (Fcopy_event (event, Qnil));
2569 goto DONE_LABEL;
2570 }
2571
2572 case timeout_event: 2597 case timeout_event:
2573 /* We execute the event even if it's ours, and notice that it's 2598 /* We execute the event even if it's ours, and notice that it's
2574 happened above. */ 2599 happened above. */
2600 case process_event:
2575 case pointer_motion_event: 2601 case pointer_motion_event:
2576 case magic_event: 2602 case magic_event:
2577 { 2603 {
2578 EXECUTE_INTERNAL: 2604 EXECUTE_INTERNAL:
2579 execute_internal_event (event); 2605 execute_internal_event (event);
2585 break; 2611 break;
2586 } 2612 }
2587 } 2613 }
2588 } 2614 }
2589 DONE_LABEL: 2615 DONE_LABEL:
2616 unbind_to (count, make_int (id));
2590 Fdeallocate_event (event); 2617 Fdeallocate_event (event);
2591 UNGCPRO; 2618 UNGCPRO;
2592 return Qnil; 2619 return Qnil;
2593 } 2620 }
2594 2621
2595 DEFUN ("sit-for", Fsit_for, 1, 2, 0, /* 2622 DEFUN ("sit-for", Fsit_for, 1, 2, 0, /*
2596 Perform redisplay, then wait ARG seconds or until user input is available. 2623 Perform redisplay, then wait ARG seconds or until user input is available.
2597 ARG may be a float, meaning a fractional part of a second. 2624 ARG may be a float, meaning a fractional part of a second.
2598 Optional second arg non-nil means don't redisplay, just wait for input. 2625 Optional second arg non-nil means don't redisplay, just wait for input.
2599 Redisplay is preempted as always if user input arrives, and does not 2626 Redisplay is preempted as always if user input arrives, and does not
2600 happen if input is available before it starts. 2627 happen if input is available before it starts.
2601 Value is t if waited the full time with no input arriving. 2628 Value is t if waited the full time with no input arriving.
2629
2630 If a filter function or timeout handler (such as installed by `add-timeout')
2631 calls any of accept-process-output, sleep-for, or sit-for, those calls
2632 will return nil immediately (regardless of their arguments) in recursive
2633 situations. It is recommended that you never call sit-for from inside
2634 of a process filter function or timer event (either synchronous or
2635 asynchronous) with an argument other than 0.
2602 */ 2636 */
2603 (seconds, nodisplay)) 2637 (seconds, nodisplay))
2604 { 2638 {
2605 /* This function can GC */ 2639 /* This function can GC */
2606 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1); 2640 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1);
2607 Lisp_Object event, result; 2641 Lisp_Object event, result;
2608 struct gcpro gcpro1; 2642 struct gcpro gcpro1;
2609 int id; 2643 int id;
2644 int count;
2645
2646 /* Recusive call from a filter function or timeout handler. */
2647 if (!NILP(recursive_sit_for))
2648 return Qnil;
2610 2649
2611 /* The unread-command-events count as pending input */ 2650 /* The unread-command-events count as pending input */
2612 if (!NILP (Vunread_command_events) || !NILP (Vunread_command_event)) 2651 if (!NILP (Vunread_command_events) || !NILP (Vunread_command_event))
2613 return Qnil; 2652 return Qnil;
2614 2653
2631 2670
2632 /* Otherwise, start reading events from the event_stream. 2671 /* Otherwise, start reading events from the event_stream.
2633 Do this loop at least once even if (sit-for 0) so that we 2672 Do this loop at least once even if (sit-for 0) so that we
2634 redisplay when no input pending. 2673 redisplay when no input pending.
2635 */ 2674 */
2675 GCPRO1 (event);
2636 event = Fmake_event (); 2676 event = Fmake_event ();
2637 GCPRO1 (event);
2638 2677
2639 /* Generate the wakeup even if MSECS is 0, so that existing timeout/etc. 2678 /* Generate the wakeup even if MSECS is 0, so that existing timeout/etc.
2640 events get processed. The old (pre-19.12) code special-cased this 2679 events get processed. The old (pre-19.12) code special-cased this
2641 and didn't generate a wakeup, but the resulting behavior was less than 2680 and didn't generate a wakeup, but the resulting behavior was less than
2642 ideal; viz. the occurrence of (sit-for 0.001) scattered throughout 2681 ideal; viz. the occurrence of (sit-for 0.001) scattered throughout
2643 the E-Lisp universe. */ 2682 the E-Lisp universe. */
2644 2683
2645 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0); 2684 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0);
2685
2686 count = specpdl_depth ();
2687 record_unwind_protect (sit_for_unwind, make_int (id));
2688 recursive_sit_for = Qt;
2646 2689
2647 while (1) 2690 while (1)
2648 { 2691 {
2649 /* If there is no user input pending, then redisplay. 2692 /* If there is no user input pending, then redisplay.
2650 */ 2693 */
2667 */ 2710 */
2668 /* We're a generator of the command_event_queue, so we can't be a 2711 /* We're a generator of the command_event_queue, so we can't be a
2669 consumer as well. In fact, we know there's nothing on the 2712 consumer as well. In fact, we know there's nothing on the
2670 command_event_queue that we didn't just put there. 2713 command_event_queue that we didn't just put there.
2671 */ 2714 */
2672 next_event_internal (event, 0, 0); /* blocks */ 2715 next_event_internal (event, 0); /* blocks */
2673 /* See the comment in accept-process-output about Vquit_flag */ 2716 /* See the comment in accept-process-output about Vquit_flag */
2674 2717
2675 if (command_event_p (event)) 2718 if (command_event_p (event))
2676 { 2719 {
2720 QUIT; /* If the command was C-g check it here
2721 so that we abort out of the sit-for,
2722 not the next command. sleep-for and
2723 accept-process-output continue looping
2724 so they check QUIT again implicitly.*/
2677 result = Qnil; 2725 result = Qnil;
2678 goto DONE_LABEL; 2726 goto DONE_LABEL;
2679 } 2727 }
2680 switch (XEVENT_TYPE (event)) 2728 switch (XEVENT_TYPE (event))
2681 { 2729 {
2683 { 2731 {
2684 /* eval-events get delayed until later. */ 2732 /* eval-events get delayed until later. */
2685 enqueue_command_event (Fcopy_event (event, Qnil)); 2733 enqueue_command_event (Fcopy_event (event, Qnil));
2686 break; 2734 break;
2687 } 2735 }
2688
2689 case process_event:
2690 {
2691 /* Avoid recursive calls to process filters */
2692 enqueue_process_event (Fcopy_event (event, Qnil));
2693 break;
2694 }
2695 2736
2696 case timeout_event: 2737 case timeout_event:
2697 /* We execute the event even if it's ours, and notice that it's 2738 /* We execute the event even if it's ours, and notice that it's
2698 happened above. */ 2739 happened above. */
2699 default: 2740 default:
2704 } 2745 }
2705 } 2746 }
2706 } 2747 }
2707 2748
2708 DONE_LABEL: 2749 DONE_LABEL:
2709 /* If our timeout has not been signalled yet, disable it. */ 2750 unbind_to (count, make_int (id));
2710 if (NILP (result))
2711 event_stream_disable_wakeup (id, 0);
2712 2751
2713 /* Put back the event (if any) that made Fsit_for() exit before the 2752 /* Put back the event (if any) that made Fsit_for() exit before the
2714 timeout. Note that it is being added to the back of the queue, which 2753 timeout. Note that it is being added to the back of the queue, which
2715 would be inappropriate if there were any user events on the queue 2754 would be inappropriate if there were any user events on the queue
2716 already: we would be misordering them. But we know that there are 2755 already: we would be misordering them. But we know that there are
2745 /* We're a generator of the command_event_queue, so we can't be a 2784 /* We're a generator of the command_event_queue, so we can't be a
2746 consumer as well. Also, we have no reason to consult the 2785 consumer as well. Also, we have no reason to consult the
2747 command_event_queue; there are only user and eval-events there, 2786 command_event_queue; there are only user and eval-events there,
2748 and we'd just have to put them back anyway. 2787 and we'd just have to put them back anyway.
2749 */ 2788 */
2750 next_event_internal (event, 0, 1); 2789 next_event_internal (event, 0);
2751 /* See the comment in accept-process-output about Vquit_flag */ 2790 /* See the comment in accept-process-output about Vquit_flag */
2752 if (command_event_p (event) 2791 if (command_event_p (event)
2753 || (XEVENT_TYPE (event) == eval_event) 2792 || (XEVENT_TYPE (event) == eval_event)
2754 || (XEVENT_TYPE (event) == magic_eval_event)) 2793 || (XEVENT_TYPE (event) == magic_eval_event))
2755 enqueue_command_event_1 (event); 2794 enqueue_command_event_1 (event);
4181 4220
4182 command_event_queue = Qnil; 4221 command_event_queue = Qnil;
4183 staticpro (&command_event_queue); 4222 staticpro (&command_event_queue);
4184 command_event_queue_tail = Qnil; 4223 command_event_queue_tail = Qnil;
4185 4224
4186 process_event_queue = Qnil;
4187 staticpro (&process_event_queue);
4188 process_event_queue_tail = Qnil;
4189
4190 Vlast_selected_frame = Qnil; 4225 Vlast_selected_frame = Qnil;
4191 staticpro (&Vlast_selected_frame); 4226 staticpro (&Vlast_selected_frame);
4192 4227
4193 pending_timeout_list = Qnil; 4228 pending_timeout_list = Qnil;
4194 staticpro (&pending_timeout_list); 4229 staticpro (&pending_timeout_list);
4205 4240
4206 something_happened = 0; 4241 something_happened = 0;
4207 4242
4208 last_point_position_buffer = Qnil; 4243 last_point_position_buffer = Qnil;
4209 staticpro (&last_point_position_buffer); 4244 staticpro (&last_point_position_buffer);
4245
4246 recursive_sit_for = Qnil;
4210 4247
4211 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes /* 4248 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes /*
4212 *Nonzero means echo unfinished commands after this many seconds of pause. 4249 *Nonzero means echo unfinished commands after this many seconds of pause.
4213 */ ); 4250 */ );
4214 echo_keystrokes = 1; 4251 echo_keystrokes = 1;
4550 ;a should be inserted in foo. Cursor highlighting should not change in 4587 ;a should be inserted in foo. Cursor highlighting should not change in
4551 ;the meantime. 4588 ;the meantime.
4552 4589
4553 ;do it with sleep-for. move cursor into foo, then back into *scratch* 4590 ;do it with sleep-for. move cursor into foo, then back into *scratch*
4554 ;before typing. 4591 ;before typing.
4555 4592 ;repeat also with (accept-process-output nil 20)
4556 ;make sure ^G aborts both sit-for and sleep-for. 4593
4594 ;make sure ^G aborts sit-for, sleep-for and accept-process-output:
4557 4595
4558 (defun tst () 4596 (defun tst ()
4559 (list (condition-case c 4597 (list (condition-case c
4560 (sleep-for 20) 4598 (sleep-for 20)
4561 (quit c)) 4599 (quit c))
4562 (read-char))) 4600 (read-char)))
4563 4601
4564 (tst)^Ja^G ==> ((quit) 97) with no signal 4602 (tst)^Ja^G ==> ((quit) 97) with no signal
4565 (tst)^J^Ga ==> ((quit) 97) with no signal 4603 (tst)^J^Ga ==> ((quit) 97) with no signal
4566 (tst)^Jabc^G ==> ((quit) 97) with no signal, and "bc" inserted in buffer 4604 (tst)^Jabc^G ==> ((quit) 97) with no signal, and "bc" inserted in buffer
4605
4606 ; with sit-for only do the 2nd test.
4607 ; Do all 3 tests with (accept-proccess-output nil 20)
4567 4608
4568 Do this: 4609 Do this:
4569 (setq enable-recursive-minibuffers t 4610 (setq enable-recursive-minibuffers t
4570 minibuffer-max-depth nil) 4611 minibuffer-max-depth nil)
4571 ESC ESC ESC ESC - there are now two minibuffers active 4612 ESC ESC ESC ESC - there are now two minibuffers active
4577 however C-g before "Quit" is displayed should leave minibuffer active. 4618 however C-g before "Quit" is displayed should leave minibuffer active.
4578 4619
4579 ;do it all in both v18 and v19 and make sure all results are the same. 4620 ;do it all in both v18 and v19 and make sure all results are the same.
4580 ;all of these cases matter a lot, but some in quite subtle ways. 4621 ;all of these cases matter a lot, but some in quite subtle ways.
4581 */ 4622 */
4623
4624 /*
4625 Additional test cases for accept-process-output, sleep-for, sit-for.
4626 Be sure you do all of the above checking for C-g and focus, too!
4627
4628 ; Make sure that timer handlers are run during, not after sit-for:
4629 (defun timer-check ()
4630 (add-timeout 2 '(lambda (ignore) (message "timer ran")) nil)
4631 (sit-for 5)
4632 (message "after sit-for"))
4633
4634 ; The first message should appear after 2 seconds, and the final message
4635 ; 3 seconds after that.
4636 ; repeat above test with (sleep-for 5) and (accept-process-output nil 5)
4637
4638
4639
4640 ; Make sure that process filters are run during, not after sit-for.
4641 (defun fubar ()
4642 (message "sit-for = %s" (sit-for 30)))
4643 (add-hook 'post-command-hook 'fubar)
4644
4645 ; Now type M-x shell RET
4646 ; wait for the shell prompt then send: ls RET
4647 ; the output of ls should fill immediately, and not wait 30 seconds.
4648
4649 ; repeat above test with (sleep-for 30) and (accept-process-output nil 30)
4650
4651
4652
4653 ; Make sure that recursive invocations return immediately:
4654 (defmacro test-diff-time (start end)
4655 `(+ (* (- (car ,end) (car ,start)) 65536.0)
4656 (- (cadr ,end) (cadr ,start))
4657 (/ (- (caddr ,end) (caddr ,start)) 1000000.0)))
4658
4659 (defun testee (ignore)
4660 ;; All three of these should return immediately.
4661 (sit-for 10)
4662 (sleep-for 10)
4663 (accept-process-output nil 10))
4664
4665 (defun test-them ()
4666 (let ((start (current-time))
4667 end)
4668 (add-timeout 2 'testee nil)
4669 (sit-for 5)
4670 (add-timeout 2 'testee nil)
4671 (sleep-for 5)
4672 (add-timeout 2 'testee nil)
4673 (accept-process-output nil 5)
4674 (setq end (current-time))
4675 (test-diff-time start end)))
4676
4677 (test-them) should sit for 15 seconds, not 105 or 96.
4678
4679
4680 */