diff options
| author | Mattias EngdegÄrd | 2025-07-29 16:29:43 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2025-07-30 11:04:11 +0200 |
| commit | 2d18878b962e3591fe5052ede88e520f9b861dda (patch) | |
| tree | a6e6ce1dbf506ab3bdffaec3038088901d3057d5 /src | |
| parent | 5a9cbf24ec94fc1134905db77d754f064efc7726 (diff) | |
| download | emacs-2d18878b962e3591fe5052ede88e520f9b861dda.tar.gz emacs-2d18878b962e3591fe5052ede88e520f9b861dda.zip | |
Move keyboard input functions from lread.c to keyboard.c
These have nothing to do with the Lisp reader at all.
Suggested by Lynn Winebarger (bug#79035).
* src/lread.c (read_filtered_event, Fread_char, Fread_event)
(Fread_char_exclusive, Qascii_character): Move...
* src/keyboard.c: ...here.
* test/src/lread-tests.el (test-inhibit-interaction): Move...
* test/src/keyboard-tests.el (keyboard-inhibit-interaction): ...here.
Diffstat (limited to 'src')
| -rw-r--r-- | src/keyboard.c | 270 | ||||
| -rw-r--r-- | src/lread.c | 270 |
2 files changed, 270 insertions, 270 deletions
diff --git a/src/keyboard.c b/src/keyboard.c index b389d98feaa..5feb0fe231e 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -10495,6 +10495,271 @@ void init_raw_keybuf_count (void) | |||
| 10495 | } | 10495 | } |
| 10496 | 10496 | ||
| 10497 | 10497 | ||
| 10498 | /* Get a character from the tty. */ | ||
| 10499 | |||
| 10500 | /* Read input events until we get one that's acceptable for our purposes. | ||
| 10501 | |||
| 10502 | If NO_SWITCH_FRAME, switch-frame events are stashed | ||
| 10503 | until we get a character we like, and then stuffed into | ||
| 10504 | unread_switch_frame. | ||
| 10505 | |||
| 10506 | If ASCII_REQUIRED, check function key events to see | ||
| 10507 | if the unmodified version of the symbol has a Qascii_character | ||
| 10508 | property, and use that character, if present. | ||
| 10509 | |||
| 10510 | If ERROR_NONASCII, signal an error if the input we | ||
| 10511 | get isn't an ASCII character with modifiers. If it's false but | ||
| 10512 | ASCII_REQUIRED is true, just re-read until we get an ASCII | ||
| 10513 | character. | ||
| 10514 | |||
| 10515 | If INPUT_METHOD, invoke the current input method | ||
| 10516 | if the character warrants that. | ||
| 10517 | |||
| 10518 | If SECONDS is a number, wait that many seconds for input, and | ||
| 10519 | return Qnil if no input arrives within that time. | ||
| 10520 | |||
| 10521 | If text conversion is enabled and ASCII_REQUIRED, temporarily | ||
| 10522 | disable any input method which wants to perform edits, unless | ||
| 10523 | `disable-inhibit-text-conversion'. */ | ||
| 10524 | |||
| 10525 | static Lisp_Object | ||
| 10526 | read_filtered_event (bool no_switch_frame, bool ascii_required, | ||
| 10527 | bool error_nonascii, bool input_method, Lisp_Object seconds) | ||
| 10528 | { | ||
| 10529 | Lisp_Object val, delayed_switch_frame; | ||
| 10530 | struct timespec end_time; | ||
| 10531 | #ifdef HAVE_TEXT_CONVERSION | ||
| 10532 | specpdl_ref count; | ||
| 10533 | #endif | ||
| 10534 | |||
| 10535 | #ifdef HAVE_WINDOW_SYSTEM | ||
| 10536 | if (display_hourglass_p) | ||
| 10537 | cancel_hourglass (); | ||
| 10538 | #endif | ||
| 10539 | |||
| 10540 | #ifdef HAVE_TEXT_CONVERSION | ||
| 10541 | count = SPECPDL_INDEX (); | ||
| 10542 | |||
| 10543 | /* Don't use text conversion when trying to just read a | ||
| 10544 | character. */ | ||
| 10545 | |||
| 10546 | if (ascii_required && !disable_inhibit_text_conversion) | ||
| 10547 | { | ||
| 10548 | disable_text_conversion (); | ||
| 10549 | record_unwind_protect_void (resume_text_conversion); | ||
| 10550 | } | ||
| 10551 | #endif | ||
| 10552 | |||
| 10553 | delayed_switch_frame = Qnil; | ||
| 10554 | |||
| 10555 | /* Compute timeout. */ | ||
| 10556 | if (NUMBERP (seconds)) | ||
| 10557 | { | ||
| 10558 | double duration = XFLOATINT (seconds); | ||
| 10559 | struct timespec wait_time = dtotimespec (duration); | ||
| 10560 | end_time = timespec_add (current_timespec (), wait_time); | ||
| 10561 | } | ||
| 10562 | |||
| 10563 | /* Read until we get an acceptable event. */ | ||
| 10564 | retry: | ||
| 10565 | do | ||
| 10566 | val = read_char (0, Qnil, (input_method ? Qnil : Qt), 0, | ||
| 10567 | NUMBERP (seconds) ? &end_time : NULL); | ||
| 10568 | while (FIXNUMP (val) && XFIXNUM (val) == -2); /* wrong_kboard_jmpbuf */ | ||
| 10569 | |||
| 10570 | if (BUFFERP (val)) | ||
| 10571 | goto retry; | ||
| 10572 | |||
| 10573 | /* `switch-frame' events are put off until after the next ASCII | ||
| 10574 | character. This is better than signaling an error just because | ||
| 10575 | the last characters were typed to a separate minibuffer frame, | ||
| 10576 | for example. Eventually, some code which can deal with | ||
| 10577 | switch-frame events will read it and process it. */ | ||
| 10578 | if (no_switch_frame | ||
| 10579 | && EVENT_HAS_PARAMETERS (val) | ||
| 10580 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (val)), Qswitch_frame)) | ||
| 10581 | { | ||
| 10582 | delayed_switch_frame = val; | ||
| 10583 | goto retry; | ||
| 10584 | } | ||
| 10585 | |||
| 10586 | if (ascii_required && !(NUMBERP (seconds) && NILP (val))) | ||
| 10587 | { | ||
| 10588 | /* Convert certain symbols to their ASCII equivalents. */ | ||
| 10589 | if (SYMBOLP (val)) | ||
| 10590 | { | ||
| 10591 | Lisp_Object tem, tem1; | ||
| 10592 | tem = Fget (val, Qevent_symbol_element_mask); | ||
| 10593 | if (!NILP (tem)) | ||
| 10594 | { | ||
| 10595 | tem1 = Fget (Fcar (tem), Qascii_character); | ||
| 10596 | /* Merge this symbol's modifier bits | ||
| 10597 | with the ASCII equivalent of its basic code. */ | ||
| 10598 | if (FIXNUMP (tem1) && FIXNUMP (Fcar (Fcdr (tem)))) | ||
| 10599 | XSETFASTINT (val, XFIXNUM (tem1) | XFIXNUM (Fcar (Fcdr (tem)))); | ||
| 10600 | } | ||
| 10601 | } | ||
| 10602 | |||
| 10603 | /* If we don't have a character now, deal with it appropriately. */ | ||
| 10604 | if (!FIXNUMP (val)) | ||
| 10605 | { | ||
| 10606 | if (error_nonascii) | ||
| 10607 | { | ||
| 10608 | Vunread_command_events = list1 (val); | ||
| 10609 | error ("Non-character input-event"); | ||
| 10610 | } | ||
| 10611 | else | ||
| 10612 | goto retry; | ||
| 10613 | } | ||
| 10614 | } | ||
| 10615 | |||
| 10616 | if (! NILP (delayed_switch_frame)) | ||
| 10617 | unread_switch_frame = delayed_switch_frame; | ||
| 10618 | |||
| 10619 | #if 0 | ||
| 10620 | |||
| 10621 | #ifdef HAVE_WINDOW_SYSTEM | ||
| 10622 | if (display_hourglass_p) | ||
| 10623 | start_hourglass (); | ||
| 10624 | #endif | ||
| 10625 | |||
| 10626 | #endif | ||
| 10627 | |||
| 10628 | #ifdef HAVE_TEXT_CONVERSION | ||
| 10629 | return unbind_to (count, val); | ||
| 10630 | #else | ||
| 10631 | return val; | ||
| 10632 | #endif | ||
| 10633 | } | ||
| 10634 | |||
| 10635 | DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0, | ||
| 10636 | doc: /* Read a character event from the command input (keyboard or macro). | ||
| 10637 | Return the character as a number. | ||
| 10638 | If the event has modifiers, they are resolved and reflected in the | ||
| 10639 | returned character code if possible (e.g. C-SPC yields 0 and C-a yields 97). | ||
| 10640 | If some of the modifiers cannot be reflected in the character code, the | ||
| 10641 | returned value will include those modifiers, and will not be a valid | ||
| 10642 | character code: it will fail the `characterp' test. Use `event-basic-type' | ||
| 10643 | to recover the character code with the modifiers removed. | ||
| 10644 | |||
| 10645 | If the user generates an event which is not a character (i.e. a mouse | ||
| 10646 | click or function key event), `read-char' signals an error. As an | ||
| 10647 | exception, switch-frame events are put off until non-character events | ||
| 10648 | can be read. | ||
| 10649 | If you want to read non-character events, or ignore them, call | ||
| 10650 | `read-event' or `read-char-exclusive' instead. | ||
| 10651 | |||
| 10652 | If the optional argument PROMPT is non-nil, display that as a prompt. | ||
| 10653 | If PROMPT is nil or the string \"\", the key sequence/events that led | ||
| 10654 | to the current command is used as the prompt. | ||
| 10655 | |||
| 10656 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some | ||
| 10657 | input method is turned on in the current buffer, that input method | ||
| 10658 | is used for reading a character. | ||
| 10659 | |||
| 10660 | If the optional argument SECONDS is non-nil, it should be a number | ||
| 10661 | specifying the maximum number of seconds to wait for input. If no | ||
| 10662 | input arrives in that time, return nil. SECONDS may be a | ||
| 10663 | floating-point value. | ||
| 10664 | |||
| 10665 | If `inhibit-interaction' is non-nil, this function will signal an | ||
| 10666 | `inhibited-interaction' error. */) | ||
| 10667 | (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds) | ||
| 10668 | { | ||
| 10669 | Lisp_Object val; | ||
| 10670 | |||
| 10671 | barf_if_interaction_inhibited (); | ||
| 10672 | |||
| 10673 | if (! NILP (prompt)) | ||
| 10674 | { | ||
| 10675 | cancel_echoing (); | ||
| 10676 | message_with_string ("%s", prompt, 0); | ||
| 10677 | } | ||
| 10678 | val = read_filtered_event (1, 1, 1, ! NILP (inherit_input_method), seconds); | ||
| 10679 | |||
| 10680 | return (!FIXNUMP (val) ? Qnil | ||
| 10681 | : make_fixnum (char_resolve_modifier_mask (XFIXNUM (val)))); | ||
| 10682 | } | ||
| 10683 | |||
| 10684 | DEFUN ("read-event", Fread_event, Sread_event, 0, 3, 0, | ||
| 10685 | doc: /* Read and return an event object from the input stream. | ||
| 10686 | |||
| 10687 | If you want to read non-character events, consider calling `read-key' | ||
| 10688 | instead. `read-key' will decode events via `input-decode-map' that | ||
| 10689 | `read-event' will not. On a terminal this includes function keys such | ||
| 10690 | as <F7> and <RIGHT>, or mouse events generated by `xterm-mouse-mode'. | ||
| 10691 | |||
| 10692 | If the optional argument PROMPT is non-nil, display that as a prompt. | ||
| 10693 | If PROMPT is nil or the string \"\", the key sequence/events that led | ||
| 10694 | to the current command is used as the prompt. | ||
| 10695 | |||
| 10696 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some | ||
| 10697 | input method is turned on in the current buffer, that input method | ||
| 10698 | is used for reading a character. | ||
| 10699 | |||
| 10700 | If the optional argument SECONDS is non-nil, it should be a number | ||
| 10701 | specifying the maximum number of seconds to wait for input. If no | ||
| 10702 | input arrives in that time, return nil. SECONDS may be a | ||
| 10703 | floating-point value. | ||
| 10704 | |||
| 10705 | If `inhibit-interaction' is non-nil, this function will signal an | ||
| 10706 | `inhibited-interaction' error. */) | ||
| 10707 | (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds) | ||
| 10708 | { | ||
| 10709 | barf_if_interaction_inhibited (); | ||
| 10710 | |||
| 10711 | if (! NILP (prompt)) | ||
| 10712 | { | ||
| 10713 | cancel_echoing (); | ||
| 10714 | message_with_string ("%s", prompt, 0); | ||
| 10715 | } | ||
| 10716 | return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method), seconds); | ||
| 10717 | } | ||
| 10718 | |||
| 10719 | DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 3, 0, | ||
| 10720 | doc: /* Read a character event from the command input (keyboard or macro). | ||
| 10721 | Return the character as a number. Non-character events are ignored. | ||
| 10722 | If the event has modifiers, they are resolved and reflected in the | ||
| 10723 | returned character code if possible (e.g. C-SPC yields 0 and C-a yields 97). | ||
| 10724 | If some of the modifiers cannot be reflected in the character code, the | ||
| 10725 | returned value will include those modifiers, and will not be a valid | ||
| 10726 | character code: it will fail the `characterp' test. Use `event-basic-type' | ||
| 10727 | to recover the character code with the modifiers removed. | ||
| 10728 | |||
| 10729 | If the optional argument PROMPT is non-nil, display that as a prompt. | ||
| 10730 | If PROMPT is nil or the string \"\", the key sequence/events that led | ||
| 10731 | to the current command is used as the prompt. | ||
| 10732 | |||
| 10733 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some | ||
| 10734 | input method is turned on in the current buffer, that input method | ||
| 10735 | is used for reading a character. | ||
| 10736 | |||
| 10737 | If the optional argument SECONDS is non-nil, it should be a number | ||
| 10738 | specifying the maximum number of seconds to wait for input. If no | ||
| 10739 | input arrives in that time, return nil. SECONDS may be a | ||
| 10740 | floating-point value. | ||
| 10741 | |||
| 10742 | If `inhibit-interaction' is non-nil, this function will signal an | ||
| 10743 | `inhibited-interaction' error. */) | ||
| 10744 | (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds) | ||
| 10745 | { | ||
| 10746 | Lisp_Object val; | ||
| 10747 | |||
| 10748 | barf_if_interaction_inhibited (); | ||
| 10749 | |||
| 10750 | if (! NILP (prompt)) | ||
| 10751 | { | ||
| 10752 | cancel_echoing (); | ||
| 10753 | message_with_string ("%s", prompt, 0); | ||
| 10754 | } | ||
| 10755 | |||
| 10756 | val = read_filtered_event (1, 1, 0, ! NILP (inherit_input_method), seconds); | ||
| 10757 | |||
| 10758 | return (!FIXNUMP (val) ? Qnil | ||
| 10759 | : make_fixnum (char_resolve_modifier_mask (XFIXNUM (val)))); | ||
| 10760 | } | ||
| 10761 | |||
| 10762 | |||
| 10498 | 10763 | ||
| 10499 | #ifdef HAVE_TEXT_CONVERSION | 10764 | #ifdef HAVE_TEXT_CONVERSION |
| 10500 | 10765 | ||
| @@ -13376,6 +13641,10 @@ syms_of_keyboard (void) | |||
| 13376 | defsubr (&Sposn_at_point); | 13641 | defsubr (&Sposn_at_point); |
| 13377 | defsubr (&Sposn_at_x_y); | 13642 | defsubr (&Sposn_at_x_y); |
| 13378 | 13643 | ||
| 13644 | defsubr (&Sread_char); | ||
| 13645 | defsubr (&Sread_char_exclusive); | ||
| 13646 | defsubr (&Sread_event); | ||
| 13647 | |||
| 13379 | DEFVAR_LISP ("last-command-event", last_command_event, | 13648 | DEFVAR_LISP ("last-command-event", last_command_event, |
| 13380 | doc: /* Last input event of a key sequence that called a command. | 13649 | doc: /* Last input event of a key sequence that called a command. |
| 13381 | See Info node `(elisp)Command Loop Info'.*/); | 13650 | See Info node `(elisp)Command Loop Info'.*/); |
| @@ -14117,6 +14386,7 @@ function is called to remap that sequence. */); | |||
| 14117 | DEFSYM (Qsuspend_resume_hook, "suspend-resume-hook"); | 14386 | DEFSYM (Qsuspend_resume_hook, "suspend-resume-hook"); |
| 14118 | DEFSYM (Qcommand_error_default_function, "command-error-default-function"); | 14387 | DEFSYM (Qcommand_error_default_function, "command-error-default-function"); |
| 14119 | DEFSYM (Qsigusr2, "sigusr2"); | 14388 | DEFSYM (Qsigusr2, "sigusr2"); |
| 14389 | DEFSYM (Qascii_character, "ascii-character"); | ||
| 14120 | } | 14390 | } |
| 14121 | 14391 | ||
| 14122 | static void | 14392 | static void |
diff --git a/src/lread.c b/src/lread.c index 54b74b18782..b0b6cdee4f2 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -739,272 +739,6 @@ static Lisp_Object substitute_object_recurse (struct subst *, Lisp_Object); | |||
| 739 | static void substitute_in_interval (INTERVAL, void *); | 739 | static void substitute_in_interval (INTERVAL, void *); |
| 740 | 740 | ||
| 741 | 741 | ||
| 742 | /* Get a character from the tty. */ | ||
| 743 | |||
| 744 | /* Read input events until we get one that's acceptable for our purposes. | ||
| 745 | |||
| 746 | If NO_SWITCH_FRAME, switch-frame events are stashed | ||
| 747 | until we get a character we like, and then stuffed into | ||
| 748 | unread_switch_frame. | ||
| 749 | |||
| 750 | If ASCII_REQUIRED, check function key events to see | ||
| 751 | if the unmodified version of the symbol has a Qascii_character | ||
| 752 | property, and use that character, if present. | ||
| 753 | |||
| 754 | If ERROR_NONASCII, signal an error if the input we | ||
| 755 | get isn't an ASCII character with modifiers. If it's false but | ||
| 756 | ASCII_REQUIRED is true, just re-read until we get an ASCII | ||
| 757 | character. | ||
| 758 | |||
| 759 | If INPUT_METHOD, invoke the current input method | ||
| 760 | if the character warrants that. | ||
| 761 | |||
| 762 | If SECONDS is a number, wait that many seconds for input, and | ||
| 763 | return Qnil if no input arrives within that time. | ||
| 764 | |||
| 765 | If text conversion is enabled and ASCII_REQUIRED, temporarily | ||
| 766 | disable any input method which wants to perform edits, unless | ||
| 767 | `disable-inhibit-text-conversion'. */ | ||
| 768 | |||
| 769 | static Lisp_Object | ||
| 770 | read_filtered_event (bool no_switch_frame, bool ascii_required, | ||
| 771 | bool error_nonascii, bool input_method, Lisp_Object seconds) | ||
| 772 | { | ||
| 773 | Lisp_Object val, delayed_switch_frame; | ||
| 774 | struct timespec end_time; | ||
| 775 | #ifdef HAVE_TEXT_CONVERSION | ||
| 776 | specpdl_ref count; | ||
| 777 | #endif | ||
| 778 | |||
| 779 | #ifdef HAVE_WINDOW_SYSTEM | ||
| 780 | if (display_hourglass_p) | ||
| 781 | cancel_hourglass (); | ||
| 782 | #endif | ||
| 783 | |||
| 784 | #ifdef HAVE_TEXT_CONVERSION | ||
| 785 | count = SPECPDL_INDEX (); | ||
| 786 | |||
| 787 | /* Don't use text conversion when trying to just read a | ||
| 788 | character. */ | ||
| 789 | |||
| 790 | if (ascii_required && !disable_inhibit_text_conversion) | ||
| 791 | { | ||
| 792 | disable_text_conversion (); | ||
| 793 | record_unwind_protect_void (resume_text_conversion); | ||
| 794 | } | ||
| 795 | #endif | ||
| 796 | |||
| 797 | delayed_switch_frame = Qnil; | ||
| 798 | |||
| 799 | /* Compute timeout. */ | ||
| 800 | if (NUMBERP (seconds)) | ||
| 801 | { | ||
| 802 | double duration = XFLOATINT (seconds); | ||
| 803 | struct timespec wait_time = dtotimespec (duration); | ||
| 804 | end_time = timespec_add (current_timespec (), wait_time); | ||
| 805 | } | ||
| 806 | |||
| 807 | /* Read until we get an acceptable event. */ | ||
| 808 | retry: | ||
| 809 | do | ||
| 810 | val = read_char (0, Qnil, (input_method ? Qnil : Qt), 0, | ||
| 811 | NUMBERP (seconds) ? &end_time : NULL); | ||
| 812 | while (FIXNUMP (val) && XFIXNUM (val) == -2); /* wrong_kboard_jmpbuf */ | ||
| 813 | |||
| 814 | if (BUFFERP (val)) | ||
| 815 | goto retry; | ||
| 816 | |||
| 817 | /* `switch-frame' events are put off until after the next ASCII | ||
| 818 | character. This is better than signaling an error just because | ||
| 819 | the last characters were typed to a separate minibuffer frame, | ||
| 820 | for example. Eventually, some code which can deal with | ||
| 821 | switch-frame events will read it and process it. */ | ||
| 822 | if (no_switch_frame | ||
| 823 | && EVENT_HAS_PARAMETERS (val) | ||
| 824 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (val)), Qswitch_frame)) | ||
| 825 | { | ||
| 826 | delayed_switch_frame = val; | ||
| 827 | goto retry; | ||
| 828 | } | ||
| 829 | |||
| 830 | if (ascii_required && !(NUMBERP (seconds) && NILP (val))) | ||
| 831 | { | ||
| 832 | /* Convert certain symbols to their ASCII equivalents. */ | ||
| 833 | if (SYMBOLP (val)) | ||
| 834 | { | ||
| 835 | Lisp_Object tem, tem1; | ||
| 836 | tem = Fget (val, Qevent_symbol_element_mask); | ||
| 837 | if (!NILP (tem)) | ||
| 838 | { | ||
| 839 | tem1 = Fget (Fcar (tem), Qascii_character); | ||
| 840 | /* Merge this symbol's modifier bits | ||
| 841 | with the ASCII equivalent of its basic code. */ | ||
| 842 | if (FIXNUMP (tem1) && FIXNUMP (Fcar (Fcdr (tem)))) | ||
| 843 | XSETFASTINT (val, XFIXNUM (tem1) | XFIXNUM (Fcar (Fcdr (tem)))); | ||
| 844 | } | ||
| 845 | } | ||
| 846 | |||
| 847 | /* If we don't have a character now, deal with it appropriately. */ | ||
| 848 | if (!FIXNUMP (val)) | ||
| 849 | { | ||
| 850 | if (error_nonascii) | ||
| 851 | { | ||
| 852 | Vunread_command_events = list1 (val); | ||
| 853 | error ("Non-character input-event"); | ||
| 854 | } | ||
| 855 | else | ||
| 856 | goto retry; | ||
| 857 | } | ||
| 858 | } | ||
| 859 | |||
| 860 | if (! NILP (delayed_switch_frame)) | ||
| 861 | unread_switch_frame = delayed_switch_frame; | ||
| 862 | |||
| 863 | #if 0 | ||
| 864 | |||
| 865 | #ifdef HAVE_WINDOW_SYSTEM | ||
| 866 | if (display_hourglass_p) | ||
| 867 | start_hourglass (); | ||
| 868 | #endif | ||
| 869 | |||
| 870 | #endif | ||
| 871 | |||
| 872 | #ifdef HAVE_TEXT_CONVERSION | ||
| 873 | return unbind_to (count, val); | ||
| 874 | #else | ||
| 875 | return val; | ||
| 876 | #endif | ||
| 877 | } | ||
| 878 | |||
| 879 | DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0, | ||
| 880 | doc: /* Read a character event from the command input (keyboard or macro). | ||
| 881 | Return the character as a number. | ||
| 882 | If the event has modifiers, they are resolved and reflected in the | ||
| 883 | returned character code if possible (e.g. C-SPC yields 0 and C-a yields 97). | ||
| 884 | If some of the modifiers cannot be reflected in the character code, the | ||
| 885 | returned value will include those modifiers, and will not be a valid | ||
| 886 | character code: it will fail the `characterp' test. Use `event-basic-type' | ||
| 887 | to recover the character code with the modifiers removed. | ||
| 888 | |||
| 889 | If the user generates an event which is not a character (i.e. a mouse | ||
| 890 | click or function key event), `read-char' signals an error. As an | ||
| 891 | exception, switch-frame events are put off until non-character events | ||
| 892 | can be read. | ||
| 893 | If you want to read non-character events, or ignore them, call | ||
| 894 | `read-event' or `read-char-exclusive' instead. | ||
| 895 | |||
| 896 | If the optional argument PROMPT is non-nil, display that as a prompt. | ||
| 897 | If PROMPT is nil or the string \"\", the key sequence/events that led | ||
| 898 | to the current command is used as the prompt. | ||
| 899 | |||
| 900 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some | ||
| 901 | input method is turned on in the current buffer, that input method | ||
| 902 | is used for reading a character. | ||
| 903 | |||
| 904 | If the optional argument SECONDS is non-nil, it should be a number | ||
| 905 | specifying the maximum number of seconds to wait for input. If no | ||
| 906 | input arrives in that time, return nil. SECONDS may be a | ||
| 907 | floating-point value. | ||
| 908 | |||
| 909 | If `inhibit-interaction' is non-nil, this function will signal an | ||
| 910 | `inhibited-interaction' error. */) | ||
| 911 | (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds) | ||
| 912 | { | ||
| 913 | Lisp_Object val; | ||
| 914 | |||
| 915 | barf_if_interaction_inhibited (); | ||
| 916 | |||
| 917 | if (! NILP (prompt)) | ||
| 918 | { | ||
| 919 | cancel_echoing (); | ||
| 920 | message_with_string ("%s", prompt, 0); | ||
| 921 | } | ||
| 922 | val = read_filtered_event (1, 1, 1, ! NILP (inherit_input_method), seconds); | ||
| 923 | |||
| 924 | return (!FIXNUMP (val) ? Qnil | ||
| 925 | : make_fixnum (char_resolve_modifier_mask (XFIXNUM (val)))); | ||
| 926 | } | ||
| 927 | |||
| 928 | DEFUN ("read-event", Fread_event, Sread_event, 0, 3, 0, | ||
| 929 | doc: /* Read and return an event object from the input stream. | ||
| 930 | |||
| 931 | If you want to read non-character events, consider calling `read-key' | ||
| 932 | instead. `read-key' will decode events via `input-decode-map' that | ||
| 933 | `read-event' will not. On a terminal this includes function keys such | ||
| 934 | as <F7> and <RIGHT>, or mouse events generated by `xterm-mouse-mode'. | ||
| 935 | |||
| 936 | If the optional argument PROMPT is non-nil, display that as a prompt. | ||
| 937 | If PROMPT is nil or the string \"\", the key sequence/events that led | ||
| 938 | to the current command is used as the prompt. | ||
| 939 | |||
| 940 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some | ||
| 941 | input method is turned on in the current buffer, that input method | ||
| 942 | is used for reading a character. | ||
| 943 | |||
| 944 | If the optional argument SECONDS is non-nil, it should be a number | ||
| 945 | specifying the maximum number of seconds to wait for input. If no | ||
| 946 | input arrives in that time, return nil. SECONDS may be a | ||
| 947 | floating-point value. | ||
| 948 | |||
| 949 | If `inhibit-interaction' is non-nil, this function will signal an | ||
| 950 | `inhibited-interaction' error. */) | ||
| 951 | (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds) | ||
| 952 | { | ||
| 953 | barf_if_interaction_inhibited (); | ||
| 954 | |||
| 955 | if (! NILP (prompt)) | ||
| 956 | { | ||
| 957 | cancel_echoing (); | ||
| 958 | message_with_string ("%s", prompt, 0); | ||
| 959 | } | ||
| 960 | return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method), seconds); | ||
| 961 | } | ||
| 962 | |||
| 963 | DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 3, 0, | ||
| 964 | doc: /* Read a character event from the command input (keyboard or macro). | ||
| 965 | Return the character as a number. Non-character events are ignored. | ||
| 966 | If the event has modifiers, they are resolved and reflected in the | ||
| 967 | returned character code if possible (e.g. C-SPC yields 0 and C-a yields 97). | ||
| 968 | If some of the modifiers cannot be reflected in the character code, the | ||
| 969 | returned value will include those modifiers, and will not be a valid | ||
| 970 | character code: it will fail the `characterp' test. Use `event-basic-type' | ||
| 971 | to recover the character code with the modifiers removed. | ||
| 972 | |||
| 973 | If the optional argument PROMPT is non-nil, display that as a prompt. | ||
| 974 | If PROMPT is nil or the string \"\", the key sequence/events that led | ||
| 975 | to the current command is used as the prompt. | ||
| 976 | |||
| 977 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some | ||
| 978 | input method is turned on in the current buffer, that input method | ||
| 979 | is used for reading a character. | ||
| 980 | |||
| 981 | If the optional argument SECONDS is non-nil, it should be a number | ||
| 982 | specifying the maximum number of seconds to wait for input. If no | ||
| 983 | input arrives in that time, return nil. SECONDS may be a | ||
| 984 | floating-point value. | ||
| 985 | |||
| 986 | If `inhibit-interaction' is non-nil, this function will signal an | ||
| 987 | `inhibited-interaction' error. */) | ||
| 988 | (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds) | ||
| 989 | { | ||
| 990 | Lisp_Object val; | ||
| 991 | |||
| 992 | barf_if_interaction_inhibited (); | ||
| 993 | |||
| 994 | if (! NILP (prompt)) | ||
| 995 | { | ||
| 996 | cancel_echoing (); | ||
| 997 | message_with_string ("%s", prompt, 0); | ||
| 998 | } | ||
| 999 | |||
| 1000 | val = read_filtered_event (1, 1, 0, ! NILP (inherit_input_method), seconds); | ||
| 1001 | |||
| 1002 | return (!FIXNUMP (val) ? Qnil | ||
| 1003 | : make_fixnum (char_resolve_modifier_mask (XFIXNUM (val)))); | ||
| 1004 | } | ||
| 1005 | |||
| 1006 | |||
| 1007 | |||
| 1008 | typedef enum { | 742 | typedef enum { |
| 1009 | Cookie_None, /* no cookie */ | 743 | Cookie_None, /* no cookie */ |
| 1010 | Cookie_Dyn, /* explicit dynamic binding */ | 744 | Cookie_Dyn, /* explicit dynamic binding */ |
| @@ -5852,9 +5586,6 @@ syms_of_lread (void) | |||
| 5852 | defsubr (&Sload); | 5586 | defsubr (&Sload); |
| 5853 | defsubr (&Seval_buffer); | 5587 | defsubr (&Seval_buffer); |
| 5854 | defsubr (&Seval_region); | 5588 | defsubr (&Seval_region); |
| 5855 | defsubr (&Sread_char); | ||
| 5856 | defsubr (&Sread_char_exclusive); | ||
| 5857 | defsubr (&Sread_event); | ||
| 5858 | defsubr (&Smapatoms); | 5589 | defsubr (&Smapatoms); |
| 5859 | defsubr (&Slocate_file_internal); | 5590 | defsubr (&Slocate_file_internal); |
| 5860 | defsubr (&Sinternal__obarray_buckets); | 5591 | defsubr (&Sinternal__obarray_buckets); |
| @@ -6166,7 +5897,6 @@ will use instead of `load-path' to look for the file to load. */); | |||
| 6166 | #endif | 5897 | #endif |
| 6167 | 5898 | ||
| 6168 | DEFSYM (Qinhibit_file_name_operation, "inhibit-file-name-operation"); | 5899 | DEFSYM (Qinhibit_file_name_operation, "inhibit-file-name-operation"); |
| 6169 | DEFSYM (Qascii_character, "ascii-character"); | ||
| 6170 | DEFSYM (Qfunction, "function"); | 5900 | DEFSYM (Qfunction, "function"); |
| 6171 | DEFSYM (Qload, "load"); | 5901 | DEFSYM (Qload, "load"); |
| 6172 | DEFSYM (Qload_file_name, "load-file-name"); | 5902 | DEFSYM (Qload_file_name, "load-file-name"); |