emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master 69ec333eab0: Allow customizing partial-completion to be more


From: Spencer Baugh
Subject: Re: master 69ec333eab0: Allow customizing partial-completion to be more like substring
Date: Fri, 06 Sep 2024 13:23:19 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

Eli Zaretskii <eliz@gnu.org> writes:
> Spencer, would you please take care of these gotchas?

The attached patch does so.

>> From: Michael Albinus <michael.albinus@gmx.de>
>> Cc: Spencer Baugh <sbaugh@janestreet.com>
>> Date: Sat, 24 Aug 2024 12:15:49 +0200
>> 
>> Eli Zaretskii <eliz@gnu.org> 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. 

>From 818332ad5069bd865a865f22ab5d5c2dda083049 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]