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, 24 Apr 2021 08:44:38 +0000 [thread overview]
Message-ID: <7ee648e8400708d266ed@heytings.org> (raw)
In-Reply-To: <jwvbla44qoy.fsf-monnier+emacs@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1279 bytes --]
>> Aren't these problems orthogonal to the problem at hand? It seems to
>> me that this is not different from the traditional way of passing
>> arguments to a function; of course something unexpected can happen when
>> they are evaluated, before the function is entered, but that's
>> something outside the responsibility of the function.
>
> No, the problem is not "can someone change `minibuffer-completion-table`
> before we get to its intended consumer" but "will the let-binding of
> `minibuffer-completion-table` also affect code which was not the
> intended consumer". This problem does not exist with
> traditional/explicit argument passing.
>
Again, it seems to me that this problem is not directly related to the
problem at hand. If the caller of read-from-minibuffer is not careful
enough and binds minibuffer-completion-* too far from the call, in such a
way that other code is unexpectedly affected (or could unexpectedly be
affected) by this binding, it's the responsibility of that caller to fix
that problem.
Anyway, I attach a last version of my patch, in which all the dancing
happens at the C level. It is probably also possible to finally get rid
of the 15 lines with the minibuffer-completing-file-name = Qlambda hack in
read_minibuf().
[-- 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: 5859 bytes --]
From 33dcdd6ea992e88614baa77b42c3e53bf9f6a08a Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
Date: Sat, 24 Apr 2021 08:43:45 +0000
Subject: [PATCH] Make it possible to disable a completion backend in recursive
minibuffers
---
lisp/minibuffer.el | 3 ++-
src/minibuf.c | 49 ++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 47 insertions(+), 5 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/src/minibuf.c b/src/minibuf.c
index c4482d7f1e..d0b804cdff 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -68,6 +68,9 @@ Copyright (C) 1985-1986, 1993-2021 Free Software Foundation, Inc.
/* Width of current mini-buffer prompt. Only set after display_line
of the line that contains the prompt. */
+static Lisp_Object minibuffer_completion_table, minibuffer_completion_predicate,
+ minibuffer_completion_confirm;
+
static ptrdiff_t minibuf_prompt_width;
static Lisp_Object nth_minibuffer (EMACS_INT depth);
@@ -862,6 +865,16 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
if (STRINGP (input_method) && !NILP (Ffboundp (Qactivate_input_method)))
call1 (Qactivate_input_method, input_method);
+ if (! EQ (Vminibuffer_local_completion, Qnil)) {
+ Fmake_local_variable (Qminibuffer_completion_table);
+ Fset (Qminibuffer_completion_table, minibuffer_completion_table);
+ Fmake_local_variable (Qminibuffer_completion_predicate);
+ Fset (Qminibuffer_completion_predicate, minibuffer_completion_predicate);
+ Fmake_local_variable (Qminibuffer_completion_confirm);
+ Fset (Qminibuffer_completion_confirm, minibuffer_completion_confirm);
+ Vminibuffer_local_completion = Qnil;
+ }
+
run_hook (Qminibuffer_setup_hook);
/* Don't allow the user to undo past this point. */
@@ -1291,6 +1304,7 @@ DEFUN ("read-from-minibuffer", Fread_from_minibuffer,
(Lisp_Object prompt, Lisp_Object initial_contents, Lisp_Object keymap, Lisp_Object read, Lisp_Object hist, Lisp_Object default_value, Lisp_Object inherit_input_method)
{
Lisp_Object histvar, histpos, val;
+ ptrdiff_t count;
barf_if_interaction_inhibited ();
@@ -1315,11 +1329,25 @@ DEFUN ("read-from-minibuffer", Fread_from_minibuffer,
if (NILP (histpos))
XSETFASTINT (histpos, 0);
+ count = SPECPDL_INDEX ();
+
+ if (! EQ (Vminibuffer_local_completion, Qnil)) {
+ minibuffer_completion_table = Vminibuffer_completion_table;
+ minibuffer_completion_predicate = Vminibuffer_completion_predicate;
+ minibuffer_completion_confirm = Vminibuffer_completion_confirm;
+ specbind (Qminibuffer_completion_table, Qnil);
+ specbind (Qminibuffer_completion_predicate, Qnil);
+ specbind (Qminibuffer_completion_confirm, Qnil);
+ }
+
val = read_minibuf (keymap, initial_contents, prompt,
!NILP (read),
histvar, histpos, default_value,
minibuffer_allow_text_properties,
!NILP (inherit_input_method));
+
+ unbind_to (count, Qnil);
+
return val;
}
@@ -1345,11 +1373,9 @@ DEFUN ("read-string", Fread_string, Sread_string, 1, 5, 0,
Lisp_Object val;
ptrdiff_t count = SPECPDL_INDEX ();
- /* Just in case we're in a recursive minibuffer, make it clear that the
- previous minibuffer's completion table does not apply to the new
- minibuffer.
- FIXME: `minibuffer-completion-table' should be buffer-local instead. */
specbind (Qminibuffer_completion_table, Qnil);
+ specbind (Qminibuffer_completion_predicate, Qnil);
+ specbind (Qminibuffer_completion_confirm, Qnil);
val = Fread_from_minibuffer (prompt, initial_input, Qnil,
Qnil, history, default_value,
@@ -2281,6 +2307,9 @@ syms_of_minibuf (void)
Fset (Qminibuffer_default, Qnil);
DEFSYM (Qminibuffer_completion_table, "minibuffer-completion-table");
+ DEFSYM (Qminibuffer_completion_predicate, "minibuffer-completion-predicate");
+ DEFSYM (Qminibuffer_completion_confirm, "minibuffer-completion-confirm");
+ DEFSYM (Qminibuffer_local_completion, "minibuffer-local-completion");
staticpro (&last_minibuf_string);
@@ -2414,6 +2443,18 @@ syms_of_minibuf (void)
completion commands listed in `minibuffer-confirm-exit-commands'. */);
Vminibuffer_completion_confirm = Qnil;
+ DEFVAR_LISP ("minibuffer-local-completion", Vminibuffer_local_completion,
+ doc: /* 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. */);
+ Vminibuffer_local_completion = Qnil;
+
DEFVAR_LISP ("minibuffer-completing-file-name",
Vminibuffer_completing_file_name,
doc: /* Non-nil means completing file names. */);
--
2.30.2
next prev parent reply other threads:[~2021-04-24 8:44 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
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 [this message]
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=7ee648e8400708d266ed@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).