From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.bugs Subject: bug#70217: [PATCH] Add substring-partial-completion style Date: Sat, 25 May 2024 17:22:14 -0400 Message-ID: References: <86a5kpgdo7.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32420"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 70217@debbugs.gnu.org, monnier@iro.umontreal.ca To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat May 25 23:23:24 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sAyrL-0008CC-17 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 25 May 2024 23:23:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sAyqt-0000nE-Sd; Sat, 25 May 2024 17:22:55 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sAyqs-0000n5-Tn for bug-gnu-emacs@gnu.org; Sat, 25 May 2024 17:22:54 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sAyqs-00053m-Fk for bug-gnu-emacs@gnu.org; Sat, 25 May 2024 17:22:54 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sAyqz-0003Bf-TS for bug-gnu-emacs@gnu.org; Sat, 25 May 2024 17:23:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 25 May 2024 21:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70217 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 70217-submit@debbugs.gnu.org id=B70217.171667215012209 (code B ref 70217); Sat, 25 May 2024 21:23:01 +0000 Original-Received: (at 70217) by debbugs.gnu.org; 25 May 2024 21:22:30 +0000 Original-Received: from localhost ([127.0.0.1]:47599 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sAyqT-0003Aq-Sw for submit@debbugs.gnu.org; Sat, 25 May 2024 17:22:30 -0400 Original-Received: from mxout6.mail.janestreet.com ([64.215.233.21]:33431) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sAyqS-0003Ad-25 for 70217@debbugs.gnu.org; Sat, 25 May 2024 17:22:28 -0400 In-Reply-To: <86a5kpgdo7.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 17 May 2024 09:23:04 +0300") DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1716672134; bh=Zq1MPXvvPqBSN0pGxCFnzTTQxspLQEu/lJYiyRCxBW8=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=WOTz/qokE9zIrBDAG8XBYvnH08kkkgovbHAMovlibKxU1HDO7oNpStjESq1Nu9vNj Z3t49LzPtzk5oB7eqaearb+HkcvW9KQpwkvNyUooDqa/146OIRoE0KVZKrprPfYKqq UfiG7Elx6QtZfgms6NR5QrzrQUpQZF2CTp/j4FsRxNsnTmzMepZvakswhZHh/K94qi cW4WUMmDU8AP9onJaCQx5g2k+tEMKmee0HM90oX7O/1NCD2JewoRY995nHRg2MWjQD 1q6V+itQLK5woPFNIFoku97m1Hz7UH1Cctqd/A1t6WSlmZp5eCfpukg94oxI5i+5f4 osOZPp3O/Xwgg== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:285912 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> Cc: 70217@debbugs.gnu.org >> From: Spencer Baugh >> Date: Thu, 16 May 2024 16:26:32 -0400 >> >> +(defcustom completion-pcm-anchored t >> + "If nil, the partial-completion style expands at the start of a string. > > How can a style "expand at the start of a string"? This sentence > needs to be reworded to tell the effect of the variable more clear. > >> +If non-nil, then expansion at the start of a string only happens >> +if the string begins with a wildcard. > > What is a "wildcard" in this context? > > This is a user option, so the doc string should be understandable by > users, not just by Lisp programmers who tinker with completion stuff. OK, reworded that docstring heavily. Maybe it's better now? > > Also, this new option should be in NEWS, I think. Added to NEWS and documentation, and the same for the new possible values of completion-styles. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Allow-customizing-partial-completion-to-be-more-like.patch >From d042041accf927b6425a5e0331b19facbff20983 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Sat, 25 May 2024 16:29:43 -0400 Subject: [PATCH] Allow customizing partial-completion to be more like substring The substring completion style completes "foo-bar" as "*foo-bar*". The partial-completion completion style completes "foo-bar" as "foo*bar*". Previously, it was not possible to get completion of "foo-bar" to act as "*foo*bar*", e.g. combining the partial-completion and substring styles. This would be especially useful for things like project-find-file. Now it is possible by customizing the completion-pcm-anchored variable to a non-nil value. Furthermore, it's convenient to be able to run regular (completion-pcm-anchored=t, non-substring) partial-completion before running completion-pcm-anchored=nil partial-completion, since the former provides more narrowly targeted completions. It's possible to do this by customizing completion-styles. Just add '(partial-completion ((completion-pcm-anchored t))) and '(partial-completion ((completion-pcm-anchored nil))) in that order. Then the completion machinery will first run partial-completion with completion-pcm-anchored=t, and if that returns no completions, run partial-completion with completion-pcm-anchored=nil. * lisp/minibuffer.el (completion--nth-completion): Allow an element of completion-styles to contain a list of bindings. (completion-styles): Document that. (completion-pcm-anchored): Add. (completion-pcm--string->pattern): Check completion-pcm-anchored. (bug#70217) --- doc/emacs/mini.texi | 17 ++++++++++-- etc/NEWS | 20 ++++++++++++++ lisp/minibuffer.el | 63 +++++++++++++++++++++++++++++++++++++++------ 3 files changed, 90 insertions(+), 10 deletions(-) diff --git a/doc/emacs/mini.texi b/doc/emacs/mini.texi index 4557f41c3f7..2e9766eb50c 100644 --- a/doc/emacs/mini.texi +++ b/doc/emacs/mini.texi @@ -535,8 +535,14 @@ Completion Styles @vindex completion-styles The list variable @code{completion-styles} specifies the completion -styles to use. Each list element is the name of a completion style (a -Lisp symbol). The available style symbols are stored in the variable +styles to use. Each list element is either the name of a completion +style (a Lisp symbol) or a list starting with the name of a completion +style followed by @code{let}-style list of bindings which will be in +effect for that completion style. Multiple elements of +@code{completion-styles} can name the same completion style with +different variable bindings. + +The available style symbols are stored in the variable @code{completion-styles-alist} (@pxref{Completion Variables,,, elisp, The Emacs Lisp Reference Manual}). The default completion styles are (in order): @@ -561,6 +567,13 @@ Completion Styles @dfn{wildcard}---it matches any string of characters at the corresponding position in the completion alternative. +@vindex completion-pcm-anchored +By default, a matching completion alternative must have the same +beginning as the first word of the minibuffer text, but if +@code{completion-pcm-anchored} is nil, the first word of the minibuffer +text can start anywhere in a completion alternative. For example, +@samp{l-m} completes to @samp{emacs-lisp-mode}. + @item emacs22 @cindex @code{emacs22}, completion style This completion style is similar to @code{basic}, except that it diff --git a/etc/NEWS b/etc/NEWS index d058acc3572..be59cf37ad0 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1848,6 +1848,26 @@ customization group control exactly when Emacs displays this preview. 'completion-preview-mode' is buffer-local, to enable it globally use 'global-completion-preview-mode'. ++++ +*** New user option 'completion-pcm-anchored'. +This option configures how the partial-completion style does completion. +It defaults to t, which preserves the existing behavior. When it is set +to nil, the partial-completion style behaves more like the substring +style, in that a string being completed can match against a candidate +anywhere in the candidate string. + ++++ +*** 'completion-styles' now can contain lists of bindings +An element of 'completion-styles' can be a symbol naming a completion +style in 'completion-styles-alist'. Now it can also be a list of the +form '(style ((variable value) ...))' where style is a symbol naming a +completion style. 'variable' will be bound to 'value' (without +evaluating it) while the style is executing. This allows duplicating a +completion style with different values for completion-affecting +variables like 'completion-pcm-anchored' or 'completion-ignore-case'. +This also applies for the styles configuration in +'completion-category-overrides' and 'completion-category-defaults'. + --- ** The highly accessible Modus themes collection has eight items. The 'modus-operandi' and 'modus-vivendi' are the main themes that have diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index f62cb2566b2..10bab12b3ba 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1141,10 +1141,22 @@ completion-styles ;; and simply add "bar" to the end of the result. emacs22) "List of completion styles to use. -The available styles are listed in `completion-styles-alist'. +An element should be a symbol which is listed in +`completion-styles-alist'. + +An element can also be a list of the form \"(style ((variable value) +...))\". \"style\" must be a symbol listed in +`completion-styles-alist', followed by a `let'-style list of +variable/value pairs. \"variable\" will be bound to \"value\" (without +evaluating it) while the style is handling completion. This allows +repeating the same style with different configurations. Note that `completion-category-overrides' may override these -styles for specific categories, such as files, buffers, etc." +styles for specific categories, such as files, buffers, etc. + +Note that Tramp host name completion (e.g., \"/ssh:ho\") +currently doesn't work if this list doesn't contain at least one +of `basic', `emacs22' or `emacs21'." :type completion--styles-type :version "23.1") @@ -1284,11 +1296,18 @@ completion--nth-completion (result-and-style (seq-some (lambda (style) - (let ((probe (funcall - (or (nth n (assq style completion-styles-alist)) - (error "Invalid completion style %s" style)) - string table pred point))) - (and probe (cons probe style)))) + (let (symbols values) + (when (consp style) + (dolist (binding (cadr style)) + (push (car binding) symbols) + (push (cadr binding) values)) + (setq style (car style))) + (cl-progv symbols values + (let ((probe (funcall + (or (nth n (assq style completion-styles-alist)) + (error "Invalid completion style %s" style)) + string table pred point))) + (and probe (cons probe style)))))) (completion--styles md))) (adjust-fn (get (cdr result-and-style) 'completion--adjust-metadata))) (when (and adjust-fn metadata) @@ -3864,6 +3883,30 @@ completion-pcm--pattern-trivial-p (setq trivial nil))) trivial))) +(defcustom completion-pcm-anchored t + "If non-nil, PCM matches only against the start of completions. + +The partial-completion completion style filters the completion +candidates based on whether they match the string being +completed, according to the partial-completion rules. + +If this variable is non-nil, the string's match must begin at the +start of a completion candidate. + +If this variable is nil, the string's match can begin anywhere in +the completion candidate, similar to the substring completion +style. The behavior is identical to inserting a \"*\" at the +start of the completion string. Note that this can be slower to +compute since less filtering of the completion candidates is +possible. + +For example: when the string being completed is \"b/c\", +\"bbb/ccc\" is a valid completion according to +partial-completion. If this is nil, then \"aaa/bbb/ccc\" and +\"aaabbb/ccc\" are also valid completions." + :version "30.1" + :type 'boolean) + (defun completion-pcm--string->pattern (string &optional point) "Split STRING into a pattern. A pattern is a list where each element is either a string @@ -3914,7 +3957,11 @@ completion-pcm--string->pattern (when (> (length string) p0) (if pending (push pending pattern)) (push (substring string p0) pattern)) - (nreverse pattern)))) + (setq pattern (nreverse pattern)) + (unless completion-pcm-anchored + (when (stringp (car pattern)) + (push 'prefix pattern))) + pattern))) (defun completion-pcm--optimize-pattern (p) ;; Remove empty strings in a separate phase since otherwise a "" -- 2.39.3 --=-=-=--