unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Gregory Heytings <gregory@heytings.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Dario Gjorgjevski <dario.gjorgjevski@gmail.com>,
	45474@debbugs.gnu.org, Juri Linkov <juri@linkov.net>
Subject: bug#45474: Icomplete exhibiting in recursive minibuffer when it shouldn’t
Date: Thu, 22 Apr 2021 20:57:25 +0000	[thread overview]
Message-ID: <a87041afcb2ed01ceec6@heytings.org> (raw)
In-Reply-To: <a87041afcbf49f2f8586@heytings.org>

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


>>>>    run_hook (Qminibuffer_setup_hook);
>>> 
>>> As in my patch, you could use this hook to do the completion-specific 
>>> part of the setup.
>> 
>> Indeed, but you said that 'minibuffer-with-setup-hook' is 
>> "fundamentally broken and messy"...
>
> I forgot to add that if the idea is to change the semantics of 
> read-from-minibuffer in the long term, this must happen inside 
> read-from-minibuffer, not with a minibuffer-with-setup-hook around 
> read-from-minibuffer.  What would be possible here (I think) is to move 
> this piece of code in a minibuffer-with-setup-hook inside the 
> read-from-minibuffer macro.
>

And here is the patch which does this, in case you prefer it.  AFAICS it 
is functionally equivalent to the other one.

[-- Attachment #2: Type: text/x-diff, Size: 6301 bytes --]

From edd46c1a2df6dea2154eb893da51eca1abd2da83 Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
Date: Thu, 22 Apr 2021 20:51:52 +0000
Subject: [PATCH] Make it possible to disable a completion backend in recursive
 minibuffers

---
 lisp/minibuffer.el |  3 ++-
 lisp/subr.el       | 34 ++++++++++++++++++++++++++++++++++
 src/fns.c          |  6 +++---
 src/minibuf.c      | 20 ++++++++++++++------
 4 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 7da3c39e6b..379dadef9d 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -3884,7 +3884,8 @@ completing-read-default
                 ;; `read-from-minibuffer' uses 1-based index.
                 (1+ (cdr initial-input)))))
 
-  (let* ((minibuffer-completion-table collection)
+  (let* ((minibuffer-local-completion t)
+         (minibuffer-completion-table collection)
          (minibuffer-completion-predicate predicate)
          ;; FIXME: Remove/rename this var, see the next one.
          (minibuffer-completion-confirm (unless (eq require-match t)
diff --git a/lisp/subr.el b/lisp/subr.el
index c2be26a15f..972422f343 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2791,6 +2791,40 @@ read-passwd
               ;; And of course, don't keep the sensitive data around.
               (erase-buffer))))))))
 
+(defvar minibuffer-local-completion nil
+  "Whether minibuffer completion elements should become buffer-local.
+The default is nil for Emacs 28.  Setting this variable in Emacs 29 will
+have no effect; the value t will be assumed.
+When t, `minibuffer-completion-table', `minibuffer-completion-predicate'
+and `minibuffer-completion-confirm' become buffer-local upon entering the
+minibuffer, and are nil in recursive invocations of the minibuffer, unless
+they have been let-bound to a value.
+When nil, their values is shared between the recursive invocations of the
+minibuffer, unless they have been let-bound to another value.")
+
+(defmacro read-from-minibuffer (&rest body)
+  "Read a string from the minibuffer with `internal-read-from-minibuffer'.
+See `internal-read-from-minibuffer' for a description of the arguments.
+This macro exists only in Emacs 28, for the transition period during which
+the default value of `minibuffer-local-completion' is nil, and will be
+removed in Emacs 29.  Likewise, `internal-read-from-minibuffer' will be
+removed in Emacs 29, please do not use it directly."
+  `(if minibuffer-local-completion
+       (let ((minibuffer-local-c-t minibuffer-completion-table)
+             (minibuffer-local-c-p minibuffer-completion-predicate)
+             (minibuffer-local-c-c minibuffer-completion-confirm))
+         (let ((minibuffer-completion-table nil)
+               (minibuffer-completion-predicate nil)
+               (minibuffer-completion-confirm nil))
+           (minibuffer-with-setup-hook
+               (lambda ()
+                 (setq-local minibuffer-completion-table minibuffer-local-c-t
+                             minibuffer-completion-predicate minibuffer-local-c-p
+                             minibuffer-completion-confirm minibuffer-local-c-c)
+                 (setq minibuffer-local-completion nil))
+             (internal-read-from-minibuffer ,@body))))
+     (internal-read-from-minibuffer ,@body)))
+
 (defvar read-number-history nil
   "The default history for the `read-number' function.")
 
