unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: rms@gnu.org, 46583@debbugs.gnu.org
Subject: bug#46583: 28.0.50; nested minibuffers
Date: Thu, 18 Feb 2021 19:17:13 +0200	[thread overview]
Message-ID: <87tuq9fmpi.fsf@mail.linkov.net> (raw)
In-Reply-To: <83im6p5tx8.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 18 Feb 2021 16:31:31 +0200")

[-- Attachment #1: Type: text/plain, Size: 2172 bytes --]

>> I could send a patch that fixes this bug.
>
> Thanks.  I hoped first to understand why we bind
> enable-recursive-minibuffers in these cases, but if you prefer to
> begin with a patch, please do, and let's take it from there.

To understand the problem, it's better to start from the manual.
The node (info "(elisp) Recursive Mini") says:

     If a command name has a property ‘enable-recursive-minibuffers’ that
  is non-‘nil’, then the command can use the minibuffer to read arguments
  even if it is invoked from the minibuffer.  A command can also achieve
  this by binding ‘enable-recursive-minibuffers’ to ‘t’ in the interactive
  declaration (*note Using Interactive::).  The minibuffer command
  ‘next-matching-history-element’ (normally ‘M-s’ in the minibuffer) does
  the latter.

And indeed the command ‘next-matching-history-element’ (‘M-s’)
mentioned as an example in the documentation, exhibits the same
problem reported by Richard:

0. emacs -Q
1. M-x                  ;; execute-extended-command
2. M-s                  ;; next-matching-history-element
3. C-x b                ;; switch-to-buffer

And it tries to read a buffer name, ignoring the default nil value
of ‘enable-recursive-minibuffers’.

This is because the manual documents the official way by binding
‘enable-recursive-minibuffers’ to ‘t’ that next-matching-history-element
does:

  (defun next-matching-history-element (regexp n)
    (interactive
     (let* ((enable-recursive-minibuffers t)
            (regexp (read-from-minibuffer "Next element matching (regexp): "
  ...

One possible solution is to support an additional value ‘transient’
for the variable ‘enable-recursive-minibuffers’.  Then this value
could have its effect only for the next invocation of
read-from-minibuffer.  Afterwards it will be set to ‘nil’
for any further recursive calls of read-from-minibuffer.

PS: Such transient value is similar to the value ‘lambda’ of
‘transient-mark-mode’ described in (info "(elisp) The Mark").

Currently this patch fixes the reported problem only
for the commands yes-or-no-p and next-matching-history-element:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: transient-enable-recursive-minibuffers.patch --]
[-- Type: text/x-diff, Size: 2841 bytes --]

diff --git a/src/minibuf.c b/src/minibuf.c
index 4b1f4b1ff7..8a46693846 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -592,7 +592,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
   if (!STRINGP (prompt))
     prompt = empty_unibyte_string;
 
-  if (!enable_recursive_minibuffers
+  if (NILP (Venable_recursive_minibuffers)
       && minibuf_level > 0)
     {
       Lisp_Object str
@@ -604,6 +604,9 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
 	Fthrow (Qexit, str);
     }
 
+  if (EQ (Venable_recursive_minibuffers, Qtransient))
+    specbind (Qenable_recursive_minibuffers, Qnil);
+
   if ((noninteractive
        /* In case we are running as a daemon, only do this before
 	  detaching from the terminal.  */
@@ -2242,6 +2245,7 @@ syms_of_minibuf (void)
   DEFSYM (Qcase_fold_search, "case-fold-search");
   DEFSYM (Qmetadata, "metadata");
   DEFSYM (Qcycle_sort_function, "cycle-sort-function");
+  DEFSYM (Qtransient, "transient");
 
   /* A frame parameter.  */
   DEFSYM (Qminibuffer_exit, "minibuffer-exit");
@@ -2311,12 +2315,12 @@ syms_of_minibuf (void)
 controls the behavior, rather than this variable.  */);
   completion_ignore_case = 0;
 
-  DEFVAR_BOOL ("enable-recursive-minibuffers", enable_recursive_minibuffers,
+  DEFVAR_LISP ("enable-recursive-minibuffers", Venable_recursive_minibuffers,
 	       doc: /* Non-nil means to allow minibuffer commands while in the minibuffer.
 This variable makes a difference whenever the minibuffer window is active.
 Also see `minibuffer-depth-indicate-mode', which may be handy if this
 variable is non-nil. */);
-  enable_recursive_minibuffers = 0;
+  Venable_recursive_minibuffers = Qnil;
 
   DEFVAR_LISP ("minibuffer-completion-table", Vminibuffer_completion_table,
 	       doc: /* Alist or obarray used for completion in the minibuffer.
diff --git a/src/fns.c b/src/fns.c
index f51ef2781d..4744fddf27 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -2882,7 +2882,8 @@ DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 1, 0,
   prompt = CALLN (Fconcat, prompt, yes_or_no);
 
   ptrdiff_t count = SPECPDL_INDEX ();
-  specbind (Qenable_recursive_minibuffers, Qt);
+  if (NILP (Venable_recursive_minibuffers))
+    specbind (Qenable_recursive_minibuffers, Qtransient);
 
   while (1)
     {
diff --git a/lisp/simple.el b/lisp/simple.el
index 7eee65e204..99b959b2fc 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2370,7 +2370,7 @@ next-matching-history-element
 `case-fold-search' is non-nil, but an uppercase letter in REGEXP
 makes the search case-sensitive."
   (interactive
-   (let* ((enable-recursive-minibuffers t)
+   (let* ((enable-recursive-minibuffers (or enable-recursive-minibuffers 'transient))
 	  (regexp (read-from-minibuffer "Next element matching (regexp): "
 					nil
 					minibuffer-local-map

  reply	other threads:[~2021-02-18 17:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-17  4:03 bug#46583: 28.0.50; nested minibuffers Richard Stallman
2021-02-17 18:48 ` Juri Linkov
2021-02-17 19:46   ` Eli Zaretskii
2021-02-17 20:20     ` Juri Linkov
2021-02-17 20:35       ` Eli Zaretskii
2021-02-18  9:39         ` Juri Linkov
2021-02-18 14:31           ` Eli Zaretskii
2021-02-18 17:17             ` Juri Linkov [this message]
2021-02-19  5:41   ` Richard Stallman
2022-06-17 15:23   ` Lars Ingebrigtsen
2022-06-17 19:20     ` Juri Linkov
2022-06-18 11:33       ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tuq9fmpi.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=46583@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=rms@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).