From 27de73af150c458669de29e8662a281baeb0a603 Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Wed, 27 Dec 2023 14:26:26 +0100 Subject: [PATCH 1/5] Extract check for end of macro to function * src/macros.h (at_end_of_macro_p): * src/macros.c (at_end_of_macro_p): New function. * src/keyboard.c (read_char): Use the new function. --- src/keyboard.c | 3 +-- src/macros.c | 12 ++++++++++++ src/macros.h | 5 +++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/keyboard.c b/src/keyboard.c index eb0de98bad1..b6fc568cde5 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -2637,8 +2637,7 @@ read_char (int commandflag, Lisp_Object map, /* Exit the macro if we are at the end. Also, some things replace the macro with t to force an early exit. */ - if (EQ (Vexecuting_kbd_macro, Qt) - || executing_kbd_macro_index >= XFIXNAT (Flength (Vexecuting_kbd_macro))) + if (at_end_of_macro_p ()) { XSETINT (c, -1); goto exit; diff --git a/src/macros.c b/src/macros.c index 5f71bcbd361..62129be1629 100644 --- a/src/macros.c +++ b/src/macros.c @@ -353,6 +353,18 @@ init_macros (void) executing_kbd_macro = Qnil; } +/* Whether the execution of a macro has reached its end. + It makes only sense to call this when while executing a macro. */ + +bool +at_end_of_macro_p (void) +{ + eassume (!NILP (Vexecuting_kbd_macro)); + /* Some things replace the macro with t to force an early exit. */ + return EQ (Vexecuting_kbd_macro, Qt) + || executing_kbd_macro_index >= XFIXNAT (Flength (Vexecuting_kbd_macro)); +} + void syms_of_macros (void) { diff --git a/src/macros.h b/src/macros.h index 51599a29bcd..7870aa4de1d 100644 --- a/src/macros.h +++ b/src/macros.h @@ -47,4 +47,9 @@ #define EMACS_MACROS_H extern void store_kbd_macro_char (Lisp_Object); +/* Whether the execution of a macro has reached its end. + It makes only sense to call this when while executing a macro. */ + +extern bool at_end_of_macro_p (void); + #endif /* EMACS_MACROS_H */ -- 2.44.0