From: Spencer Baugh via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 74772@debbugs.gnu.org, monnier@iro.umontreal.ca
Subject: bug#74772: [PATCH] Consistently add wildcards for completion-pcm-leading-wildcard
Date: Tue, 10 Dec 2024 15:05:12 -0500 [thread overview]
Message-ID: <ier34iv483r.fsf@janestreet.com> (raw)
In-Reply-To: <86wmg79vjd.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 10 Dec 2024 21:40:06 +0200")
[-- Attachment #1: Type: text/plain, Size: 1077 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Spencer Baugh <sbaugh@janestreet.com>
>> Cc: 74772@debbugs.gnu.org, monnier@iro.umontreal.ca
>> Date: Tue, 10 Dec 2024 14:14:15 -0500
>>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>> >> Cc: Stefan Monnier <monnier@iro.umontreal.ca>
>> >> Date: Tue, 10 Dec 2024 12:48:23 -0500
>> >> From: Spencer Baugh via "Bug reports for GNU Emacs,
>> >> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>> >>
>> >> (defcustom completion-pcm-leading-wildcard nil
>> >> - "If non-nil, partial-completion completes as if there's a leading wildcard.
>> >> + "If non-nil, partial-completion adds a leading wildcard for each word.
>> >
>> > The modified wording is misleading, because it says something that
>> > doesn't really happen (as the rest of the doc string reveals).
>>
>> Okay, how about:
>>
>> If non-nil, PCM completes as if there's a wildcard before each word.
>
> Much better, thanks. You could even say
>
> If non-nil, partial-completion behaves as if each word is preceded by wildcard.
Ok, updated patch:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Consistently-add-wildcards-for-completion-pcm-leadin.patch --]
[-- Type: text/x-patch, Size: 4137 bytes --]
From 09d8d74cabe7157d5e8e89e82b7e8bb9129ca007 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
Date: Tue, 10 Dec 2024 12:41:49 -0500
Subject: [PATCH] Consistently add wildcards for
completion-pcm-leading-wildcard
completion-pcm--find-all-completions has two different phases:
First we turn the minibuffer text into a regex and matches
completion alternatives against it. If that finds no matches,
then we strip some text off the completions and minibuffer text
and call ourselves recursively to find completions, then filter
the results with the removed text (converted into a regex).
Because of this, completion-pcm-leading-wildcard had
inconsistent behavior: in the second phase, the filter created
from the removed text would have a leading wildcard. That
effectively adds wildcards in the middle of the minibuffer text
at the start of each "word". But the first phrase created a
regex which had no such wildcards. Thus, the two phases could
get substantially different results.
We fix this by changing completion-pcm-leading-wildcard to
consistently add a leading wildcard for each word. This was
always my intention.
* lisp/minibuffer.el (completion-pcm--string->pattern): Include
a wildcard after each delimter with
completion-pcm-leading-wildcard. (bug#74772)
* lisp/minibuffer.el (completion-pcm-leading-wildcard): Update
docs.
* doc/emacs/mini.texi (Completion Styles): Update docs.
---
doc/emacs/mini.texi | 6 +++---
lisp/minibuffer.el | 17 +++++++++--------
2 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/doc/emacs/mini.texi b/doc/emacs/mini.texi
index 0fcd24ed79d..8e0d58d0f7c 100644
--- a/doc/emacs/mini.texi
+++ b/doc/emacs/mini.texi
@@ -577,9 +577,9 @@ Completion Styles
@vindex completion-pcm-leading-wildcard
If @code{completion-pcm-leading-wildcard} is set to @code{t}, this style
-always acts as if a @dfn{wildcard} is present at the start of the
-minibuffer text, similar to the @code{substring} style. For example,
-@samp{l-m} will complete to @samp{emacs-lisp-mode}.
+always acts as if a @dfn{wildcard} is present at the start of each word
+in the minibuffer text, similar to the @code{substring} style. For
+example, @samp{l-ode} will complete to @samp{emacs-lisp-mode}.
@item emacs22
@cindex @code{emacs22}, completion style
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 2d27fef44ab..a695e4f9f73 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -3996,17 +3996,18 @@ completion-pcm--pattern-trivial-p
trivial)))
(defcustom completion-pcm-leading-wildcard nil
- "If non-nil, partial-completion completes as if there's a leading wildcard.
+ "If non-nil, partial-completion behaves as if each word is preceded by wildcard.
-If nil (the default), partial-completion requires a matching completion
-alternative to have the same beginning as the first \"word\" in the
-minibuffer text, where \"word\" is determined by
+If nil (the default), partial-completion requires each word in a
+matching completion alternative to have the same beginning as each
+\"word\" in the minibuffer text, where \"word\" is determined by
`completion-pcm-word-delimiters'.
If non-nil, partial-completion allows any string of characters to occur
-at the beginning of a completion alternative, as if a wildcard such as
-\"*\" was present at the beginning of the minibuffer text. This makes
-partial-completion behave more like the substring completion style."
+at the beginning of each word in a completion alternative, as if a
+wildcard such as \"*\" was present at the beginning of each word. This
+makes partial-completion behave more like the substring completion
+style."
:version "31.1"
:type 'boolean)
@@ -4053,7 +4054,7 @@ completion-pcm--string->pattern
(setq p0 p)
(push (substring string p (match-end 0)) pattern)
;; `any-delim' is used so that "a-b" also finds "array->beginning".
- (setq pending 'any-delim)
+ (setq pending (if completion-pcm-leading-wildcard 'prefix 'any-delim))
(setq p0 (match-end 0))))
(setq p p0))
--
2.39.3
prev parent reply other threads:[~2024-12-10 20:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 17:48 bug#74772: [PATCH] Consistently add wildcards for completion-pcm-leading-wildcard Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-10 19:02 ` Eli Zaretskii
2024-12-10 19:14 ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-10 19:40 ` Eli Zaretskii
2024-12-10 20:05 ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
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=ier34iv483r.fsf@janestreet.com \
--to=bug-gnu-emacs@gnu.org \
--cc=74772@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=sbaugh@janestreet.com \
/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).