From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh via "Emacs development discussions." Newsgroups: gmane.emacs.devel Subject: Re: master 69ec333eab0: Allow customizing partial-completion to be more like substring Date: Fri, 06 Sep 2024 13:23:19 -0400 Organization: Jane Street Capital Message-ID: References: <172449136475.5211.17507793835510648935@vcs2.savannah.gnu.org> <20240824092245.2C0C9C41F06@vcs2.savannah.gnu.org> <87frqu6xbe.fsf@gmx.de> <865xrhca52.fsf@gnu.org> Reply-To: Spencer Baugh 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="11499"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: emacs-devel@gnu.org Cancel-Lock: sha1:4TcuVL2Zn4kTIjzJrbShcMi0uYY= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 06 19:39:22 2024 Return-path: Envelope-to: ged-emacs-devel@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 1smcva-0002pG-DK for ged-emacs-devel@m.gmane-mx.org; Fri, 06 Sep 2024 19:39:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1smcus-0001wT-Cq; Fri, 06 Sep 2024 13:38:38 -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 1smcgI-0000Jf-OP for emacs-devel@gnu.org; Fri, 06 Sep 2024 13:23:35 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1smcgG-0000hQ-Eb for emacs-devel@gnu.org; Fri, 06 Sep 2024 13:23:33 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1smcgB-0007mS-RT for emacs-devel@gnu.org; Fri, 06 Sep 2024 19:23:27 +0200 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 06 Sep 2024 13:38:33 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:323480 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: > Spencer, would you please take care of these gotchas? The attached patch does so. >> From: Michael Albinus >> Cc: Spencer Baugh >> Date: Sat, 24 Aug 2024 12:15:49 +0200 >> >> Eli Zaretskii writes: >> >> Hi, >> >> > diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el >> > index 3beb3c06a18..6fae62b3904 100644 >> > --- a/lisp/minibuffer.el >> > +++ b/lisp/minibuffer.el >> > @@ -1141,7 +1141,15 @@ and DOC describes the way this style of completion works.") >> > ;; 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. >> >> The :type of completion-styles should be adapted in order to reflect >> this change. Furthermore, this warrants a change of the :version, I >> believe. Fixed. >> Just being curious: why must it be a form (STYLE ((VARIABLE VALUE) ...)) ? >> Wouldn't it be sufficient to use (STYLE (VARIABLE VALUE) ...) ? Both would work fine. I thought the (style ((var val) (var val))) format would be slightly more familiar for a novice, and slightly easier for us to change: we could add (style ((var val)) something-else) later if we wanted. But it would be easy to change it to (style (var val) (var val)) if people prefer that. >> > +(defcustom completion-pcm-leading-wildcard nil >> > + "If non-nil, partial-completion completes as if there's a leading 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 >> > +`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." >> > + :version "30.1" >> > + :type 'boolean) >> >> This doesn't look right, it should be :version "31.1". Fixed. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Update-completion-styles-defcustom-for-variable-over.patch >From 818332ad5069bd865a865f22ab5d5c2dda083049 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Fri, 6 Sep 2024 13:12:52 -0400 Subject: [PATCH] Update completion-styles defcustom for variable overrides In 69ec333eab0b801949d33ef5ae505addc9061793 I allowed completion-styles to contain a list of bindings. Now the defcustom type also supports this. Since the type is somewhat unusual (a value in the list can be either a symbol or a list) I had to add a new widget to support it. * lisp/minibuffer.el (completion--styles-type): Update to allow setting variable overrides. (completion-styles, completion-category-overrides) (completion-pcm-leading-wildcard): Update :version. * lisp/wid-edit.el (widget-single-or-list-to-internal, single-or-list): Add. --- lisp/minibuffer.el | 12 +++++++----- lisp/wid-edit.el | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 1efe71f10e3..d5f666dfecf 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1119,8 +1119,10 @@ completion--update-styles-options widget)) (defconst completion--styles-type - `(repeat :tag "insert a new menu to add more styles" - (choice :convert-widget completion--update-styles-options))) + '(repeat :tag "insert a new menu to add more styles" + (single-or-list + (choice :convert-widget completion--update-styles-options) + (repeat :tag "Variable overrides" (group variable sexp))))) (defconst completion--cycling-threshold-type '(choice (const :tag "No cycling" nil) @@ -1154,7 +1156,7 @@ completion-styles Note that `completion-category-overrides' may override these styles for specific categories, such as files, buffers, etc." :type completion--styles-type - :version "23.1") + :version "31.1") (defvar completion-category-defaults '((buffer (styles . (basic substring))) @@ -1205,7 +1207,7 @@ completion-category-overrides If a property in a category is specified by this variable, it overrides the default specified in `completion-category-defaults'." - :version "25.1" + :version "31.1" :type `(alist :key-type (choice :tag "Category" (const buffer) (const file) @@ -3895,7 +3897,7 @@ completion-pcm-leading-wildcard 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." - :version "30.1" + :version "31.1" :type 'boolean) (defun completion-pcm--string->pattern (string &optional point) diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el index e7e6351fcab..05c3f412bf6 100644 --- a/lisp/wid-edit.el +++ b/lisp/wid-edit.el @@ -3891,6 +3891,30 @@ widget-cons-match (and (consp value) (widget-group-match widget (widget-apply widget :value-to-internal value)))) + +(defun widget-single-or-list-to-internal (widget val) + (if (listp val) val + (cons val (make-list (1- (length (widget-get widget :args))) nil)))) + +(define-widget 'single-or-list 'group + "Either a single value (`nlistp') or a list of values (`listp'). + +If the initial value is `nlistp', the first child widget gets +that value and the other children get nil. + +If the first child's value is `nlistp' and the other children are +nil, then `widget-value' just returns the first child's value." + ;; The internal value is always a list; only :value-to-internal and + ;; :match ever get called with the external value, which might be + ;; `nlistp'. + :value-to-external (lambda (_ val) + (if (and (nlistp (car val)) + (cl-every #'null (cdr val))) + (car val) val)) + :value-to-internal #'widget-single-or-list-to-internal + :match (lambda (widget val) + (widget-group-match widget (widget-single-or-list-to-internal widget val)))) + ;;; The `lazy' Widget. ;; -- 2.39.3 --=-=-=--