macro: insert it in keystroke buffer without discarding latter's contents

Instead of simply overwriting the current contents of the keystroke
buffer with the contents of the macro buffer, insert the latter's
contents at the head of the keystroke buffer.

This allows using {runmacro} in a string bind, and allows typing ahead
over a laggy connection after invoking `runmacro` (normally with M-;).

This fixes https://savannah.gnu.org/bugs/?65991.
Reported-by: Tasos Papastylianou <tpapastylianou@hotmail.com>

Bug exists since version 2.9.4, since string binds were introduced.
This commit is contained in:
Benno Schulenberg 2024-07-15 17:27:48 +02:00
parent c53839cefa
commit c356db9f44
2 changed files with 3 additions and 8 deletions

View File

@ -595,8 +595,8 @@ linestruct *line_from_number(ssize_t number);
void record_macro(void); void record_macro(void);
void run_macro(void); void run_macro(void);
#endif #endif
void reserve_space_for(size_t newsize);
size_t waiting_keycodes(void); size_t waiting_keycodes(void);
void put_back(int keycode);
#ifdef ENABLE_NANORC #ifdef ENABLE_NANORC
void implant(const char *string); void implant(const char *string);
#endif #endif

View File

@ -123,14 +123,9 @@ void run_macro(void)
return; return;
} }
if (macro_length > capacity) for (size_t index = macro_length; index > 0; )
reserve_space_for(macro_length); put_back(macro_buffer[--index]);
for (size_t i = 0; i < macro_length; i++)
key_buffer[i] = macro_buffer[i];
waiting_codes = macro_length;
nextcodes = key_buffer;
mute_modifiers = TRUE; mute_modifiers = TRUE;
} }
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */