Mercurial > hg > xemacs-beta
comparison src/event-stream.c @ 110:fe104dbd9147 r20-1b7
Import from CVS: tag r20-1b7
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:19:45 +0200 |
parents | 360340f9fd5f |
children | 9f59509498e1 |
comparison
equal
deleted
inserted
replaced
109:e183fc049578 | 110:fe104dbd9147 |
---|---|
2366 /**********************************************************************/ | 2366 /**********************************************************************/ |
2367 | 2367 |
2368 /* This is used in accept-process-output, sleep-for and sit-for. | 2368 /* This is used in accept-process-output, sleep-for and sit-for. |
2369 Before running any process_events in these routines, we set | 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 | 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 | 2371 Qnil upon exit. When recursive_sit_for is Qt, calling sit-for will |
2372 three routines will cause them to return immediately no matter what | 2372 cause it to return immediately. |
2373 their arguments were. | |
2374 | 2373 |
2375 All of these routines install timeouts, so we clear the installed | 2374 All of these routines install timeouts, so we clear the installed |
2376 timeout as well. | 2375 timeout as well. |
2377 | 2376 |
2378 Note: It's very easy to break the desired behaviours of these | 2377 Note: It's very easy to break the desired behaviours of these |
2404 from PROCESS. This argument may be a float, meaning wait some fractional | 2403 from PROCESS. This argument may be a float, meaning wait some fractional |
2405 part of a second. | 2404 part of a second. |
2406 If the third arg is non-nil, it is a number of milliseconds that is added | 2405 If the third arg is non-nil, it is a number of milliseconds that is added |
2407 to the second arg. (This exists only for compatibility.) | 2406 to the second arg. (This exists only for compatibility.) |
2408 Return non-nil iff we received any output before the timeout expired. | 2407 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). | |
2416 */ | 2408 */ |
2417 (process, timeout_secs, timeout_msecs)) | 2409 (process, timeout_secs, timeout_msecs)) |
2418 { | 2410 { |
2419 /* This function can GC */ | 2411 /* This function can GC */ |
2420 struct gcpro gcpro1, gcpro2; | 2412 struct gcpro gcpro1, gcpro2; |
2423 int timeout_id; | 2415 int timeout_id; |
2424 int timeout_enabled = 0; | 2416 int timeout_enabled = 0; |
2425 int done = 0; | 2417 int done = 0; |
2426 struct buffer *old_buffer = current_buffer; | 2418 struct buffer *old_buffer = current_buffer; |
2427 int count; | 2419 int count; |
2428 | |
2429 /* Recusive call from a filter function or timeout handler. */ | |
2430 if (!NILP(recursive_sit_for)) | |
2431 return Qnil; | |
2432 | 2420 |
2433 /* We preserve the current buffer but nothing else. If a focus | 2421 /* We preserve the current buffer but nothing else. If a focus |
2434 change alters the selected window then the top level event loop | 2422 change alters the selected window then the top level event loop |
2435 will eventually alter current_buffer to match. In the mean time | 2423 will eventually alter current_buffer to match. In the mean time |
2436 we don't want to mess up whatever called this function. */ | 2424 we don't want to mess up whatever called this function. */ |
2545 | 2533 |
2546 DEFUN ("sleep-for", Fsleep_for, 1, 1, 0, /* | 2534 DEFUN ("sleep-for", Fsleep_for, 1, 1, 0, /* |
2547 Pause, without updating display, for ARG seconds. | 2535 Pause, without updating display, for ARG seconds. |
2548 ARG may be a float, meaning pause for some fractional part of a second. | 2536 ARG may be a float, meaning pause for some fractional part of a second. |
2549 | 2537 |
2550 If a filter function or timeout handler (such as installed by `add-timeout') | 2538 It is recommended that you never call sleep-for from inside of a process |
2551 calls any of accept-process-output, sleep-for, or sit-for, those calls | 2539 filter function or timer event (either synchronous or asynchronous). |
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). | |
2556 */ | 2540 */ |
2557 (seconds)) | 2541 (seconds)) |
2558 { | 2542 { |
2559 /* This function can GC */ | 2543 /* This function can GC */ |
2560 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1); | 2544 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1); |
2561 int id; | 2545 int id; |
2562 Lisp_Object event = Qnil; | 2546 Lisp_Object event = Qnil; |
2563 int count; | 2547 int count; |
2564 struct gcpro gcpro1; | 2548 struct gcpro gcpro1; |
2565 | |
2566 /* Recusive call from a filter function or timeout handler. */ | |
2567 if (!NILP(recursive_sit_for)) | |
2568 return Qnil; | |
2569 | 2549 |
2570 GCPRO1 (event); | 2550 GCPRO1 (event); |
2571 | 2551 |
2572 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0); | 2552 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0); |
2573 event = Fmake_event (); | 2553 event = Fmake_event (); |
2625 Optional second arg non-nil means don't redisplay, just wait for input. | 2605 Optional second arg non-nil means don't redisplay, just wait for input. |
2626 Redisplay is preempted as always if user input arrives, and does not | 2606 Redisplay is preempted as always if user input arrives, and does not |
2627 happen if input is available before it starts. | 2607 happen if input is available before it starts. |
2628 Value is t if waited the full time with no input arriving. | 2608 Value is t if waited the full time with no input arriving. |
2629 | 2609 |
2630 If a filter function or timeout handler (such as installed by `add-timeout') | 2610 If sit-for is called from within a process filter function or timer |
2631 calls any of accept-process-output, sleep-for, or sit-for, those calls | 2611 event (either synchronous or asynchronous) it will return immediately. |
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. | |
2636 */ | 2612 */ |
2637 (seconds, nodisplay)) | 2613 (seconds, nodisplay)) |
2638 { | 2614 { |
2639 /* This function can GC */ | 2615 /* This function can GC */ |
2640 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1); | 2616 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1); |
2641 Lisp_Object event, result; | 2617 Lisp_Object event, result; |
2642 struct gcpro gcpro1; | 2618 struct gcpro gcpro1; |
2643 int id; | 2619 int id; |
2644 int count; | 2620 int count; |
2645 | 2621 |
2646 /* Recusive call from a filter function or timeout handler. */ | |
2647 if (!NILP(recursive_sit_for)) | |
2648 return Qnil; | |
2649 | |
2650 /* The unread-command-events count as pending input */ | 2622 /* The unread-command-events count as pending input */ |
2651 if (!NILP (Vunread_command_events) || !NILP (Vunread_command_event)) | 2623 if (!NILP (Vunread_command_events) || !NILP (Vunread_command_event)) |
2652 return Qnil; | 2624 return Qnil; |
2653 | 2625 |
2654 /* If the command-builder already has user-input on it (not eval events) | 2626 /* If the command-builder already has user-input on it (not eval events) |
2665 | 2637 |
2666 /* If we're in a macro, or noninteractive, or early in temacs, then | 2638 /* If we're in a macro, or noninteractive, or early in temacs, then |
2667 don't wait. */ | 2639 don't wait. */ |
2668 if (noninteractive || !NILP (Vexecuting_macro)) | 2640 if (noninteractive || !NILP (Vexecuting_macro)) |
2669 return (Qnil); | 2641 return (Qnil); |
2642 | |
2643 /* Recusive call from a filter function or timeout handler. */ | |
2644 if (!NILP(recursive_sit_for)) | |
2645 { | |
2646 if (!event_stream_event_pending_p (1) && NILP (nodisplay)) | |
2647 { | |
2648 run_pre_idle_hook (); | |
2649 redisplay (); | |
2650 } | |
2651 return Qnil; | |
2652 } | |
2653 | |
2670 | 2654 |
2671 /* Otherwise, start reading events from the event_stream. | 2655 /* Otherwise, start reading events from the event_stream. |
2672 Do this loop at least once even if (sit-for 0) so that we | 2656 Do this loop at least once even if (sit-for 0) so that we |
2673 redisplay when no input pending. | 2657 redisplay when no input pending. |
2674 */ | 2658 */ |
3280 -- We do not reset this-command-keys when we finish reading a | 3264 -- We do not reset this-command-keys when we finish reading a |
3281 command. This is because some commands (e.g. C-u) act | 3265 command. This is because some commands (e.g. C-u) act |
3282 like command prefixes; they signal this by setting prefix-arg | 3266 like command prefixes; they signal this by setting prefix-arg |
3283 to non-nil. | 3267 to non-nil. |
3284 -- Therefore, we reset this-command-keys when we finish | 3268 -- Therefore, we reset this-command-keys when we finish |
3285 executing a comand, unless prefix-arg is set. | 3269 executing a command, unless prefix-arg is set. |
3286 -- However, if we ever do a non-local exit out of a command | 3270 -- However, if we ever do a non-local exit out of a command |
3287 loop (e.g. an error in a command), we need to reset | 3271 loop (e.g. an error in a command), we need to reset |
3288 this-command-keys. We do this by calling reset_this_command_keys() | 3272 this-command-keys. We do this by calling reset_this_command_keys() |
3289 from cmdloop.c, whenever an error causes an invocation of the | 3273 from cmdloop.c, whenever an error causes an invocation of the |
3290 default error handler, and whenever there's a throw to top-level.) | 3274 default error handler, and whenever there's a throw to top-level.) |
3314 enqueue_event (new, &Vthis_command_keys, &Vthis_command_keys_tail); | 3298 enqueue_event (new, &Vthis_command_keys, &Vthis_command_keys_tail); |
3315 } | 3299 } |
3316 | 3300 |
3317 /* The following two functions are used in call-interactively, | 3301 /* The following two functions are used in call-interactively, |
3318 for the @ and e specifications. We used to just use | 3302 for the @ and e specifications. We used to just use |
3319 `current-mouse-event' (i.e. the last mouse event in this-comand-keys), | 3303 `current-mouse-event' (i.e. the last mouse event in this-command-keys), |
3320 but FSF does it more generally so we follow their lead. */ | 3304 but FSF does it more generally so we follow their lead. */ |
3321 | 3305 |
3322 Lisp_Object | 3306 Lisp_Object |
3323 extract_this_command_keys_nth_mouse_event (int n) | 3307 extract_this_command_keys_nth_mouse_event (int n) |
3324 { | 3308 { |
4655 `(+ (* (- (car ,end) (car ,start)) 65536.0) | 4639 `(+ (* (- (car ,end) (car ,start)) 65536.0) |
4656 (- (cadr ,end) (cadr ,start)) | 4640 (- (cadr ,end) (cadr ,start)) |
4657 (/ (- (caddr ,end) (caddr ,start)) 1000000.0))) | 4641 (/ (- (caddr ,end) (caddr ,start)) 1000000.0))) |
4658 | 4642 |
4659 (defun testee (ignore) | 4643 (defun testee (ignore) |
4660 ;; All three of these should return immediately. | 4644 (sit-for 10)) |
4661 (sit-for 10) | |
4662 (sleep-for 10) | |
4663 (accept-process-output nil 10)) | |
4664 | 4645 |
4665 (defun test-them () | 4646 (defun test-them () |
4666 (let ((start (current-time)) | 4647 (let ((start (current-time)) |
4667 end) | 4648 end) |
4668 (add-timeout 2 'testee nil) | 4649 (add-timeout 2 'testee nil) |
4672 (add-timeout 2 'testee nil) | 4653 (add-timeout 2 'testee nil) |
4673 (accept-process-output nil 5) | 4654 (accept-process-output nil 5) |
4674 (setq end (current-time)) | 4655 (setq end (current-time)) |
4675 (test-diff-time start end))) | 4656 (test-diff-time start end))) |
4676 | 4657 |
4677 (test-them) should sit for 15 seconds, not 105 or 96. | 4658 (test-them) should sit for 15 seconds. |
4678 | 4659 Repeat with testee set to sleep-for and accept-process-output. |
4660 These should each delay 36 seconds. | |
4679 | 4661 |
4680 */ | 4662 */ |