aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Monnier2013-09-04 16:32:22 -0400
committerStefan Monnier2013-09-04 16:32:22 -0400
commit6629638eb3d49be98cb9633d7b52d19acc0c5d18 (patch)
tree345a1da8a16a01148070bbab09660139a7c70c45 /src
parentd99760fa44c45477afeaf46784742a2670423161 (diff)
downloademacs-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/ChangeLog4
-rw-r--r--src/keyboard.c152
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 @@
12013-09-04 Stefan Monnier <monnier@iro.umontreal.ca> 12013-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
52013-09-04 Paul Eggert <eggert@cs.ucla.edu> 92013-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
9715DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 5, 0, 9715static Lisp_Object
9716 doc: /* Read a sequence of keystrokes and return as a string or vector. 9716read_key_sequence_vs (Lisp_Object prompt, Lisp_Object continue_echo,
9717The sequence is sufficient to specify a non-prefix command in the 9717 Lisp_Object dont_downcase_last,
9718current local and global maps. 9718 Lisp_Object can_return_switch_frame,
9719 9719 Lisp_Object cmd_loop, bool allow_string)
9720First arg PROMPT is a prompt string. If nil, do not prompt specially.
9721Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos
9722as a continuation of the previous key.
9723
9724The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not
9725convert the last event to lower case. (Normally any upper case event
9726is converted to lower case if the original event is undefined and the lower
9727case equivalent is defined.) A non-nil value is appropriate for reading
9728a key sequence to be defined.
9729
9730A C-g typed while in this function is treated like any other character,
9731and `quit-flag' is not set.
9732
9733If the key sequence starts with a mouse click, then the sequence is read
9734using the keymaps of the buffer of the window clicked in, not the buffer
9735of the selected window as normal.
9736
9737`read-key-sequence' drops unbound button-down events, since you normally
9738only care about the click or drag events which follow them. If a drag
9739or multi-click event is unbound, but the corresponding click event would
9740be bound, `read-key-sequence' turns the event into a click event at the
9741drag's starting position. This means that you don't have to distinguish
9742between click and drag, double, or triple events unless you want to.
9743
9744`read-key-sequence' prefixes mouse events on mode lines, the vertical
9745lines separating windows, and scroll bars with imaginary keys
9746`mode-line', `vertical-line', and `vertical-scroll-bar'.
9747
9748Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this
9749function will process a switch-frame event if the user switches frames
9750before typing anything. If the user switches frames in the middle of a
9751key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME
9752is 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
9755sequences, where they wouldn't conflict with ordinary bindings. See
9756`function-key-map' for more details.
9757
9758The optional fifth argument CMD-LOOP, if non-nil, means
9759that this key sequence is being read by something that will
9760read commands one after another. It should be nil if the caller
9761will 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
9816DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector, 9775DEFUN ("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. */) 9777The 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) 9778current 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)) 9780First arg PROMPT is a prompt string. If nil, do not prompt specially.
9827 CHECK_STRING (prompt); 9781Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos
9828 QUIT; 9782as a continuation of the previous key.
9829 9783
9830 specbind (Qinput_method_exit_on_first_char, 9784The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not
9831 (NILP (cmd_loop) ? Qt : Qnil)); 9785convert the last event to lower case. (Normally any upper case event
9832 specbind (Qinput_method_use_echo_area, 9786is converted to lower case if the original event is undefined and the lower
9833 (NILP (cmd_loop) ? Qt : Qnil)); 9787case equivalent is defined.) A non-nil value is appropriate for reading
9788a key sequence to be defined.
9834 9789
9835 memset (keybuf, 0, sizeof keybuf); 9790A C-g typed while in this function is treated like any other character,
9836 GCPRO1 (keybuf[0]); 9791and `quit-flag' is not set.
9837 gcpro1.nvars = (sizeof keybuf / sizeof (keybuf[0]));
9838 9792
9839 if (NILP (continue_echo)) 9793If the key sequence starts with a mouse click, then the sequence is read
9840 { 9794using the keymaps of the buffer of the window clicked in, not the buffer
9841 this_command_key_count = 0; 9795of 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) 9798only care about the click or drag events which follow them. If a drag
9848 cancel_hourglass (); 9799or multi-click event is unbound, but the corresponding click event would
9849#endif 9800be bound, `read-key-sequence' turns the event into a click event at the
9801drag's starting position. This means that you don't have to distinguish
9802between 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), 9805lines 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 9808Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this
9856 if (display_hourglass_p) 9809function will process a switch-frame event if the user switches frames
9857 start_hourglass (); 9810before typing anything. If the user switches frames in the middle of a
9858#endif 9811key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME
9812is 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 { 9815sequences, where they wouldn't conflict with ordinary bindings. See
9862 Vquit_flag = Qt; 9816`function-key-map' for more details.
9863 QUIT; 9817
9864 } 9818The optional fifth argument CMD-LOOP, if non-nil, means
9865 UNGCPRO; 9819that this key sequence is being read by something that will
9866 return unbind_to (count, Fvector (i, keybuf)); 9820read commands one after another. It should be nil if the caller
9821will 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
9828DEFUN ("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. */