Subject: bug#66998: 29.1; Regression for recursive keyboard macros + minibuffers in (I think) Emacs 28

From: Alan Mackenzie <[email-masked]>
Date: Thu, 9 Nov 2023 17:37:22 +0000

Hello, Morgon.

Thanks for taking the trouble to report this.

[ Unfortunately, your post, in HTML, has got corrupted somewhere,
possibly in my mail user agent, thus is difficult to read. ]

On Tue, Nov 07, 2023 at 22:29:22 -0500, Morgon Kanter wrote:
>    I believe there is a regression, but possibly intentional, caused by
>    this patch:
>    [1]https://github.com/emacs-mirror/emacs/commit/203e61ff837128b397eb313
>    a5bb1b703f0eae0ec
>    This affects minibuffers created when (kbd-macro-query t) is called as
>    part of the hook that runs when the (read-from-minibuffer) function is
>    called. You get the error message "Not in most nested command loop".

>    For example, this code here:
>    [2]https://www.emacswiki.org/emacs/KeyboardMacros#h5o-5
>    Or, pasting the code in question:
>    Â  Â  (defun my-macro-query (arg)
>    Â  Â  Â  "Prompt for input using minibuffer during kbd macro execution.
>    Â  Â  With prefix argument, allows you to select what prompt string to
>    use.
>    Â  Â  If the input is non-empty, it is inserted at point."
>    Â  Â  Â  (interactive "P")
>    Â  Â  Â  (let* ((prompt (if arg (read-from-minibuffer "PROMPT: ")
>    "Input: "))
>    Â  Â  Â  Â  Â  Â  Â (input (minibuffer-with-setup-hook (lambda ()
>    (kbd-macro-query t))
>    Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  (read-from-minibuffer prompt))))
>    Â  Â  Â  Â  (unless (string= "" input) (insert input))))
>    Â  Â  (global-set-key (kbd "C-x Q") 'my-macro-query)

>    If you attempt to start a keyboard macro via F3, then attempt to read a
>    minibuffer with the above code via C-x Q, upon pressing ENTER to close
>    the minibuffer, you get the following error message:
>    "Not in most nested command loop"

>    You won't be able to close out the minibuffer, the only way I found
>    to proceed was to C-] or multiple escapes, which canceled the
>    keyboard macro creation. As a result, it appears we can't use the
>    above method to read and set variables during keyboard macro
>    creation. I'm not sure if this is intentional or not, or if there's
>    a replacement for the above or not. But it appears to be a
>    regression from before that series of patches.

As you say in your later post, you can terminate the recursive edit with
C-M-c.  I'm not sure there's actually a bug, here.  While in the
recursive edit, the minibuffer "belongs" to the outer editing level,
and this outer level expects the recursive edit to be closed before its
minibuffer input can be terminated.

So I think the error message "Not in most nested command loop" is
correct, even if its not very clear in this context.

What are you actually trying to achieve in your real Lisp code with this
recursive edit?  At first acquaintance, it looks rather unusual.

>    In GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38,
>    cairo version 1.17.8)
>    Windowing system distributor 'Microsoft Corporation', version
>    11.0.12010000
>    System Description: Arch Linux

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).