diff options
| author | Chong Yidong | 2006-07-26 18:13:49 +0000 |
|---|---|---|
| committer | Chong Yidong | 2006-07-26 18:13:49 +0000 |
| commit | 50e48299ca6ebd8b6b82fa86e1c7c95b29d85965 (patch) | |
| tree | 86ac39f42d6d539038665b202d42d92a5e75b0ff /src | |
| parent | 179f689c0ad607687b6d2d9a4bce58bf251aabcc (diff) | |
| download | emacs-50e48299ca6ebd8b6b82fa86e1c7c95b29d85965.tar.gz emacs-50e48299ca6ebd8b6b82fa86e1c7c95b29d85965.zip | |
* lread.c (read_filtered_event): New arg SECONDS to wait until.
(Fread_char, Fread_event, Fread_char_exclusive): New arg SECONDS.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lread.c | 72 |
1 files changed, 51 insertions, 21 deletions
diff --git a/src/lread.c b/src/lread.c index 88a70f691c3..8f82c13be6a 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -455,14 +455,19 @@ extern Lisp_Object read_char (); | |||
| 455 | character. | 455 | character. |
| 456 | 456 | ||
| 457 | If INPUT_METHOD is nonzero, we invoke the current input method | 457 | If INPUT_METHOD is nonzero, we invoke the current input method |
| 458 | if the character warrants that. */ | 458 | if the character warrants that. |
| 459 | |||
| 460 | If SECONDS is a number, we wait that many seconds for input, and | ||
| 461 | return Qnil if no input arrives within that time. */ | ||
| 459 | 462 | ||
| 460 | Lisp_Object | 463 | Lisp_Object |
| 461 | read_filtered_event (no_switch_frame, ascii_required, error_nonascii, | 464 | read_filtered_event (no_switch_frame, ascii_required, error_nonascii, |
| 462 | input_method) | 465 | input_method, seconds) |
| 463 | int no_switch_frame, ascii_required, error_nonascii, input_method; | 466 | int no_switch_frame, ascii_required, error_nonascii, input_method; |
| 467 | Lisp_Object seconds; | ||
| 464 | { | 468 | { |
| 465 | Lisp_Object val, delayed_switch_frame; | 469 | Lisp_Object val, delayed_switch_frame; |
| 470 | EMACS_TIME end_time; | ||
| 466 | 471 | ||
| 467 | #ifdef HAVE_WINDOW_SYSTEM | 472 | #ifdef HAVE_WINDOW_SYSTEM |
| 468 | if (display_hourglass_p) | 473 | if (display_hourglass_p) |
| @@ -471,11 +476,24 @@ read_filtered_event (no_switch_frame, ascii_required, error_nonascii, | |||
| 471 | 476 | ||
| 472 | delayed_switch_frame = Qnil; | 477 | delayed_switch_frame = Qnil; |
| 473 | 478 | ||
| 479 | /* Compute timeout. */ | ||
| 480 | if (NUMBERP (seconds)) | ||
| 481 | { | ||
| 482 | EMACS_TIME wait_time; | ||
| 483 | int sec, usec; | ||
| 484 | double duration = extract_float (seconds); | ||
| 485 | |||
| 486 | sec = (int) duration; | ||
| 487 | usec = (duration - sec) * 1000000; | ||
| 488 | EMACS_GET_TIME (end_time); | ||
| 489 | EMACS_SET_SECS_USECS (wait_time, sec, usec); | ||
| 490 | EMACS_ADD_TIME (end_time, end_time, wait_time); | ||
| 491 | } | ||
| 492 | |||
| 474 | /* Read until we get an acceptable event. */ | 493 | /* Read until we get an acceptable event. */ |
| 475 | retry: | 494 | retry: |
| 476 | val = read_char (0, 0, 0, | 495 | val = read_char (0, 0, 0, (input_method ? Qnil : Qt), 0, |
| 477 | (input_method ? Qnil : Qt), | 496 | NUMBERP (seconds) ? &end_time : NULL); |
| 478 | 0); | ||
| 479 | 497 | ||
| 480 | if (BUFFERP (val)) | 498 | if (BUFFERP (val)) |
| 481 | goto retry; | 499 | goto retry; |
| @@ -493,7 +511,7 @@ read_filtered_event (no_switch_frame, ascii_required, error_nonascii, | |||
| 493 | goto retry; | 511 | goto retry; |
| 494 | } | 512 | } |
| 495 | 513 | ||
| 496 | if (ascii_required) | 514 | if (ascii_required && !(NUMBERP (seconds) && NILP (val))) |
| 497 | { | 515 | { |
| 498 | /* Convert certain symbols to their ASCII equivalents. */ | 516 | /* Convert certain symbols to their ASCII equivalents. */ |
| 499 | if (SYMBOLP (val)) | 517 | if (SYMBOLP (val)) |
| @@ -538,7 +556,7 @@ read_filtered_event (no_switch_frame, ascii_required, error_nonascii, | |||
| 538 | return val; | 556 | return val; |
| 539 | } | 557 | } |
| 540 | 558 | ||
| 541 | DEFUN ("read-char", Fread_char, Sread_char, 0, 2, 0, | 559 | DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0, |
| 542 | doc: /* Read a character from the command input (keyboard or macro). | 560 | doc: /* Read a character from the command input (keyboard or macro). |
| 543 | It is returned as a number. | 561 | It is returned as a number. |
| 544 | If the user generates an event which is not a character (i.e. a mouse | 562 | If the user generates an event which is not a character (i.e. a mouse |
| @@ -551,43 +569,55 @@ If you want to read non-character events, or ignore them, call | |||
| 551 | If the optional argument PROMPT is non-nil, display that as a prompt. | 569 | If the optional argument PROMPT is non-nil, display that as a prompt. |
| 552 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some | 570 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some |
| 553 | input method is turned on in the current buffer, that input method | 571 | input method is turned on in the current buffer, that input method |
| 554 | is used for reading a character. */) | 572 | is used for reading a character. |
| 555 | (prompt, inherit_input_method) | 573 | If the optional argument SECONDS is non-nil, it should be a number |
| 556 | Lisp_Object prompt, inherit_input_method; | 574 | specifying the maximum number of seconds to wait for input. If no |
| 575 | input arrives in that time, return nil. SECONDS may be a | ||
| 576 | floating-point value. */) | ||
| 577 | (prompt, inherit_input_method, seconds) | ||
| 578 | Lisp_Object prompt, inherit_input_method, seconds; | ||
| 557 | { | 579 | { |
| 558 | if (! NILP (prompt)) | 580 | if (! NILP (prompt)) |
| 559 | message_with_string ("%s", prompt, 0); | 581 | message_with_string ("%s", prompt, 0); |
| 560 | return read_filtered_event (1, 1, 1, ! NILP (inherit_input_method)); | 582 | return read_filtered_event (1, 1, 1, ! NILP (inherit_input_method), seconds); |
| 561 | } | 583 | } |
| 562 | 584 | ||
| 563 | DEFUN ("read-event", Fread_event, Sread_event, 0, 2, 0, | 585 | DEFUN ("read-event", Fread_event, Sread_event, 0, 3, 0, |
| 564 | doc: /* Read an event object from the input stream. | 586 | doc: /* Read an event object from the input stream. |
| 565 | If the optional argument PROMPT is non-nil, display that as a prompt. | 587 | If the optional argument PROMPT is non-nil, display that as a prompt. |
| 566 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some | 588 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some |
| 567 | input method is turned on in the current buffer, that input method | 589 | input method is turned on in the current buffer, that input method |
| 568 | is used for reading a character. */) | 590 | is used for reading a character. |
| 569 | (prompt, inherit_input_method) | 591 | If the optional argument SECONDS is non-nil, it should be a number |
| 570 | Lisp_Object prompt, inherit_input_method; | 592 | specifying the maximum number of seconds to wait for input. If no |
| 593 | input arrives in that time, return nil. SECONDS may be a | ||
| 594 | floating-point value. */) | ||
| 595 | (prompt, inherit_input_method, seconds) | ||
| 596 | Lisp_Object prompt, inherit_input_method, seconds; | ||
| 571 | { | 597 | { |
| 572 | if (! NILP (prompt)) | 598 | if (! NILP (prompt)) |
| 573 | message_with_string ("%s", prompt, 0); | 599 | message_with_string ("%s", prompt, 0); |
| 574 | return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method)); | 600 | return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method), seconds); |
| 575 | } | 601 | } |
| 576 | 602 | ||
| 577 | DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 2, 0, | 603 | DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 3, 0, |
| 578 | doc: /* Read a character from the command input (keyboard or macro). | 604 | doc: /* Read a character from the command input (keyboard or macro). |
| 579 | It is returned as a number. Non-character events are ignored. | 605 | It is returned as a number. Non-character events are ignored. |
| 580 | 606 | ||
| 581 | If the optional argument PROMPT is non-nil, display that as a prompt. | 607 | If the optional argument PROMPT is non-nil, display that as a prompt. |
| 582 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some | 608 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some |
| 583 | input method is turned on in the current buffer, that input method | 609 | input method is turned on in the current buffer, that input method |
| 584 | is used for reading a character. */) | 610 | is used for reading a character. |
| 585 | (prompt, inherit_input_method) | 611 | If the optional argument SECONDS is non-nil, it should be a number |
| 586 | Lisp_Object prompt, inherit_input_method; | 612 | specifying the maximum number of seconds to wait for input. If no |
| 613 | input arrives in that time, return nil. SECONDS may be a | ||
| 614 | floating-point value. */) | ||
| 615 | (prompt, inherit_input_method, seconds) | ||
| 616 | Lisp_Object prompt, inherit_input_method, seconds; | ||
| 587 | { | 617 | { |
| 588 | if (! NILP (prompt)) | 618 | if (! NILP (prompt)) |
| 589 | message_with_string ("%s", prompt, 0); | 619 | message_with_string ("%s", prompt, 0); |
| 590 | return read_filtered_event (1, 1, 0, ! NILP (inherit_input_method)); | 620 | return read_filtered_event (1, 1, 0, ! NILP (inherit_input_method), seconds); |
| 591 | } | 621 | } |
| 592 | 622 | ||
| 593 | DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0, | 623 | DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0, |