Subject: Re: bug#67837: 29.1.90; inhibit-interaction breaks keyboard macros

From: Spencer Baugh <[email-masked]>
Date: Fri, 15 Dec 2023 11:50:29 -0500

Patch to fix:

>From b0f680393991d9ccbd888be8f754a85775196799 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <[email-masked]>
Date: Fri, 15 Dec 2023 11:39:24 -0500
Subject: [PATCH] Make inhibit-interaction work properly with keyboard macros

Previously, inhibit-interaction=t prevented keyboard macros from
running, even when those macros did not result in user interaction,
since it was checked before the keyboard macro code had a chance to
provide input.

Now, if there's a running keyboard macro which can provide input, that
keyboard macro is allowed to provide input even if
inhibit-interaction=t.  This is achieved by moving the check on
inhibit-interaction to run after checking executing-kbd-macro in the
low-level input handling mechanism, read_char.

inhibit-interaction also suppresses reading from stdin in batch mode,
so we also must add a check on inhibit-interaction to
read_minibuf_noninteractive, which again is only called after checking
executing-kbd-macro.

* src/keyboard.c (read_char): Add call to
barf_if_interaction_inhibited. (bug#67837)
* src/lread.c (Fread_char, Fread_event, Fread_char_exclusive): Remove
call to barf_if_interaction_inhibited.
* src/minibuf.c (Fread_from_minibuffer): Remove call to
barf_if_interaction_inhibited.
(read_minibuf_noninteractive): Add call to barf_if_interaction_inhibited.
---
 src/keyboard.c | 5 ++++-
 src/lread.c    | 6 ------
 src/minibuf.c  | 5 +++--
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/keyboard.c b/src/keyboard.c
index 81605e75ba2..9ec39c89699 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -2632,7 +2632,10 @@ read_char (int commandflag, Lisp_Object map,
       executing_kbd_macro_index++;
 
       goto from_macro;
-    }
+    } else
+    /* Getting input from a keyboard macro doesn't count as
+       interacting with the user.  */
+    barf_if_interaction_inhibited ();
 
   if (!NILP (unread_switch_frame))
     {
diff --git a/src/lread.c b/src/lread.c
index 255b6e914d9..154c751cbe9 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -950,8 +950,6 @@ DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0,
 {
   Lisp_Object val;
 
-  barf_if_interaction_inhibited ();
-
   if (! NILP (prompt))
     {
       cancel_echoing ();
@@ -988,8 +986,6 @@ DEFUN ("read-event", Fread_event, Sread_event, 0, 3, 0,
 `inhibited-interaction' error.  */)
   (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds)
 {
-  barf_if_interaction_inhibited ();
-
   if (! NILP (prompt))
     {
       cancel_echoing ();
@@ -1027,8 +1023,6 @@ DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 3,
 {
   Lisp_Object val;
 
-  barf_if_interaction_inhibited ();
-
   if (! NILP (prompt))
     {
       cancel_echoing ();
diff --git a/src/minibuf.c b/src/minibuf.c
index 58adde1bf66..bf21a8d9cad 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -316,6 +316,9 @@ read_minibuf_noninteractive (Lisp_Object prompt, bool expflag,
   struct emacs_tty etty;
   bool etty_valid UNINIT;
 
+  /* inhibit-interaction also prevents reading from stdin. */
+  barf_if_interaction_inhibited ();
+
   /* Check, whether we need to suppress echoing.  */
   if (CHARACTERP (Vread_hide_char))
     hide_char = XFIXNAT (Vread_hide_char);
@@ -1344,8 +1347,6 @@ DEFUN ("read-from-minibuffer", Fread_from_minibuffer,
 {
   Lisp_Object histvar, histpos, val;
 
-  barf_if_interaction_inhibited ();
-
   CHECK_STRING (prompt);
   if (NILP (keymap))
     keymap = Vminibuffer_local_map;
-- 
2.39.3