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: Thu, 16 May 2024 16:26:32 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21049"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 70217@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu May 16 22:27:39 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 1s7hhT-0005Fb-FS for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 16 May 2024 22:27:39 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s7hgt-0002jY-Km; Thu, 16 May 2024 16:27:03 -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 1s7hgr-0002j1-BD for bug-gnu-emacs@gnu.org; Thu, 16 May 2024 16:27:01 -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 1s7hgr-0002TA-2E for bug-gnu-emacs@gnu.org; Thu, 16 May 2024 16:27:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s7hgt-0003TV-6u for bug-gnu-emacs@gnu.org; Thu, 16 May 2024 16:27:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 May 2024 20:27:03 +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.171589120613321 (code B ref 70217); Thu, 16 May 2024 20:27:03 +0000 Original-Received: (at 70217) by debbugs.gnu.org; 16 May 2024 20:26:46 +0000 Original-Received: from localhost ([127.0.0.1]:50821 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s7hgb-0003Sn-TX for submit@debbugs.gnu.org; Thu, 16 May 2024 16:26:46 -0400 Original-Received: from mxout6.mail.janestreet.com ([64.215.233.21]:44023) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s7hgW-0003Sh-NZ for 70217@debbugs.gnu.org; Thu, 16 May 2024 16:26:44 -0400 In-Reply-To: (Stefan Monnier's message of "Wed, 08 May 2024 13:14:34 -0400") DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1715891192; bh=dqrjdlCRAsDPpv5FnMKPp6mUS9NfPWT6lVOe3Tyn30g=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=jk/7HYKN9dA00j1EHNAzVTWciZFEkRbROdptT9hIVB70/zu/1mn22aThUQkyrvNSY bolIFfN0WgtthGvLVD6GWNKFSTqQT/IQnyOx47Y+qYoB8nb+i8GJ3jBs9YMX9D6Whi uFBf3qH8qEgcUObfMDaKs27r/ncU65wpqDcZ/5ceF/tSdwkNgF+Y4+eY+xOdXD4sXa MbLxqEFzXCapTtWk01dVfX6gSmmbChXK6E2t9duym1qgdeoRLf0rnIXqu2eGUXsa02 4mlZT18wjU2614pNGzIOKskNabb69cEgcVpZ+u7TmAlwIMG+R6/wM0cQSIF3jVz5LY /TbehHIcAVUWg== 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:285204 Archived-At: Stefan Monnier writes: >> * lisp/minibuffer.el (completion-emacs22-use-pcm) >> (completion-substring-use-pcm): Add. (bug#70217) >> (completion-emacs22-try-completion) >> (completion-emacs22-all-completions): Check completion-emacs22-use-pcm. >> (completion-pcm--string->pattern, completion-pcm--find-all-completions) >> (completion-pcm-all-completions, completion-pcm--merge-try) >> (completion-pcm-try-completion): Add "startglob" optional argument and >> pass through. >> (completion-substring-try-completion) >> (completion-substring-all-completions): Check >> completion-substring-use-pcm and pass startglob=t. > > I'm not super happy about this `startglob` everywhere. > Two things bother me about it: > > - Its name and doc (in my view of what "glob" means, there's no such > thing as a "leading glob"; I think you're talking about a leading > wildcard (which is one of the things that can appear in a glob > pattern)). Yes, very true, changed to "anchored". > - Its spreading all over the place. In the attached diff it's a dynamic variable completion-pcm-anchored checked in one place. How's that? > I don't have the time to dig into the second problem (which might be > fixable by combining this info into the `string` argument (which > wouldn't be just a string as more, so it could have too-far reaching > consequences)), but for the first I suspect a "standard" name for this > idea is `anchored`. > > Other than that, I don't have a strong opinion on whether to introduce > the feature via new styles or as custom vars that affect > existing styles. Either way works for me. As part of making it a dynamic variable, I also changed the usage. In the attached diff, an element in completion-styles can contain additional dynamic variable bindings: (setq completion-styles '(basic (partial-completion (completion-pcm-anchored nil)) emacs22)) This is powerful and elegant in some ways - for example now a user could use completion-ignore-case only for an individual style. Also, the overall diff is now much shorter. But it may be a bit too powerful. Also, now completion uses cl-progv, which internally uses eval, which might be undesirable. Maybe that could be solved with a C implementation of cl-progv? I think a C implementation of cl-progv might also be useful for my native modules, so I'd be happy to implement that if it seems like a good idea. Also, it's somewhat hard to expose this new power via customize (I haven't bothered to update the customize type for it yet in this diff) What do you think? diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 5ce5aab5c7e..7110e7f573d 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1218,11 +1218,18 @@ completion--nth-completion (result-and-style (completion--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 (cdr 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) @@ -3780,6 +3787,17 @@ completion-pcm--pattern-trivial-p (setq trivial nil))) trivial))) +(defcustom completion-pcm-anchored t + "If nil, the partial-completion style expands at the start of a string. + +If non-nil, then expansion at the start of a string only happens +if the string begins with a wildcard. + +For example, if this is nil then \"b/c\" will match +\"aaa/bbb/ccc\"." + :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 @@ -3830,7 +3848,12 @@ 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 ""