comparison src/keyboard.c @ 15129:e48968f04ea7

(Fthis_single_command_keys): New function. (syms_of_keyboard): defsubr it. (this_single_command_key_start): New variable. (add_command_key): Reduce this_single_command_key_start if nec. (command_loop_1): Clear this_single_command_key_start if nec. (Fread_key_sequence, Fexecute_extended_command): Likewise. (read_key_sequence): Set this_single_command_key_start.
author Richard M. Stallman <rms@gnu.org>
date Thu, 02 May 1996 22:33:51 +0000
parents a5faedec59f1
children aa3de03facd8
comparison
equal deleted inserted replaced
15128:a5faedec59f1 15129:e48968f04ea7
123 actually mean something. 123 actually mean something.
124 It's easier to staticpro a single Lisp_Object than an array. */ 124 It's easier to staticpro a single Lisp_Object than an array. */
125 Lisp_Object this_command_keys; 125 Lisp_Object this_command_keys;
126 int this_command_key_count; 126 int this_command_key_count;
127 127
128 /* Number of elements of this_command_keys
129 that precede this key sequence. */
130 int this_single_command_key_start;
131
128 /* Record values of this_command_key_count and echo_length () 132 /* Record values of this_command_key_count and echo_length ()
129 before this command was read. */ 133 before this command was read. */
130 static int before_command_key_count; 134 static int before_command_key_count;
131 static int before_command_echo_length; 135 static int before_command_echo_length;
132 /* Values of before_command_key_count and before_command_echo_length 136 /* Values of before_command_key_count and before_command_echo_length
713 /* If reset-this-command-length was called recently, obey it now. 717 /* If reset-this-command-length was called recently, obey it now.
714 See the doc string of that function for an explanation of why. */ 718 See the doc string of that function for an explanation of why. */
715 if (before_command_restore_flag) 719 if (before_command_restore_flag)
716 { 720 {
717 this_command_key_count = before_command_key_count_1; 721 this_command_key_count = before_command_key_count_1;
722 if (this_command_key_count < this_single_command_key_start)
723 this_single_command_key_start = this_command_key_count;
718 echo_truncate (before_command_echo_length_1); 724 echo_truncate (before_command_echo_length_1);
719 before_command_restore_flag = 0; 725 before_command_restore_flag = 0;
720 } 726 }
721 727
722 if (this_command_key_count >= size) 728 if (this_command_key_count >= size)
1066 cancel_echoing (); 1072 cancel_echoing ();
1067 1073
1068 nonundocount = 0; 1074 nonundocount = 0;
1069 no_redisplay = 0; 1075 no_redisplay = 0;
1070 this_command_key_count = 0; 1076 this_command_key_count = 0;
1077 this_single_command_key_start = 0;
1071 1078
1072 /* Make sure this hook runs after commands that get errors and 1079 /* Make sure this hook runs after commands that get errors and
1073 throw to top level. */ 1080 throw to top level. */
1074 /* Note that the value cell will never directly contain nil 1081 /* Note that the value cell will never directly contain nil
1075 if the symbol is a local variable. */ 1082 if the symbol is a local variable. */
1172 Just loop around and read another command. */ 1179 Just loop around and read another command. */
1173 if (i == -1) 1180 if (i == -1)
1174 { 1181 {
1175 cancel_echoing (); 1182 cancel_echoing ();
1176 this_command_key_count = 0; 1183 this_command_key_count = 0;
1184 this_single_command_key_start = 0;
1177 goto finalize; 1185 goto finalize;
1178 } 1186 }
1179 1187
1180 last_command_char = keybuf[i - 1]; 1188 last_command_char = keybuf[i - 1];
1181 1189
1396 if (NILP (current_kboard->Vprefix_arg) || CONSP (last_command_char)) 1404 if (NILP (current_kboard->Vprefix_arg) || CONSP (last_command_char))
1397 { 1405 {
1398 current_kboard->Vlast_command = this_command; 1406 current_kboard->Vlast_command = this_command;
1399 cancel_echoing (); 1407 cancel_echoing ();
1400 this_command_key_count = 0; 1408 this_command_key_count = 0;
1409 this_single_command_key_start = 0;
1401 } 1410 }
1402 1411
1403 if (!NILP (current_buffer->mark_active) && !NILP (Vrun_hooks)) 1412 if (!NILP (current_buffer->mark_active) && !NILP (Vrun_hooks))
1404 { 1413 {
1405 if (!NILP (Vdeactivate_mark) && !NILP (Vtransient_mark_mode)) 1414 if (!NILP (Vdeactivate_mark) && !NILP (Vtransient_mark_mode))
5817 /* Record the initial state of the echo area and this_command_keys; 5826 /* Record the initial state of the echo area and this_command_keys;
5818 we will need to restore them if we replay a key sequence. */ 5827 we will need to restore them if we replay a key sequence. */
5819 if (INTERACTIVE) 5828 if (INTERACTIVE)
5820 echo_start = echo_length (); 5829 echo_start = echo_length ();
5821 keys_start = this_command_key_count; 5830 keys_start = this_command_key_count;
5831 this_single_command_key_start = keys_start;
5822 5832
5823 #if defined (GOBBLE_FIRST_EVENT) 5833 #if defined (GOBBLE_FIRST_EVENT)
5824 /* This doesn't quite work, because some of the things that read_char 5834 /* This doesn't quite work, because some of the things that read_char
5825 does cannot safely be bypassed. It seems too risky to try to make 5835 does cannot safely be bypassed. It seems too risky to try to make
5826 this work right. */ 5836 this work right. */
6334 we don't update last_nonmenu_event; it continues to hold the mouse 6344 we don't update last_nonmenu_event; it continues to hold the mouse
6335 event that preceded the first level of menu. */ 6345 event that preceded the first level of menu. */
6336 if (!used_mouse_menu) 6346 if (!used_mouse_menu)
6337 last_nonmenu_event = key; 6347 last_nonmenu_event = key;
6338 6348
6349 /* Record what part of this_command_keys is the current key sequence. */
6350 this_single_command_key_start = this_command_key_count - t;
6351
6339 prev_fkey_map = fkey_map; 6352 prev_fkey_map = fkey_map;
6340 prev_fkey_start = fkey_start; 6353 prev_fkey_start = fkey_start;
6341 prev_fkey_end = fkey_end; 6354 prev_fkey_end = fkey_end;
6342 6355
6343 prev_keytran_map = keytran_map; 6356 prev_keytran_map = keytran_map;
6402 /* If the function returned something invalid, 6415 /* If the function returned something invalid,
6403 barf--don't ignore it. 6416 barf--don't ignore it.
6404 (To ignore it safely, we would need to gcpro a bunch of 6417 (To ignore it safely, we would need to gcpro a bunch of
6405 other variables.) */ 6418 other variables.) */
6406 if (! (VECTORP (fkey_next) || STRINGP (fkey_next))) 6419 if (! (VECTORP (fkey_next) || STRINGP (fkey_next)))
6407 error ("Function in function-key-map returns invalid key sequence"); 6420 error ("Function in key-translation-map returns invalid key sequence");
6408 } 6421 }
6409 6422
6410 function_key_possible = ! NILP (fkey_next); 6423 function_key_possible = ! NILP (fkey_next);
6411 6424
6412 /* If keybuf[fkey_start..fkey_end] is bound in the 6425 /* If keybuf[fkey_start..fkey_end] is bound in the
6736 bzero (keybuf, sizeof keybuf); 6749 bzero (keybuf, sizeof keybuf);
6737 GCPRO1 (keybuf[0]); 6750 GCPRO1 (keybuf[0]);
6738 gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0])); 6751 gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0]));
6739 6752
6740 if (NILP (continue_echo)) 6753 if (NILP (continue_echo))
6741 this_command_key_count = 0; 6754 {
6755 this_command_key_count = 0;
6756 this_single_command_key_start = 0;
6757 }
6742 6758
6743 i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])), 6759 i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])),
6744 prompt, ! NILP (dont_downcase_last), 6760 prompt, ! NILP (dont_downcase_last),
6745 ! NILP (can_return_switch_frame)); 6761 ! NILP (can_return_switch_frame));
6746 6762
6758 CMD must be a symbol that satisfies the `commandp' predicate.\n\ 6774 CMD must be a symbol that satisfies the `commandp' predicate.\n\
6759 Optional second arg RECORD-FLAG non-nil\n\ 6775 Optional second arg RECORD-FLAG non-nil\n\
6760 means unconditionally put this command in `command-history'.\n\ 6776 means unconditionally put this command in `command-history'.\n\
6761 Otherwise, that is done only if an arg is read using the minibuffer.\n\ 6777 Otherwise, that is done only if an arg is read using the minibuffer.\n\
6762 The argument KEYS specifies the value to use instead of (this-command-keys)\n\ 6778 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
6763 when reading the arguments; if it is nil, (this_command_key_count) is used.\n\ 6779 when reading the arguments; if it is nil, (this-command-keys) is used.\n\
6764 The argument SPECIAL, if non-nil, means that this command is executing\n\ 6780 The argument SPECIAL, if non-nil, means that this command is executing\n\
6765 a special event, so ignore the prefix argument and don't clear it.") 6781 a special event, so ignore the prefix argument and don't clear it.")
6766 (cmd, record_flag, keys, special) 6782 (cmd, record_flag, keys, special)
6767 Lisp_Object cmd, record_flag, keys, special; 6783 Lisp_Object cmd, record_flag, keys, special;
6768 { 6784 {
6896 Lisp_Object *keys; 6912 Lisp_Object *keys;
6897 int i; 6913 int i;
6898 Lisp_Object tem; 6914 Lisp_Object tem;
6899 6915
6900 this_command_key_count = 0; 6916 this_command_key_count = 0;
6917 this_single_command_key_start = 0;
6901 6918
6902 keys = XVECTOR (saved_keys)->contents; 6919 keys = XVECTOR (saved_keys)->contents;
6903 for (i = 0; i < XVECTOR (saved_keys)->size; i++) 6920 for (i = 0; i < XVECTOR (saved_keys)->size; i++)
6904 add_command_key (keys[i]); 6921 add_command_key (keys[i]);
6905 6922
7058 The value is a string or a vector.") 7075 The value is a string or a vector.")
7059 () 7076 ()
7060 { 7077 {
7061 return make_event_array (this_command_key_count, 7078 return make_event_array (this_command_key_count,
7062 XVECTOR (this_command_keys)->contents); 7079 XVECTOR (this_command_keys)->contents);
7080 }
7081
7082 DEFUN ("this-single-command-keys", Fthis_single_command_keys,
7083 Sthis_single_command_keys, 0, 0, 0,
7084 "Return the key sequence that invoked this command.\n\
7085 Unlike `this-command-keys', this function's value\n\
7086 does not include prefix arguments.\n\
7087 The value is a string or a vector.")
7088 ()
7089 {
7090 return make_event_array (this_command_key_count
7091 - this_single_command_key_start,
7092 (XVECTOR (this_command_keys)->contents
7093 + this_single_command_key_start));
7063 } 7094 }
7064 7095
7065 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths, 7096 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths,
7066 Sreset_this_command_lengths, 0, 0, 0, 7097 Sreset_this_command_lengths, 0, 0, 0,
7067 "Used for complicated reasons in `universal-argument-other-key'.\n\ 7098 "Used for complicated reasons in `universal-argument-other-key'.\n\
7812 #endif 7843 #endif
7813 defsubr (&Sinput_pending_p); 7844 defsubr (&Sinput_pending_p);
7814 defsubr (&Scommand_execute); 7845 defsubr (&Scommand_execute);
7815 defsubr (&Srecent_keys); 7846 defsubr (&Srecent_keys);
7816 defsubr (&Sthis_command_keys); 7847 defsubr (&Sthis_command_keys);
7848 defsubr (&Sthis_single_command_keys);
7817 defsubr (&Sreset_this_command_lengths); 7849 defsubr (&Sreset_this_command_lengths);
7818 defsubr (&Ssuspend_emacs); 7850 defsubr (&Ssuspend_emacs);
7819 defsubr (&Sabort_recursive_edit); 7851 defsubr (&Sabort_recursive_edit);
7820 defsubr (&Sexit_recursive_edit); 7852 defsubr (&Sexit_recursive_edit);
7821 defsubr (&Srecursion_depth); 7853 defsubr (&Srecursion_depth);