diff options
| author | Stefan Monnier | 2013-09-04 16:32:22 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2013-09-04 16:32:22 -0400 |
| commit | 6629638eb3d49be98cb9633d7b52d19acc0c5d18 (patch) | |
| tree | 345a1da8a16a01148070bbab09660139a7c70c45 /src | |
| parent | d99760fa44c45477afeaf46784742a2670423161 (diff) | |
| download | emacs-6629638eb3d49be98cb9633d7b52d19acc0c5d18.tar.gz emacs-6629638eb3d49be98cb9633d7b52d19acc0c5d18.zip | |
* src/keyboard.c (read_key_sequence_vs): New function.
(Fread_key_sequence_vector, Fread_key_sequence): Use it to factor out
common code.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 4 | ||||
| -rw-r--r-- | src/keyboard.c | 152 |
2 files changed, 64 insertions, 92 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index ffd6477aed3..e64d22b9a6e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,9 @@ | |||
| 1 | 2013-09-04 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2013-09-04 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * keyboard.c (read_key_sequence_vs): New function. | ||
| 4 | (Fread_key_sequence_vector, Fread_key_sequence): Use it to factor out | ||
| 5 | common code. | ||
| 6 | |||
| 3 | * callint.c (Fcall_interactively): Always return a vector for 'K'. | 7 | * callint.c (Fcall_interactively): Always return a vector for 'K'. |
| 4 | 8 | ||
| 5 | 2013-09-04 Paul Eggert <eggert@cs.ucla.edu> | 9 | 2013-09-04 Paul Eggert <eggert@cs.ucla.edu> |
diff --git a/src/keyboard.c b/src/keyboard.c index b8e05cf7925..bf7c44aeeda 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -9712,54 +9712,11 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, | |||
| 9712 | return t; | 9712 | return t; |
| 9713 | } | 9713 | } |
| 9714 | 9714 | ||
| 9715 | DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 5, 0, | 9715 | static Lisp_Object |
| 9716 | doc: /* Read a sequence of keystrokes and return as a string or vector. | 9716 | read_key_sequence_vs (Lisp_Object prompt, Lisp_Object continue_echo, |
| 9717 | The sequence is sufficient to specify a non-prefix command in the | 9717 | Lisp_Object dont_downcase_last, |
| 9718 | current local and global maps. | 9718 | Lisp_Object can_return_switch_frame, |
| 9719 | 9719 | Lisp_Object cmd_loop, bool allow_string) | |
| 9720 | First arg PROMPT is a prompt string. If nil, do not prompt specially. | ||
| 9721 | Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos | ||
| 9722 | as a continuation of the previous key. | ||
| 9723 | |||
| 9724 | The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not | ||
| 9725 | convert the last event to lower case. (Normally any upper case event | ||
| 9726 | is converted to lower case if the original event is undefined and the lower | ||
| 9727 | case equivalent is defined.) A non-nil value is appropriate for reading | ||
| 9728 | a key sequence to be defined. | ||
| 9729 | |||
| 9730 | A C-g typed while in this function is treated like any other character, | ||
| 9731 | and `quit-flag' is not set. | ||
| 9732 | |||
| 9733 | If the key sequence starts with a mouse click, then the sequence is read | ||
| 9734 | using the keymaps of the buffer of the window clicked in, not the buffer | ||
| 9735 | of the selected window as normal. | ||
| 9736 | |||
| 9737 | `read-key-sequence' drops unbound button-down events, since you normally | ||
| 9738 | only care about the click or drag events which follow them. If a drag | ||
| 9739 | or multi-click event is unbound, but the corresponding click event would | ||
| 9740 | be bound, `read-key-sequence' turns the event into a click event at the | ||
| 9741 | drag's starting position. This means that you don't have to distinguish | ||
| 9742 | between click and drag, double, or triple events unless you want to. | ||
| 9743 | |||
| 9744 | `read-key-sequence' prefixes mouse events on mode lines, the vertical | ||
| 9745 | lines separating windows, and scroll bars with imaginary keys | ||
| 9746 | `mode-line', `vertical-line', and `vertical-scroll-bar'. | ||
| 9747 | |||
| 9748 | Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this | ||
| 9749 | function will process a switch-frame event if the user switches frames | ||
| 9750 | before typing anything. If the user switches frames in the middle of a | ||
| 9751 | key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME | ||
| 9752 | is nil, then the event will be put off until after the current key sequence. | ||
| 9753 | |||
| 9754 | `read-key-sequence' checks `function-key-map' for function key | ||
| 9755 | sequences, where they wouldn't conflict with ordinary bindings. See | ||
| 9756 | `function-key-map' for more details. | ||
| 9757 | |||
| 9758 | The optional fifth argument CMD-LOOP, if non-nil, means | ||
| 9759 | that this key sequence is being read by something that will | ||
| 9760 | read commands one after another. It should be nil if the caller | ||
| 9761 | will read just one key sequence. */) | ||
| 9762 | (Lisp_Object prompt, Lisp_Object continue_echo, Lisp_Object dont_downcase_last, Lisp_Object can_return_switch_frame, Lisp_Object cmd_loop) | ||
| 9763 | { | 9720 | { |
| 9764 | Lisp_Object keybuf[30]; | 9721 | Lisp_Object keybuf[30]; |
| 9765 | register int i; | 9722 | register int i; |
| @@ -9810,60 +9767,71 @@ will read just one key sequence. */) | |||
| 9810 | QUIT; | 9767 | QUIT; |
| 9811 | } | 9768 | } |
| 9812 | UNGCPRO; | 9769 | UNGCPRO; |
| 9813 | return unbind_to (count, make_event_array (i, keybuf)); | 9770 | return unbind_to (count, |
| 9771 | ((allow_string ? make_event_array : Fvector) | ||
| 9772 | (i, keybuf))); | ||
| 9814 | } | 9773 | } |
| 9815 | 9774 | ||
| 9816 | DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector, | 9775 | DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 5, 0, |
| 9817 | Sread_key_sequence_vector, 1, 5, 0, | 9776 | doc: /* Read a sequence of keystrokes and return as a string or vector. |
| 9818 | doc: /* Like `read-key-sequence' but always return a vector. */) | 9777 | The sequence is sufficient to specify a non-prefix command in the |
| 9819 | (Lisp_Object prompt, Lisp_Object continue_echo, Lisp_Object dont_downcase_last, Lisp_Object can_return_switch_frame, Lisp_Object cmd_loop) | 9778 | current local and global maps. |
| 9820 | { | ||
| 9821 | Lisp_Object keybuf[30]; | ||
| 9822 | register int i; | ||
| 9823 | struct gcpro gcpro1; | ||
| 9824 | ptrdiff_t count = SPECPDL_INDEX (); | ||
| 9825 | 9779 | ||
| 9826 | if (!NILP (prompt)) | 9780 | First arg PROMPT is a prompt string. If nil, do not prompt specially. |
| 9827 | CHECK_STRING (prompt); | 9781 | Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos |
| 9828 | QUIT; | 9782 | as a continuation of the previous key. |
| 9829 | 9783 | ||
| 9830 | specbind (Qinput_method_exit_on_first_char, | 9784 | The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not |
| 9831 | (NILP (cmd_loop) ? Qt : Qnil)); | 9785 | convert the last event to lower case. (Normally any upper case event |
| 9832 | specbind (Qinput_method_use_echo_area, | 9786 | is converted to lower case if the original event is undefined and the lower |
| 9833 | (NILP (cmd_loop) ? Qt : Qnil)); | 9787 | case equivalent is defined.) A non-nil value is appropriate for reading |
| 9788 | a key sequence to be defined. | ||
| 9834 | 9789 | ||
| 9835 | memset (keybuf, 0, sizeof keybuf); | 9790 | A C-g typed while in this function is treated like any other character, |
| 9836 | GCPRO1 (keybuf[0]); | 9791 | and `quit-flag' is not set. |
| 9837 | gcpro1.nvars = (sizeof keybuf / sizeof (keybuf[0])); | ||
| 9838 | 9792 | ||
| 9839 | if (NILP (continue_echo)) | 9793 | If the key sequence starts with a mouse click, then the sequence is read |
| 9840 | { | 9794 | using the keymaps of the buffer of the window clicked in, not the buffer |
| 9841 | this_command_key_count = 0; | 9795 | of the selected window as normal. |
| 9842 | this_command_key_count_reset = 0; | ||
| 9843 | this_single_command_key_start = 0; | ||
| 9844 | } | ||
| 9845 | 9796 | ||
| 9846 | #ifdef HAVE_WINDOW_SYSTEM | 9797 | `read-key-sequence' drops unbound button-down events, since you normally |
| 9847 | if (display_hourglass_p) | 9798 | only care about the click or drag events which follow them. If a drag |
| 9848 | cancel_hourglass (); | 9799 | or multi-click event is unbound, but the corresponding click event would |
| 9849 | #endif | 9800 | be bound, `read-key-sequence' turns the event into a click event at the |
| 9801 | drag's starting position. This means that you don't have to distinguish | ||
| 9802 | between click and drag, double, or triple events unless you want to. | ||
| 9850 | 9803 | ||
| 9851 | i = read_key_sequence (keybuf, (sizeof keybuf / sizeof (keybuf[0])), | 9804 | `read-key-sequence' prefixes mouse events on mode lines, the vertical |
| 9852 | prompt, ! NILP (dont_downcase_last), | 9805 | lines separating windows, and scroll bars with imaginary keys |
| 9853 | ! NILP (can_return_switch_frame), 0); | 9806 | `mode-line', `vertical-line', and `vertical-scroll-bar'. |
| 9854 | 9807 | ||
| 9855 | #ifdef HAVE_WINDOW_SYSTEM | 9808 | Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this |
| 9856 | if (display_hourglass_p) | 9809 | function will process a switch-frame event if the user switches frames |
| 9857 | start_hourglass (); | 9810 | before typing anything. If the user switches frames in the middle of a |
| 9858 | #endif | 9811 | key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME |
| 9812 | is nil, then the event will be put off until after the current key sequence. | ||
| 9859 | 9813 | ||
| 9860 | if (i == -1) | 9814 | `read-key-sequence' checks `function-key-map' for function key |
| 9861 | { | 9815 | sequences, where they wouldn't conflict with ordinary bindings. See |
| 9862 | Vquit_flag = Qt; | 9816 | `function-key-map' for more details. |
| 9863 | QUIT; | 9817 | |
| 9864 | } | 9818 | The optional fifth argument CMD-LOOP, if non-nil, means |
| 9865 | UNGCPRO; | 9819 | that this key sequence is being read by something that will |
| 9866 | return unbind_to (count, Fvector (i, keybuf)); | 9820 | read commands one after another. It should be nil if the caller |
| 9821 | will read just one key sequence. */) | ||
| 9822 | (Lisp_Object prompt, Lisp_Object continue_echo, Lisp_Object dont_downcase_last, Lisp_Object can_return_switch_frame, Lisp_Object cmd_loop) | ||
| 9823 | { | ||
| 9824 | return read_key_sequence_vs (prompt, continue_echo, dont_downcase_last, | ||
| 9825 | can_return_switch_frame, cmd_loop, true); | ||
| 9826 | } | ||
| 9827 | |||
| 9828 | DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector, | ||
| 9829 | Sread_key_sequence_vector, 1, 5, 0, | ||
| 9830 | doc: /* Like `read-key-sequence' but always return a vector. */) | ||
| 9831 | (Lisp_Object prompt, Lisp_Object continue_echo, Lisp_Object dont_downcase_last, Lisp_Object can_return_switch_frame, Lisp_Object cmd_loop) | ||
| 9832 | { | ||
| 9833 | return read_key_sequence_vs (prompt, continue_echo, dont_downcase_last, | ||
| 9834 | can_return_switch_frame, cmd_loop, false); | ||
| 9867 | } | 9835 | } |
| 9868 | 9836 | ||
| 9869 | /* Return true if input events are pending. */ | 9837 | /* Return true if input events are pending. */ |