Subject: bug#17272: bug#19064: bug#17272: bug#19064: bug#17272: bug#19064: 25.0.50; `message' overwrites `y-or-n-p' prompt, so user misses it

From: Juri Linkov <[email-masked]>
Date: Thu, 21 Nov 2019 00:10:59 +0200

> Emacs -Q
> M-x fido-mode
> (defalias 'yes-or-no-p 'y-or-n-p) ;; a common custmization
> C-x b
> C-k ;; to kill the Messages buffer
>
> Before your changes to `y-or-n-p` this worked well, afterwards
> I get the "Attempt to use minibuffer inside minibuffer" error.
>
> Bear in mind that fido-mode is very new. Also bear in mind
> that the problem is already present when yes-or-no-p is used.
>
> I think a good fix is for icomplete to do this (and for
> you to do nothing :-) )

It's tempting to do nothing :-), but since the problem is
already present with yes-or-no-p too, it should be fixed
because it's a general problem affecting other commands too.

The nil value of enable-recursive-minibuffers by default was intended
to avoid confusion for beginners unadvisedly typing such sequences as
M-x M-x M-x M-x M-x ... to get out from which is not easy.

But for yes/no or y/n questions it should be right to
allow recursive minibuffers temporarily:

diff --git a/lisp/subr.el b/lisp/subr.el
index 20daed623f..2265965c60 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2847,6 +2848,7 @@ y-or-n-p
      (t
       (setq prompt (funcall padded prompt))
       (let* ((empty-history '())
+             (enable-recursive-minibuffers t)
              (str (read-from-minibuffer
                    prompt nil
                    (make-composed-keymap y-or-n-p-map query-replace-map)
diff --git a/src/fns.c b/src/fns.c
index cbb6879223..3ae3192b3d 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -2805,15 +2805,18 @@ DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 1, 0,
   AUTO_STRING (yes_or_no, "(yes or no) ");
   prompt = CALLN (Fconcat, prompt, yes_or_no);
 
+  ptrdiff_t count = SPECPDL_INDEX ();
+  specbind (Qenable_recursive_minibuffers, Qt);
+
   while (1)
     {
       ans = Fdowncase (Fread_from_minibuffer (prompt, Qnil, Qnil, Qnil,
 					      Qyes_or_no_p_history, Qnil,
 					      Qnil));
       if (SCHARS (ans) == 3 && !strcmp (SSDATA (ans), "yes"))
-	return Qt;
+	return unbind_to (count, Qt);
       if (SCHARS (ans) == 2 && !strcmp (SSDATA (ans), "no"))
-	return Qnil;
+	return unbind_to (count, Qnil);
 
       Fding (Qnil);
       Fdiscard_input ();