From c356db9f44a669ee66d5cc14e6968b31e1a6210e Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Mon, 15 Jul 2024 17:27:48 +0200 Subject: [PATCH] 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 Bug exists since version 2.9.4, since string binds were introduced. --- src/prototypes.h | 2 +- src/winio.c | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/prototypes.h b/src/prototypes.h index 6795d6e1..4a1eac51 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -595,8 +595,8 @@ linestruct *line_from_number(ssize_t number); void record_macro(void); void run_macro(void); #endif -void reserve_space_for(size_t newsize); size_t waiting_keycodes(void); +void put_back(int keycode); #ifdef ENABLE_NANORC void implant(const char *string); #endif diff --git a/src/winio.c b/src/winio.c index 843d34df..90c32b44 100644 --- a/src/winio.c +++ b/src/winio.c @@ -123,14 +123,9 @@ void run_macro(void) return; } - if (macro_length > capacity) - reserve_space_for(macro_length); + for (size_t index = macro_length; index > 0; ) + 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; } #endif /* !NANO_TINY */