Mercurial > hg > xemacs-beta
comparison src/event-stream.c @ 30:ec9a17fef872 r19-15b98
Import from CVS: tag r19-15b98
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:52:29 +0200 |
parents | 859a2309aef8 |
children | e04119814345 |
comparison
equal
deleted
inserted
replaced
29:7976500f47f9 | 30:ec9a17fef872 |
---|---|
249 keyboard and mouse events by pushing them here. | 249 keyboard and mouse events by pushing them here. |
250 | 250 |
251 Chained through event_next() | 251 Chained through event_next() |
252 command_event_queue_tail is a pointer to the last-added element. | 252 command_event_queue_tail is a pointer to the last-added element. |
253 */ | 253 */ |
254 static Lisp_Object process_event_queue; | |
255 static Lisp_Object process_event_queue_tail; | |
256 static Lisp_Object command_event_queue; | 254 static Lisp_Object command_event_queue; |
257 static Lisp_Object command_event_queue_tail; | 255 static Lisp_Object command_event_queue_tail; |
258 | 256 |
259 /* Nonzero means echo unfinished commands after this many seconds of pause. */ | 257 /* Nonzero means echo unfinished commands after this many seconds of pause. */ |
260 static int echo_keystrokes; | 258 static int echo_keystrokes; |
266 when waiting for an event. Otherwise holding down C-g could | 264 when waiting for an event. Otherwise holding down C-g could |
267 cause a suspension back to the shell, which is generally | 265 cause a suspension back to the shell, which is generally |
268 undesirable. (#### This doesn't fully work.) */ | 266 undesirable. (#### This doesn't fully work.) */ |
269 | 267 |
270 int emacs_is_blocking; | 268 int emacs_is_blocking; |
269 | |
270 /* Handlers which run during sit-for, sleep-for and accept-process-output | |
271 are not allowed to recursively call these routines. We record here | |
272 if we are in that situation. */ | |
273 | |
274 static Lisp_Object recursive_sit_for; | |
275 | |
271 | 276 |
272 | 277 |
273 /**********************************************************************/ | 278 /**********************************************************************/ |
274 /* Command-builder object */ | 279 /* Command-builder object */ |
275 /**********************************************************************/ | 280 /**********************************************************************/ |
1441 | 1446 |
1442 /**********************************************************************/ | 1447 /**********************************************************************/ |
1443 /* enqueuing and dequeuing events */ | 1448 /* enqueuing and dequeuing events */ |
1444 /**********************************************************************/ | 1449 /**********************************************************************/ |
1445 | 1450 |
1446 /* Add an event to the back of the process_event_queue */ | |
1447 void | |
1448 enqueue_process_event (Lisp_Object event) | |
1449 { | |
1450 enqueue_event (event, &process_event_queue, &process_event_queue_tail); | |
1451 } | |
1452 | |
1453 Lisp_Object | |
1454 dequeue_process_event (void) | |
1455 { | |
1456 return dequeue_event (&process_event_queue, &process_event_queue_tail); | |
1457 } | |
1458 | |
1459 /* Add an event to the back of the command-event queue: it will be the next | 1451 /* Add an event to the back of the command-event queue: it will be the next |
1460 event read after all pending events. This only works on keyboard, | 1452 event read after all pending events. This only works on keyboard, |
1461 mouse-click, misc-user, and eval events. | 1453 mouse-click, misc-user, and eval events. |
1462 */ | 1454 */ |
1463 void | 1455 void |
1843 /* the number of keyboard characters read. callint.c wants this. | 1835 /* the number of keyboard characters read. callint.c wants this. |
1844 */ | 1836 */ |
1845 Charcount num_input_chars; | 1837 Charcount num_input_chars; |
1846 | 1838 |
1847 static void | 1839 static void |
1848 next_event_internal (Lisp_Object target_event, int allow_queued, | 1840 next_event_internal (Lisp_Object target_event, int allow_queued) |
1849 int allow_deferred) | |
1850 { | 1841 { |
1851 struct gcpro gcpro1; | 1842 struct gcpro gcpro1; |
1852 /* QUIT; This is incorrect - the caller must do this because some | 1843 /* QUIT; This is incorrect - the caller must do this because some |
1853 callers (ie, Fnext_event()) do not want to QUIT. */ | 1844 callers (ie, Fnext_event()) do not want to QUIT. */ |
1854 | 1845 |
1864 Fdeallocate_event (event); | 1855 Fdeallocate_event (event); |
1865 #ifdef DEBUG_XEMACS | 1856 #ifdef DEBUG_XEMACS |
1866 if (debug_emacs_events) | 1857 if (debug_emacs_events) |
1867 { | 1858 { |
1868 write_c_string ("(command event queue) ", | 1859 write_c_string ("(command event queue) ", |
1869 Qexternal_debugging_output); | |
1870 print_internal (target_event, Qexternal_debugging_output, 1); | |
1871 write_c_string ("\n", Qexternal_debugging_output); | |
1872 } | |
1873 #endif | |
1874 } | |
1875 else if (allow_deferred && !NILP (process_event_queue)) | |
1876 { | |
1877 Lisp_Object event = dequeue_process_event (); | |
1878 Fcopy_event (event, target_event); | |
1879 Fdeallocate_event (event); | |
1880 #ifdef DEBUG_EMACS | |
1881 if (debug_emacs_events) | |
1882 { | |
1883 write_c_string ("(process event queue) ", | |
1884 Qexternal_debugging_output); | 1860 Qexternal_debugging_output); |
1885 print_internal (target_event, Qexternal_debugging_output, 1); | 1861 print_internal (target_event, Qexternal_debugging_output, 1); |
1886 write_c_string ("\n", Qexternal_debugging_output); | 1862 write_c_string ("\n", Qexternal_debugging_output); |
1887 } | 1863 } |
1888 #endif | 1864 #endif |
2121 recent-keys. */ | 2097 recent-keys. */ |
2122 else | 2098 else |
2123 { | 2099 { |
2124 run_pre_idle_hook (); | 2100 run_pre_idle_hook (); |
2125 redisplay (); | 2101 redisplay (); |
2126 next_event_internal (event, 1, 1); | 2102 next_event_internal (event, 1); |
2127 Vquit_flag = Qnil; /* Read C-g as an event. */ | 2103 Vquit_flag = Qnil; /* Read C-g as an event. */ |
2128 store_this_key = 1; | 2104 store_this_key = 1; |
2129 } | 2105 } |
2130 } | 2106 } |
2131 | 2107 |
2322 || event_stream_event_pending_p (1)) | 2298 || event_stream_event_pending_p (1)) |
2323 { | 2299 { |
2324 /* This will take stuff off the command_event_queue, or read it | 2300 /* This will take stuff off the command_event_queue, or read it |
2325 from the event_stream, but it will not block. | 2301 from the event_stream, but it will not block. |
2326 */ | 2302 */ |
2327 next_event_internal (event, 1, 1); | 2303 next_event_internal (event, 1); |
2328 Vquit_flag = Qnil; /* Treat C-g as a user event (ignore it). | 2304 Vquit_flag = Qnil; /* Treat C-g as a user event (ignore it). |
2329 It is vitally important that we reset | 2305 It is vitally important that we reset |
2330 Vquit_flag here. Otherwise, if we're | 2306 Vquit_flag here. Otherwise, if we're |
2331 reading from a TTY console, | 2307 reading from a TTY console, |
2332 maybe_read_quit_event() will notice | 2308 maybe_read_quit_event() will notice |
2376 | 2352 |
2377 /**********************************************************************/ | 2353 /**********************************************************************/ |
2378 /* pausing until an action occurs */ | 2354 /* pausing until an action occurs */ |
2379 /**********************************************************************/ | 2355 /**********************************************************************/ |
2380 | 2356 |
2357 /* This is used in accept-process-output, sleep-for and sit-for. | |
2358 Before running any process_events in these routines, we set | |
2359 recursive_sit_for to Qt, and use this unwind protect to reset it to | |
2360 Qnil upon exit. When recursive_sit_for is Qt, calling any of these | |
2361 three routines will cause them to return immediately no matter what | |
2362 their arguments were. | |
2363 | |
2364 All of these routines install timeouts, so we clear the installed | |
2365 timeout as well. | |
2366 | |
2367 Note: It's very easy to break the desired behaviours of these | |
2368 3 routines. If you make any changes to anything in this area, run | |
2369 the regression tests at the bottom of the file. -- dmoore */ | |
2370 | |
2371 | |
2372 static Lisp_Object | |
2373 sit_for_unwind (Lisp_Object timeout_id) | |
2374 { | |
2375 if (!NILP(timeout_id)) | |
2376 Fdisable_timeout (timeout_id); | |
2377 | |
2378 recursive_sit_for = Qnil; | |
2379 return Qnil; | |
2380 } | |
2381 | |
2381 /* #### Is (accept-process-output nil 3) supposed to be like (sleep-for 3)? | 2382 /* #### Is (accept-process-output nil 3) supposed to be like (sleep-for 3)? |
2382 */ | 2383 */ |
2383 | 2384 |
2384 DEFUN ("accept-process-output", Faccept_process_output, 0, 3, 0, /* | 2385 DEFUN ("accept-process-output", Faccept_process_output, 0, 3, 0, /* |
2385 Allow any pending output from subprocesses to be read by Emacs. | 2386 Allow any pending output from subprocesses to be read by Emacs. |
2392 from PROCESS. This argument may be a float, meaning wait some fractional | 2393 from PROCESS. This argument may be a float, meaning wait some fractional |
2393 part of a second. | 2394 part of a second. |
2394 If the third arg is non-nil, it is a number of milliseconds that is added | 2395 If the third arg is non-nil, it is a number of milliseconds that is added |
2395 to the second arg. (This exists only for compatibility.) | 2396 to the second arg. (This exists only for compatibility.) |
2396 Return non-nil iff we received any output before the timeout expired. | 2397 Return non-nil iff we received any output before the timeout expired. |
2398 | |
2399 If a filter function or timeout handler (such as installed by `add-timeout') | |
2400 calls any of accept-process-output, sleep-for, or sit-for, those calls | |
2401 will return nil immediately (regardless of their arguments) in recursive | |
2402 situations. It is recommended that you never call accept-process-output | |
2403 from inside of a process filter function or timer event (either synchronous | |
2404 or asynchronous). | |
2397 */ | 2405 */ |
2398 (process, timeout_secs, timeout_msecs)) | 2406 (process, timeout_secs, timeout_msecs)) |
2399 { | 2407 { |
2400 /* This function can GC */ | 2408 /* This function can GC */ |
2401 struct gcpro gcpro1, gcpro2; | 2409 struct gcpro gcpro1, gcpro2; |
2403 Lisp_Object result = Qnil; | 2411 Lisp_Object result = Qnil; |
2404 int timeout_id; | 2412 int timeout_id; |
2405 int timeout_enabled = 0; | 2413 int timeout_enabled = 0; |
2406 int done = 0; | 2414 int done = 0; |
2407 struct buffer *old_buffer = current_buffer; | 2415 struct buffer *old_buffer = current_buffer; |
2416 int count; | |
2417 | |
2418 /* Recusive call from a filter function or timeout handler. */ | |
2419 if (!NILP(recursive_sit_for)) | |
2420 return Qnil; | |
2408 | 2421 |
2409 /* We preserve the current buffer but nothing else. If a focus | 2422 /* We preserve the current buffer but nothing else. If a focus |
2410 change alters the selected window then the top level event loop | 2423 change alters the selected window then the top level event loop |
2411 will eventually alter current_buffer to match. In the mean time | 2424 will eventually alter current_buffer to match. In the mean time |
2412 we don't want to mess up whatever called this function. */ | 2425 we don't want to mess up whatever called this function. */ |
2433 } | 2446 } |
2434 } | 2447 } |
2435 | 2448 |
2436 event = Fmake_event (); | 2449 event = Fmake_event (); |
2437 | 2450 |
2451 count = specpdl_depth (); | |
2452 record_unwind_protect (sit_for_unwind, | |
2453 timeout_enabled ? make_int (timeout_id) : Qnil); | |
2454 recursive_sit_for = Qt; | |
2455 | |
2438 while (!done && | 2456 while (!done && |
2439 ((NILP (process) && timeout_enabled) || | 2457 ((NILP (process) && timeout_enabled) || |
2440 (NILP (process) && event_stream_event_pending_p (0)) || | 2458 (NILP (process) && event_stream_event_pending_p (0)) || |
2441 (!NILP (process)))) | 2459 (!NILP (process)))) |
2442 /* Calling detect_input_pending() is the wrong thing here, because | 2460 /* Calling detect_input_pending() is the wrong thing here, because |
2465 QUIT; /* next_event_internal() does not QUIT, so check for ^G | 2483 QUIT; /* next_event_internal() does not QUIT, so check for ^G |
2466 before reading output from the process - this makes it | 2484 before reading output from the process - this makes it |
2467 less likely that the filter will actually be aborted. | 2485 less likely that the filter will actually be aborted. |
2468 */ | 2486 */ |
2469 | 2487 |
2470 next_event_internal (event, 0, 1); | 2488 next_event_internal (event, 0); |
2471 /* If C-g was pressed while we were waiting, Vquit_flag got | 2489 /* If C-g was pressed while we were waiting, Vquit_flag got |
2472 set and next_event_internal() also returns C-g. When | 2490 set and next_event_internal() also returns C-g. When |
2473 we enqueue the C-g below, it will get discarded. The | 2491 we enqueue the C-g below, it will get discarded. The |
2474 next time through, QUIT will be called and will signal a quit. */ | 2492 next time through, QUIT will be called and will signal a quit. */ |
2475 switch (XEVENT_TYPE (event)) | 2493 switch (XEVENT_TYPE (event)) |
2504 break; | 2522 break; |
2505 } | 2523 } |
2506 } | 2524 } |
2507 } | 2525 } |
2508 | 2526 |
2509 /* If our timeout has not been signalled yet, disable it. */ | 2527 unbind_to (count, timeout_enabled ? make_int (timeout_id) : Qnil); |
2510 if (timeout_enabled) | |
2511 event_stream_disable_wakeup (timeout_id, 0); | |
2512 | 2528 |
2513 Fdeallocate_event (event); | 2529 Fdeallocate_event (event); |
2514 UNGCPRO; | 2530 UNGCPRO; |
2515 current_buffer = old_buffer; | 2531 current_buffer = old_buffer; |
2516 return result; | 2532 return result; |
2517 } | 2533 } |
2518 | 2534 |
2519 DEFUN ("sleep-for", Fsleep_for, 1, 1, 0, /* | 2535 DEFUN ("sleep-for", Fsleep_for, 1, 1, 0, /* |
2520 Pause, without updating display, for ARG seconds. | 2536 Pause, without updating display, for ARG seconds. |
2521 ARG may be a float, meaning pause for some fractional part of a second. | 2537 ARG may be a float, meaning pause for some fractional part of a second. |
2538 | |
2539 If a filter function or timeout handler (such as installed by `add-timeout') | |
2540 calls any of accept-process-output, sleep-for, or sit-for, those calls | |
2541 will return nil immediately (regardless of their arguments) in recursive | |
2542 situations. It is recommended that you never call sleep-for from inside | |
2543 of a process filter function or timer event (either synchronous or | |
2544 asynchronous). | |
2522 */ | 2545 */ |
2523 (seconds)) | 2546 (seconds)) |
2524 { | 2547 { |
2525 /* This function can GC */ | 2548 /* This function can GC */ |
2526 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1); | 2549 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1); |
2527 int id; | 2550 int id; |
2528 Lisp_Object event = Qnil; | 2551 Lisp_Object event = Qnil; |
2552 int count; | |
2529 struct gcpro gcpro1; | 2553 struct gcpro gcpro1; |
2554 | |
2555 /* Recusive call from a filter function or timeout handler. */ | |
2556 if (!NILP(recursive_sit_for)) | |
2557 return Qnil; | |
2530 | 2558 |
2531 GCPRO1 (event); | 2559 GCPRO1 (event); |
2532 | 2560 |
2533 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0); | 2561 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0); |
2534 event = Fmake_event (); | 2562 event = Fmake_event (); |
2563 | |
2564 count = specpdl_depth (); | |
2565 record_unwind_protect (sit_for_unwind, make_int (id)); | |
2566 recursive_sit_for = Qt; | |
2567 | |
2535 while (1) | 2568 while (1) |
2536 { | 2569 { |
2537 /* If our timeout has arrived, we move along. */ | 2570 /* If our timeout has arrived, we move along. */ |
2538 if (!event_stream_wakeup_pending_p (id, 0)) | 2571 if (!event_stream_wakeup_pending_p (id, 0)) |
2539 goto DONE_LABEL; | 2572 goto DONE_LABEL; |
2544 */ | 2577 */ |
2545 /* We're a generator of the command_event_queue, so we can't be a | 2578 /* We're a generator of the command_event_queue, so we can't be a |
2546 consumer as well. We don't care about command and eval-events | 2579 consumer as well. We don't care about command and eval-events |
2547 anyway. | 2580 anyway. |
2548 */ | 2581 */ |
2549 next_event_internal (event, 0, 0); /* blocks */ | 2582 next_event_internal (event, 0); /* blocks */ |
2550 /* See the comment in accept-process-output about Vquit_flag */ | 2583 /* See the comment in accept-process-output about Vquit_flag */ |
2551 switch (XEVENT_TYPE (event)) | 2584 switch (XEVENT_TYPE (event)) |
2552 { | 2585 { |
2553 case process_event: | |
2554 { | |
2555 /* Avoid calling filter functions recursively by squirreling | |
2556 away process events */ | |
2557 enqueue_process_event (Fcopy_event (event, Qnil)); | |
2558 goto DONE_LABEL; | |
2559 } | |
2560 | |
2561 case timeout_event: | 2586 case timeout_event: |
2562 /* We execute the event even if it's ours, and notice that it's | 2587 /* We execute the event even if it's ours, and notice that it's |
2563 happened above. */ | 2588 happened above. */ |
2589 case process_event: | |
2564 case pointer_motion_event: | 2590 case pointer_motion_event: |
2565 case magic_event: | 2591 case magic_event: |
2566 { | 2592 { |
2567 EXECUTE_INTERNAL: | 2593 EXECUTE_INTERNAL: |
2568 execute_internal_event (event); | 2594 execute_internal_event (event); |
2574 break; | 2600 break; |
2575 } | 2601 } |
2576 } | 2602 } |
2577 } | 2603 } |
2578 DONE_LABEL: | 2604 DONE_LABEL: |
2605 unbind_to (count, make_int (id)); | |
2579 Fdeallocate_event (event); | 2606 Fdeallocate_event (event); |
2580 UNGCPRO; | 2607 UNGCPRO; |
2581 return Qnil; | 2608 return Qnil; |
2582 } | 2609 } |
2583 | 2610 |
2584 DEFUN ("sit-for", Fsit_for, 1, 2, 0, /* | 2611 DEFUN ("sit-for", Fsit_for, 1, 2, 0, /* |
2585 Perform redisplay, then wait ARG seconds or until user input is available. | 2612 Perform redisplay, then wait ARG seconds or until user input is available. |
2586 ARG may be a float, meaning a fractional part of a second. | 2613 ARG may be a float, meaning a fractional part of a second. |
2587 Optional second arg non-nil means don't redisplay, just wait for input. | 2614 Optional second arg non-nil means don't redisplay, just wait for input. |
2588 Redisplay is preempted as always if user input arrives, and does not | 2615 Redisplay is preempted as always if user input arrives, and does not |
2589 happen if input is available before it starts. | 2616 happen if input is available before it starts. |
2590 Value is t if waited the full time with no input arriving. | 2617 Value is t if waited the full time with no input arriving. |
2618 | |
2619 If a filter function or timeout handler (such as installed by `add-timeout') | |
2620 calls any of accept-process-output, sleep-for, or sit-for, those calls | |
2621 will return nil immediately (regardless of their arguments) in recursive | |
2622 situations. It is recommended that you never call sit-for from inside | |
2623 of a process filter function or timer event (either synchronous or | |
2624 asynchronous) with an argument other than 0. | |
2591 */ | 2625 */ |
2592 (seconds, nodisplay)) | 2626 (seconds, nodisplay)) |
2593 { | 2627 { |
2594 /* This function can GC */ | 2628 /* This function can GC */ |
2595 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1); | 2629 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1); |
2596 Lisp_Object event, result; | 2630 Lisp_Object event, result; |
2597 struct gcpro gcpro1; | 2631 struct gcpro gcpro1; |
2598 int id; | 2632 int id; |
2633 int count; | |
2634 | |
2635 /* Recusive call from a filter function or timeout handler. */ | |
2636 if (!NILP(recursive_sit_for)) | |
2637 return Qnil; | |
2599 | 2638 |
2600 /* The unread-command-events count as pending input */ | 2639 /* The unread-command-events count as pending input */ |
2601 if (!NILP (Vunread_command_events) || !NILP (Vunread_command_event)) | 2640 if (!NILP (Vunread_command_events) || !NILP (Vunread_command_event)) |
2602 return Qnil; | 2641 return Qnil; |
2603 | 2642 |
2620 | 2659 |
2621 /* Otherwise, start reading events from the event_stream. | 2660 /* Otherwise, start reading events from the event_stream. |
2622 Do this loop at least once even if (sit-for 0) so that we | 2661 Do this loop at least once even if (sit-for 0) so that we |
2623 redisplay when no input pending. | 2662 redisplay when no input pending. |
2624 */ | 2663 */ |
2664 GCPRO1 (event); | |
2625 event = Fmake_event (); | 2665 event = Fmake_event (); |
2626 GCPRO1 (event); | |
2627 | 2666 |
2628 /* Generate the wakeup even if MSECS is 0, so that existing timeout/etc. | 2667 /* Generate the wakeup even if MSECS is 0, so that existing timeout/etc. |
2629 events get processed. The old (pre-19.12) code special-cased this | 2668 events get processed. The old (pre-19.12) code special-cased this |
2630 and didn't generate a wakeup, but the resulting behavior was less than | 2669 and didn't generate a wakeup, but the resulting behavior was less than |
2631 ideal; viz. the occurrence of (sit-for 0.001) scattered throughout | 2670 ideal; viz. the occurrence of (sit-for 0.001) scattered throughout |
2632 the E-Lisp universe. */ | 2671 the E-Lisp universe. */ |
2633 | 2672 |
2634 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0); | 2673 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0); |
2674 | |
2675 count = specpdl_depth (); | |
2676 record_unwind_protect (sit_for_unwind, make_int (id)); | |
2677 recursive_sit_for = Qt; | |
2635 | 2678 |
2636 while (1) | 2679 while (1) |
2637 { | 2680 { |
2638 /* If there is no user input pending, then redisplay. | 2681 /* If there is no user input pending, then redisplay. |
2639 */ | 2682 */ |
2656 */ | 2699 */ |
2657 /* We're a generator of the command_event_queue, so we can't be a | 2700 /* We're a generator of the command_event_queue, so we can't be a |
2658 consumer as well. In fact, we know there's nothing on the | 2701 consumer as well. In fact, we know there's nothing on the |
2659 command_event_queue that we didn't just put there. | 2702 command_event_queue that we didn't just put there. |
2660 */ | 2703 */ |
2661 next_event_internal (event, 0, 0); /* blocks */ | 2704 next_event_internal (event, 0); /* blocks */ |
2662 /* See the comment in accept-process-output about Vquit_flag */ | 2705 /* See the comment in accept-process-output about Vquit_flag */ |
2663 | 2706 |
2664 if (command_event_p (event)) | 2707 if (command_event_p (event)) |
2665 { | 2708 { |
2709 QUIT; /* If the command was C-g check it here | |
2710 so that we abort out of the sit-for, | |
2711 not the next command. sleep-for and | |
2712 accept-process-output continue looping | |
2713 so they check QUIT again implicitly.*/ | |
2666 result = Qnil; | 2714 result = Qnil; |
2667 goto DONE_LABEL; | 2715 goto DONE_LABEL; |
2668 } | 2716 } |
2669 switch (XEVENT_TYPE (event)) | 2717 switch (XEVENT_TYPE (event)) |
2670 { | 2718 { |
2672 { | 2720 { |
2673 /* eval-events get delayed until later. */ | 2721 /* eval-events get delayed until later. */ |
2674 enqueue_command_event (Fcopy_event (event, Qnil)); | 2722 enqueue_command_event (Fcopy_event (event, Qnil)); |
2675 break; | 2723 break; |
2676 } | 2724 } |
2677 | |
2678 case process_event: | |
2679 { | |
2680 /* Avoid recursive calls to process filters */ | |
2681 enqueue_process_event (Fcopy_event (event, Qnil)); | |
2682 break; | |
2683 } | |
2684 | 2725 |
2685 case timeout_event: | 2726 case timeout_event: |
2686 /* We execute the event even if it's ours, and notice that it's | 2727 /* We execute the event even if it's ours, and notice that it's |
2687 happened above. */ | 2728 happened above. */ |
2688 default: | 2729 default: |
2693 } | 2734 } |
2694 } | 2735 } |
2695 } | 2736 } |
2696 | 2737 |
2697 DONE_LABEL: | 2738 DONE_LABEL: |
2698 /* If our timeout has not been signalled yet, disable it. */ | 2739 unbind_to (count, make_int (id)); |
2699 if (NILP (result)) | |
2700 event_stream_disable_wakeup (id, 0); | |
2701 | 2740 |
2702 /* Put back the event (if any) that made Fsit_for() exit before the | 2741 /* Put back the event (if any) that made Fsit_for() exit before the |
2703 timeout. Note that it is being added to the back of the queue, which | 2742 timeout. Note that it is being added to the back of the queue, which |
2704 would be inappropriate if there were any user events on the queue | 2743 would be inappropriate if there were any user events on the queue |
2705 already: we would be misordering them. But we know that there are | 2744 already: we would be misordering them. But we know that there are |
2734 /* We're a generator of the command_event_queue, so we can't be a | 2773 /* We're a generator of the command_event_queue, so we can't be a |
2735 consumer as well. Also, we have no reason to consult the | 2774 consumer as well. Also, we have no reason to consult the |
2736 command_event_queue; there are only user and eval-events there, | 2775 command_event_queue; there are only user and eval-events there, |
2737 and we'd just have to put them back anyway. | 2776 and we'd just have to put them back anyway. |
2738 */ | 2777 */ |
2739 next_event_internal (event, 0, 1); | 2778 next_event_internal (event, 0); |
2740 /* See the comment in accept-process-output about Vquit_flag */ | 2779 /* See the comment in accept-process-output about Vquit_flag */ |
2741 if (command_event_p (event) | 2780 if (command_event_p (event) |
2742 || (XEVENT_TYPE (event) == eval_event) | 2781 || (XEVENT_TYPE (event) == eval_event) |
2743 || (XEVENT_TYPE (event) == magic_eval_event)) | 2782 || (XEVENT_TYPE (event) == magic_eval_event)) |
2744 enqueue_command_event_1 (event); | 2783 enqueue_command_event_1 (event); |
4154 | 4193 |
4155 command_event_queue = Qnil; | 4194 command_event_queue = Qnil; |
4156 staticpro (&command_event_queue); | 4195 staticpro (&command_event_queue); |
4157 command_event_queue_tail = Qnil; | 4196 command_event_queue_tail = Qnil; |
4158 | 4197 |
4159 process_event_queue = Qnil; | |
4160 staticpro (&process_event_queue); | |
4161 process_event_queue_tail = Qnil; | |
4162 | |
4163 Vlast_selected_frame = Qnil; | 4198 Vlast_selected_frame = Qnil; |
4164 staticpro (&Vlast_selected_frame); | 4199 staticpro (&Vlast_selected_frame); |
4165 | 4200 |
4166 pending_timeout_list = Qnil; | 4201 pending_timeout_list = Qnil; |
4167 staticpro (&pending_timeout_list); | 4202 staticpro (&pending_timeout_list); |
4178 | 4213 |
4179 something_happened = 0; | 4214 something_happened = 0; |
4180 | 4215 |
4181 last_point_position_buffer = Qnil; | 4216 last_point_position_buffer = Qnil; |
4182 staticpro (&last_point_position_buffer); | 4217 staticpro (&last_point_position_buffer); |
4218 | |
4219 recursive_sit_for = Qnil; | |
4183 | 4220 |
4184 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes /* | 4221 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes /* |
4185 *Nonzero means echo unfinished commands after this many seconds of pause. | 4222 *Nonzero means echo unfinished commands after this many seconds of pause. |
4186 */ ); | 4223 */ ); |
4187 echo_keystrokes = 1; | 4224 echo_keystrokes = 1; |
4512 ;a should be inserted in foo. Cursor highlighting should not change in | 4549 ;a should be inserted in foo. Cursor highlighting should not change in |
4513 ;the meantime. | 4550 ;the meantime. |
4514 | 4551 |
4515 ;do it with sleep-for. move cursor into foo, then back into *scratch* | 4552 ;do it with sleep-for. move cursor into foo, then back into *scratch* |
4516 ;before typing. | 4553 ;before typing. |
4517 | 4554 ;repeat also with (accept-process-output nil 20) |
4518 ;make sure ^G aborts both sit-for and sleep-for. | 4555 |
4556 ;make sure ^G aborts sit-for, sleep-for and accept-process-output: | |
4519 | 4557 |
4520 (defun tst () | 4558 (defun tst () |
4521 (list (condition-case c | 4559 (list (condition-case c |
4522 (sleep-for 20) | 4560 (sleep-for 20) |
4523 (quit c)) | 4561 (quit c)) |
4524 (read-char))) | 4562 (read-char))) |
4525 | 4563 |
4526 (tst)^Ja^G ==> ((quit) 97) with no signal | 4564 (tst)^Ja^G ==> ((quit) 97) with no signal |
4527 (tst)^J^Ga ==> ((quit) 97) with no signal | 4565 (tst)^J^Ga ==> ((quit) 97) with no signal |
4528 (tst)^Jabc^G ==> ((quit) 97) with no signal, and "bc" inserted in buffer | 4566 (tst)^Jabc^G ==> ((quit) 97) with no signal, and "bc" inserted in buffer |
4567 | |
4568 ; with sit-for only do the 2nd test. | |
4569 ; Do all 3 tests with (accept-proccess-output nil 20) | |
4529 | 4570 |
4530 Do this: | 4571 Do this: |
4531 (setq enable-recursive-minibuffers t | 4572 (setq enable-recursive-minibuffers t |
4532 minibuffer-max-depth nil) | 4573 minibuffer-max-depth nil) |
4533 ESC ESC ESC ESC - there are now two minibuffers active | 4574 ESC ESC ESC ESC - there are now two minibuffers active |
4539 however C-g before "Quit" is displayed should leave minibuffer active. | 4580 however C-g before "Quit" is displayed should leave minibuffer active. |
4540 | 4581 |
4541 ;do it all in both v18 and v19 and make sure all results are the same. | 4582 ;do it all in both v18 and v19 and make sure all results are the same. |
4542 ;all of these cases matter a lot, but some in quite subtle ways. | 4583 ;all of these cases matter a lot, but some in quite subtle ways. |
4543 */ | 4584 */ |
4585 | |
4586 /* | |
4587 Additional test cases for accept-process-output, sleep-for, sit-for. | |
4588 Be sure you do all of the above checking for C-g and focus, too! | |
4589 | |
4590 ; Make sure that timer handlers are run during, not after sit-for: | |
4591 (defun timer-check () | |
4592 (add-timeout 2 '(lambda (ignore) (message "timer ran")) nil) | |
4593 (sit-for 5) | |
4594 (message "after sit-for")) | |
4595 | |
4596 ; The first message should appear after 2 seconds, and the final message | |
4597 ; 3 seconds after that. | |
4598 ; repeat above test with (sleep-for 5) and (accept-process-output nil 5) | |
4599 | |
4600 | |
4601 | |
4602 ; Make sure that process filters are run during, not after sit-for. | |
4603 (defun fubar () | |
4604 (message "sit-for = %s" (sit-for 30))) | |
4605 (add-hook 'post-command-hook 'fubar) | |
4606 | |
4607 ; Now type M-x shell RET | |
4608 ; wait for the shell prompt then send: ls RET | |
4609 ; the output of ls should fill immediately, and not wait 30 seconds. | |
4610 | |
4611 ; repeat above test with (sleep-for 30) and (accept-process-output nil 30) | |
4612 | |
4613 | |
4614 | |
4615 ; Make sure that recursive invocations return immediately: | |
4616 (defmacro test-diff-time (start end) | |
4617 `(+ (* (- (car ,end) (car ,start)) 65536.0) | |
4618 (- (cadr ,end) (cadr ,start)) | |
4619 (/ (- (caddr ,end) (caddr ,start)) 1000000.0))) | |
4620 | |
4621 (defun testee (ignore) | |
4622 ;; All three of these should return immediately. | |
4623 (sit-for 10) | |
4624 (sleep-for 10) | |
4625 (accept-process-output nil 10)) | |
4626 | |
4627 (defun test-them () | |
4628 (let ((start (current-time)) | |
4629 end) | |
4630 (add-timeout 2 'testee nil) | |
4631 (sit-for 5) | |
4632 (add-timeout 2 'testee nil) | |
4633 (sleep-for 5) | |
4634 (add-timeout 2 'testee nil) | |
4635 (accept-process-output nil 5) | |
4636 (setq end (current-time)) | |
4637 (test-diff-time start end))) | |
4638 | |
4639 (test-them) should sit for 15 seconds, not 105 or 96. | |
4640 | |
4641 | |
4642 */ |