diff --git a/src/fns.c b/src/fns.c
index 1758148ff2..db6679a847 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -2985,9 +2985,9 @@ DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 1, 0,
 
   while (1)
     {
-      ans = Fdowncase (Fread_from_minibuffer (prompt, Qnil, Qnil, Qnil,
-					      Qyes_or_no_p_history, Qnil,
-					      Qnil));
+      ans = Fdowncase (Finternal_read_from_minibuffer (prompt, Qnil, Qnil, Qnil,
+						       Qyes_or_no_p_history, Qnil,
+						       Qnil));
       if (SCHARS (ans) == 3 && !strcmp (SSDATA (ans), "yes"))
 	return unbind_to (count, Qt);
       if (SCHARS (ans) == 2 && !strcmp (SSDATA (ans), "no"))
diff --git a/src/minibuf.c b/src/minibuf.c
index 1a637c86ad..90f329ddb2 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -1231,9 +1231,17 @@ barf_if_interaction_inhibited (void)
     xsignal0 (Qinhibited_interaction);
 }
 
-DEFUN ("read-from-minibuffer", Fread_from_minibuffer,
-       Sread_from_minibuffer, 1, 7, 0,
+DEFUN ("internal-read-from-minibuffer", Finternal_read_from_minibuffer,
+       Sinternal_read_from_minibuffer, 1, 7, 0,
        doc: /* Read a string from the minibuffer, prompting with string PROMPT.
+
+Warning: Do not use this function directly, use `read-from-minibuffer'
+instead, with the arguments described below.  The `read-from-minibuffer'
+macro exists only in Emacs 28 for the transition period during which the
+default value of `minibuffer-local-completion' is nil, it will be removed
+in Emacs 29, and `internal--read-from-minibuffer' will become
+`read-from-minibuffer' again.
+
 The optional second arg INITIAL-CONTENTS is an obsolete alternative to
   DEFAULT-VALUE.  It normally should be nil in new code, except when
   HIST is a cons.  It is discussed in more detail below.
@@ -1352,9 +1360,9 @@ DEFUN ("read-string", Fread_string, Sread_string, 1, 5, 0,
      FIXME: `minibuffer-completion-table' should be buffer-local instead.  */
   specbind (Qminibuffer_completion_table, Qnil);
 
-  val = Fread_from_minibuffer (prompt, initial_input, Qnil,
-			       Qnil, history, default_value,
-			       inherit_input_method);
+  val = Finternal_read_from_minibuffer (prompt, initial_input, Qnil,
+				        Qnil, history, default_value,
+				        inherit_input_method);
   if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (default_value))
     val = CONSP (default_value) ? XCAR (default_value) : default_value;
   return unbind_to (count, val);
@@ -2487,7 +2495,7 @@ syms_of_minibuf (void)
 
   defsubr (&Sactive_minibuffer_window);
   defsubr (&Sset_minibuffer_window);
-  defsubr (&Sread_from_minibuffer);
+  defsubr (&Sinternal_read_from_minibuffer);
   defsubr (&Sread_string);
   defsubr (&Sread_command);
   defsubr (&Sread_variable);
-- 
2.30.2


  reply	other threads:[~2021-04-22 20:57 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-27 17:44 bug#45474: Icomplete exhibiting in recursive minibuffer when it shouldn’t Dario Gjorgjevski
2021-04-15 17:40 ` Gregory Heytings
2021-04-15 21:11   ` Juri Linkov
2021-04-15 22:34     ` Gregory Heytings
2021-04-16  0:03       ` Gregory Heytings
2021-04-16 16:34         ` Juri Linkov
2021-04-16 16:55           ` Gregory Heytings
2021-04-17 20:49             ` Juri Linkov
2021-04-17 21:35               ` Gregory Heytings
2021-04-17 21:58                 ` Stefan Monnier
2021-04-17 22:16                   ` Gregory Heytings
2021-04-18 14:44                     ` Stefan Monnier
2021-04-18 22:23                       ` Gregory Heytings
2021-04-19  1:26                         ` Stefan Monnier
2021-04-19 12:14                           ` Gregory Heytings
2021-04-19 15:57                             ` Stefan Monnier
2021-04-19 20:20                               ` Gregory Heytings
2021-04-17 23:21                   ` bug#45474: [External] : " Drew Adams
2021-04-18  3:59                     ` Stefan Monnier
2021-04-18  4:04                       ` Drew Adams
2021-04-18  5:08                         ` Stefan Monnier
2021-04-18 15:42                           ` Drew Adams
2021-04-18 18:35                             ` Stefan Monnier
2021-04-18 20:11                               ` Drew Adams
2021-04-18 20:53                                 ` Stefan Monnier
2021-04-18 23:46                                   ` Drew Adams
2021-04-22 15:03                                     ` Stefan Monnier
2021-04-19 18:16                   ` Juri Linkov
2021-04-19 21:42                     ` Stefan Monnier
2021-04-20 19:00                       ` Gregory Heytings
2021-04-22 13:56                         ` Stefan Monnier
2021-04-22 14:08                           ` Gregory Heytings
2021-04-20 19:01                       ` Juri Linkov
2021-04-22 13:54                         ` Stefan Monnier
2021-04-22 14:13                           ` Stefan Monnier
2021-04-22 14:18                             ` Gregory Heytings
2021-04-22 15:18                               ` Gregory Heytings
2021-04-22 18:36                                 ` Stefan Monnier
2021-04-22 19:04                                   ` Gregory Heytings
2021-04-22 19:59                                     ` Gregory Heytings
2021-04-22 20:57                                       ` Gregory Heytings [this message]
2021-04-22 23:24                                     ` Stefan Monnier
2021-04-23  6:06                                       ` Eli Zaretskii
2021-04-23 13:12                                         ` Stefan Monnier
2021-04-23 13:19                                           ` Eli Zaretskii
2021-04-23 15:18                                             ` Stefan Monnier
2021-04-23 17:37                                               ` Eli Zaretskii
2021-04-23  6:59                                       ` Gregory Heytings
2021-04-23 13:21                                         ` Stefan Monnier
2021-04-23 13:45                                           ` Gregory Heytings
2021-04-23 15:35                                             ` Stefan Monnier
2021-04-23 15:58                                               ` Gregory Heytings
2021-04-23 16:36                                                 ` Juri Linkov
2021-04-23 16:55                                                 ` Stefan Monnier
2021-04-23 18:13                                                   ` Gregory Heytings
2021-04-23 20:24                                                     ` Stefan Monnier
2021-04-23 21:36                                                       ` Gregory Heytings
2021-04-23 21:54                                                         ` Stefan Monnier
2021-04-24  8:44                                                           ` Gregory Heytings
2021-05-01 19:34                                                             ` Stefan Monnier
2021-05-03  8:40                                                               ` Gregory Heytings
2022-06-07 12:04                                                                 ` Lars Ingebrigtsen
2021-04-22 21:57                             ` Juri Linkov
2021-04-23 15:53                               ` Stefan Monnier

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=a87041afcb2ed01ceec6@heytings.org \
    --to=gregory@heytings.org \
    --cc=45474@debbugs.gnu.org \
    --cc=dario.gjorgjevski@gmail.com \
    --cc=juri@linkov.net \
    --cc=monnier@iro.umontreal.ca \
    /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).