/* This is the actual command reading loop,
sans error-handling encapsulation. */
-static int read_key_sequence (Lisp_Object *, int, Lisp_Object,
+enum { READ_KEY_ELTS = 30 };
+static int read_key_sequence (Lisp_Object *, Lisp_Object,
bool, bool, bool, bool);
static void adjust_point_for_property (ptrdiff_t, bool);
if (!CONSP (last_command_event))
kset_last_repeatable_command (current_kboard, Vreal_this_command);
- while (1)
+ while (true)
{
Lisp_Object cmd;
- Lisp_Object keybuf[30];
- int i;
if (! FRAME_LIVE_P (XFRAME (selected_frame)))
Fkill_emacs (Qnil);
/* Read next key sequence; i gets its length. */
raw_keybuf_count = 0;
- i = read_key_sequence (keybuf, ARRAYELTS (keybuf),
- Qnil, 0, 1, 1, 0);
+ Lisp_Object keybuf[READ_KEY_ELTS];
+ int i = read_key_sequence (keybuf, Qnil, false, true, true, false);
/* A filter may have run while we were reading the input. */
if (! FRAME_LIVE_P (XFRAME (selected_frame)))
Lisp_Object
read_menu_command (void)
{
- Lisp_Object keybuf[30];
ptrdiff_t count = SPECPDL_INDEX ();
- int i;
/* We don't want to echo the keystrokes while navigating the
menus. */
specbind (Qecho_keystrokes, make_number (0));
- i = read_key_sequence (keybuf, ARRAYELTS (keybuf),
- Qnil, 0, 1, 1, 1);
+ Lisp_Object keybuf[READ_KEY_ELTS];
+ int i = read_key_sequence (keybuf, Qnil, false, true, true, true);
unbind_to (count, Qnil);
/* Do one step of the key remapping used for function-key-map and
key-translation-map:
- KEYBUF is the buffer holding the input events.
- BUFSIZE is its maximum size.
+ KEYBUF is the READ_KEY_ELTS-size buffer holding the input events.
FKEY is a pointer to the keyremap structure to use.
INPUT is the index of the last element in KEYBUF.
DOIT if true says that the remapping can actually take place.
Return true if the remapping actually took place. */
static bool
-keyremap_step (Lisp_Object *keybuf, int bufsize, volatile keyremap *fkey,
+keyremap_step (Lisp_Object *keybuf, volatile keyremap *fkey,
int input, bool doit, int *diff, Lisp_Object prompt)
{
Lisp_Object next, key;
*diff = len - (fkey->end - fkey->start);
- if (bufsize - input <= *diff)
+ if (READ_KEY_ELTS - input <= *diff)
error ("Key sequence too long");
/* Shift the keys that follow fkey->end. */
raw_keybuf_count = 0;
}
-/* Grow a vector to fit.
-
- On entry, *VECTOR is nil or a bool vector. Upon return, *VECTOR
- contains a bool vector of size at least NEEDED_LENGTH, with any new
- values to false. Return the new value of *VECTOR. */
-static Lisp_Object
-grow_bool_vector (Lisp_Object *vector, int needed_length)
-{
- EMACS_INT old_length = NILP (*vector) ? 0 : bool_vector_size (*vector);
- if (NILP (*vector) || old_length < needed_length)
- {
- EMACS_INT new_length = old_length ? old_length : 64;
- while (new_length < needed_length)
- new_length *= 2;
- Lisp_Object new_vector =
- Fmake_bool_vector (make_number (needed_length), Qnil);
- if (old_length)
- memcpy (bool_vector_data (new_vector),
- bool_vector_data (*vector),
- bool_vector_bytes (old_length));
- *vector = new_vector;
- }
- return *vector;
-}
-
/* Read a sequence of keys that ends with a non prefix character,
- storing it in KEYBUF, a buffer of size BUFSIZE.
+ storing it in KEYBUF, a buffer of size READ_KEY_ELTS.
Prompt with PROMPT.
Return the length of the key sequence stored.
Return -1 if the user rejected a command menu.
from the selected window's buffer. */
static int
-read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
+read_key_sequence (Lisp_Object *keybuf, Lisp_Object prompt,
bool dont_downcase_last, bool can_return_switch_frame,
bool fix_current_buffer, bool prevent_redisplay)
{
reading characters from the keyboard. */
int mock_input = 0;
- /* This bool vector remembers whether each event in the mocked input
- came from a mouse menu. We ordinarily leave it nil and create it
- the first time we remember a mouse event. */
- Lisp_Object used_mouse_menu_history = Qnil;
+ /* Whether each event in the mocked input came from a mouse menu. */
+ bool used_mouse_menu_history[READ_KEY_ELTS] = {0};
/* Distinguish first time through from replay with mock_input == 0. */
bool is_replay = false;
replay_sequence:
starting_buffer = current_buffer;
- first_unbound = bufsize + 1;
+ first_unbound = READ_KEY_ELTS + 1;
Lisp_Object first_event = mock_input > 0 ? keybuf[0] : Qnil;
Lisp_Object second_event = mock_input > 1 ? keybuf[1] : Qnil;
goto replay_sequence;
}
- if (t >= bufsize)
+ if (t >= READ_KEY_ELTS)
error ("Key sequence too long");
if (INTERACTIVE)
current_kboard->immediate_echo = false;
echo_now ();
}
- used_mouse_menu = !NILP (used_mouse_menu_history) &&
- t < bool_vector_size (used_mouse_menu_history) &&
- bool_vector_bitref (used_mouse_menu_history, t);
+ used_mouse_menu = used_mouse_menu_history[t];
}
/* If not, we should actually read a character. */
key = read_char (prevent_redisplay ? -2 : NILP (prompt),
current_binding, last_nonmenu_event,
&used_mouse_menu, NULL);
- if (used_mouse_menu || !NILP (used_mouse_menu_history))
- bool_vector_set (
- grow_bool_vector (&used_mouse_menu_history, t + 1),
- t, used_mouse_menu);
+ used_mouse_menu_history[t] = used_mouse_menu;
if ((INTEGERP (key) && XINT (key) == -2) /* wrong_kboard_jmpbuf */
/* When switching to a new tty (with a new keyboard),
read_char returns the new buffer, rather than -2
&& (NILP (fake_prefixed_keys)
|| NILP (Fmemq (key, fake_prefixed_keys))))
{
- if (bufsize - t <= 1)
+ if (READ_KEY_ELTS - t <= 1)
error ("Key sequence too long");
keybuf[t] = posn;
insert the dummy prefix event `menu-bar'. */
if (EQ (posn, Qmenu_bar) || EQ (posn, Qtool_bar))
{
- if (bufsize - t <= 1)
+ if (READ_KEY_ELTS - t <= 1)
error ("Key sequence too long");
keybuf[t] = posn;
keybuf[t + 1] = key;
bool done;
int diff;
- done = keyremap_step (keybuf, bufsize, &indec, max (t, mock_input),
- 1, &diff, prompt);
+ done = keyremap_step (keybuf, &indec, max (t, mock_input),
+ true, &diff, prompt);
if (done)
{
mock_input = diff + max (t, mock_input);
bool done;
int diff;
- done = keyremap_step (keybuf, bufsize, &fkey,
+ done = keyremap_step (keybuf, &fkey,
max (t, mock_input),
/* If there's a binding (i.e.
first_binding >= nmaps) we don't want
to apply this function-key-mapping. */
- fkey.end + 1 == t
- && (test_undefined (current_binding)),
+ (fkey.end + 1 == t
+ && test_undefined (current_binding)),
&diff, prompt);
if (done)
{
bool done;
int diff;
- done = keyremap_step (keybuf, bufsize, &keytran, max (t, mock_input),
- 1, &diff, prompt);
+ done = keyremap_step (keybuf, &keytran, max (t, mock_input),
+ true, &diff, prompt);
if (done)
{
mock_input = diff + max (t, mock_input);
Lisp_Object can_return_switch_frame,
Lisp_Object cmd_loop, bool allow_string)
{
- Lisp_Object keybuf[30];
- int i;
ptrdiff_t count = SPECPDL_INDEX ();
if (!NILP (prompt))
#endif
raw_keybuf_count = 0;
- i = read_key_sequence (keybuf, ARRAYELTS (keybuf),
- prompt, ! NILP (dont_downcase_last),
- ! NILP (can_return_switch_frame), 0, 0);
+ Lisp_Object keybuf[READ_KEY_ELTS];
+ int i = read_key_sequence (keybuf, prompt, ! NILP (dont_downcase_last),
+ ! NILP (can_return_switch_frame), false, false);
#if 0 /* The following is fine for code reading a key sequence and
then proceeding with a lengthy computation, but it's not good