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: Sat, 17 Apr 2021 22:16:16 +0000	[thread overview]
Message-ID: <1869622e16dc36c3f2fd@heytings.org> (raw)
In-Reply-To: <jwvk0p04mbj.fsf-monnier+emacs@gnu.org>

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


>> What's wrong with my approach, which disables the completion backend on 
>> demand?
>
> [ I'm not sure which is "your approach", sorry.  ]
>

See the attached patch.  I's a draft, as I said 
read-from-minibuffer-simple could probably renamed to something more 
elegant, and (at least some of) the other calls to read-from-minibuffer 
could be replaced by the macro.

>> A variant of it would be to add an eight argument to 
>> read-from-minibuffer.  AFAICS it's only the caller that can know 
>> whether the completion backend should be used, IOW, the only thing that 
>> the completion backend can do is to obey the caller.
>
> We should think hard before adding yet another argument.
>

Yes ;-)  Which is why I did not do that.

>
> I agree that the current design is problematic.  Basically, I think that 
> `minibuffer-completion-table` should be set buffer-locally in the 
> minibuffer instead of being "set" by dynamic scoping.
>
> Fixing the problem "right" might call for a significant redesign of 
> `read-from-minibuffer`s API and `completing-read`s implementation.
>
> A quick&dirty workaround for now would be for `completing-read` to set 
> some var alongside `minibuffer-completion-table` which indicates *which* 
> minibuffer this is for (e.g. some minibuffer-depth information). This 
> way `read-from-minibuffer` could distinguish a 
> `minibuffer-completion-table` passed for the current invocation from one 
> passed for the outer invocation and could hence temporarily rebind 
> `minibuffer-completion-table` to nil.
>
> Another approach would be for `completing-read` not to let-bind those 
> vars but instead to use `minibuffer-setup-hook` to set the vars 
> buffer-locally.
>

These are yet other possible approaches indeed, but it seems to me at 
first sight that they are more complex than the solution I suggest.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-diff; name=Make-it-possible-to-disable-a-completion-backend-in-.patch, Size: 4780 bytes --]

From 99050c96e7ff522aa1b180920fac74e98a2d6c79 Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
Date: Thu, 15 Apr 2021 23:50:24 +0000
Subject: [PATCH] Make it possible to disable a completion backend in recursive
 minibuffers

* lisp/subr.el (read-from-minibuffer-simple): New macro.
(disable-for-read-from-minibuffer-simple): New macro.
(read-from-minibuffer-simple): New internal variable.
(read-number, read-char-from-minibuffer, y-or-n-p): Use the new macro

* lisp/simple.el (read--expression): Use the new macro.

* lisp/icomplete.el (icomplete-minibuffer-setup): Use the new macro.
---
 lisp/icomplete.el |  1 +
 lisp/simple.el    |  6 +++---
 lisp/subr.el      | 28 ++++++++++++++++++++++++----
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index d5b6f76d7b..76313eb91d 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -446,6 +446,7 @@ icomplete-simple-completing-p
 (defun icomplete-minibuffer-setup ()
   "Run in minibuffer on activation to establish incremental completion.
 Usually run by inclusion in `minibuffer-setup-hook'."
+  (disable-for-read-from-minibuffer-simple icomplete-mode)
   (when (and icomplete-mode (icomplete-simple-completing-p))
     (setq-local icomplete--initial-input (icomplete--field-string))
     (setq-local completion-show-inline-help nil)
diff --git a/lisp/simple.el b/lisp/simple.el
index 999755a642..7a0953a939 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1755,9 +1755,9 @@ read--expression
           (add-hook 'completion-at-point-functions
                     #'elisp-completion-at-point nil t)
           (run-hooks 'eval-expression-minibuffer-setup-hook))
-      (read-from-minibuffer prompt initial-contents
-                            read-expression-map t
-                            'read-expression-history))))
+      (read-from-minibuffer-simple prompt initial-contents
+                                   read-expression-map t
+                                   'read-expression-history))))
 
 (defun read--expression-try-read ()
   "Try to read an Emacs Lisp expression in the minibuffer.
diff --git a/lisp/subr.el b/lisp/subr.el
index c2be26a15f..d2230f6034 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2791,6 +2791,26 @@ read-passwd
               ;; And of course, don't keep the sensitive data around.
               (erase-buffer))))))))
 
+(defvar read-from-minibuffer-simple nil
+  "Whether `read-from-minibuffer' should display completion candidates.")
+
+(defmacro read-from-minibuffer-simple (&rest body)
+  "Read a string from the minibuffer without completion.
+Set `read-from-minibuffer-simple' to t, and call `read-from-minibuffer',
+which see."
+  `(progn
+     (setq read-from-minibuffer-simple t)
+     (read-from-minibuffer ,@body)))
+
+(defmacro disable-for-read-from-minibuffer-simple (completion-mode)
+  "Set COMPLETION-MODE to nil for `read-from-minibuffer-simple'.
+This is meant to be used by completion backends to setup the minibuffer
+to conditionally activate completion in each recursive invocation of
+the minibuffer, without affecting other recursive invocations."
+  `(when read-from-minibuffer-simple
+     (setq-local ,completion-mode nil)
+     (setq read-from-minibuffer-simple nil)))
+
 (defvar read-number-history nil
   "The default history for the `read-number' function.")
 
@@ -2812,7 +2832,7 @@ read-number
 					prompt t t))))
     (while
 	(progn
-	  (let ((str (read-from-minibuffer
+	  (let ((str (read-from-minibuffer-simple
 		      prompt nil nil nil (or hist 'read-number-history)
 		      (when default
 			(if (consp default)
@@ -3052,8 +3072,8 @@ read-char-from-minibuffer
          ;; Protect this-command when called from pre-command-hook (bug#45029)
          (this-command this-command)
          (result
-          (read-from-minibuffer prompt nil map nil
-                                (or history 'empty-history)))
+          (read-from-minibuffer-simple prompt nil map nil
+                                       (or history 'empty-history)))
          (char
           (if (> (length result) 0)
               ;; We have a string (with one character), so return the first one.
@@ -3247,7 +3267,7 @@ y-or-n-p
                        map))
              ;; Protect this-command when called from pre-command-hook (bug#45029)
              (this-command this-command)
-             (str (read-from-minibuffer
+             (str (read-from-minibuffer-simple
                    prompt nil keymap nil
                    (or y-or-n-p-history-variable 'empty-history))))
         (setq answer (if (member str '("y" "Y")) 'act 'skip)))))
-- 
2.30.2


  reply	other threads:[~2021-04-17 22:16 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 [this message]
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
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=1869622e16dc36c3f2fd@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).