aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lread.c72
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
460Lisp_Object 463Lisp_Object
461read_filtered_event (no_switch_frame, ascii_required, error_nonascii, 464read_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
541DEFUN ("read-char", Fread_char, Sread_char, 0, 2, 0, 559DEFUN ("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).
543It is returned as a number. 561It is returned as a number.
544If the user generates an event which is not a character (i.e. a mouse 562If 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
551If the optional argument PROMPT is non-nil, display that as a prompt. 569If the optional argument PROMPT is non-nil, display that as a prompt.
552If the optional argument INHERIT-INPUT-METHOD is non-nil and some 570If the optional argument INHERIT-INPUT-METHOD is non-nil and some
553input method is turned on in the current buffer, that input method 571input method is turned on in the current buffer, that input method
554is used for reading a character. */) 572is used for reading a character.
555 (prompt, inherit_input_method) 573If the optional argument SECONDS is non-nil, it should be a number
556 Lisp_Object prompt, inherit_input_method; 574specifying the maximum number of seconds to wait for input. If no
575input arrives in that time, return nil. SECONDS may be a
576floating-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
563DEFUN ("read-event", Fread_event, Sread_event, 0, 2, 0, 585DEFUN ("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.
565If the optional argument PROMPT is non-nil, display that as a prompt. 587If the optional argument PROMPT is non-nil, display that as a prompt.
566If the optional argument INHERIT-INPUT-METHOD is non-nil and some 588If the optional argument INHERIT-INPUT-METHOD is non-nil and some
567input method is turned on in the current buffer, that input method 589input method is turned on in the current buffer, that input method
568is used for reading a character. */) 590is used for reading a character.
569 (prompt, inherit_input_method) 591If the optional argument SECONDS is non-nil, it should be a number
570 Lisp_Object prompt, inherit_input_method; 592specifying the maximum number of seconds to wait for input. If no
593input arrives in that time, return nil. SECONDS may be a
594floating-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
577DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 2, 0, 603DEFUN ("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).
579It is returned as a number. Non-character events are ignored. 605It is returned as a number. Non-character events are ignored.
580 606
581If the optional argument PROMPT is non-nil, display that as a prompt. 607If the optional argument PROMPT is non-nil, display that as a prompt.
582If the optional argument INHERIT-INPUT-METHOD is non-nil and some 608If the optional argument INHERIT-INPUT-METHOD is non-nil and some
583input method is turned on in the current buffer, that input method 609input method is turned on in the current buffer, that input method
584is used for reading a character. */) 610is used for reading a character.
585 (prompt, inherit_input_method) 611If the optional argument SECONDS is non-nil, it should be a number
586 Lisp_Object prompt, inherit_input_method; 612specifying the maximum number of seconds to wait for input. If no
613input arrives in that time, return nil. SECONDS may be a
614floating-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
593DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0, 623DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0,