unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: master 69ec333eab0: Allow customizing partial-completion to be more like substring
       [not found] ` <20240824092245.2C0C9C41F06@vcs2.savannah.gnu.org>
@ 2024-08-24 10:15   ` Michael Albinus
  2024-08-31  9:30     ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Albinus @ 2024-08-24 10:15 UTC (permalink / raw)
  To: emacs-devel; +Cc: Spencer Baugh

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.

Just being curious: why must it be a form (STYLE ((VARIABLE VALUE) ...)) ?
Wouldn't it be sufficient to use (STYLE (VARIABLE VALUE) ...) ?

> +(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".

Best regards, Michael.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: master 69ec333eab0: Allow customizing partial-completion to be more like substring
  2024-08-24 10:15   ` master 69ec333eab0: Allow customizing partial-completion to be more like substring Michael Albinus
@ 2024-08-31  9:30     ` Eli Zaretskii
  2024-09-06 17:23       ` Spencer Baugh via Emacs development discussions.
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2024-08-31  9:30 UTC (permalink / raw)
  To: Michael Albinus, sbaugh; +Cc: emacs-devel

Spencer, would you please take care of these gotchas?

> 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.
> 
> Just being curious: why must it be a form (STYLE ((VARIABLE VALUE) ...)) ?
> Wouldn't it be sufficient to use (STYLE (VARIABLE VALUE) ...) ?
> 
> > +(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".
> 
> Best regards, Michael.
> 
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: master 69ec333eab0: Allow customizing partial-completion to be more like substring
  2024-08-31  9:30     ` Eli Zaretskii
@ 2024-09-06 17:23       ` Spencer Baugh via Emacs development discussions.
  2024-09-14  8:47         ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Spencer Baugh via Emacs development discussions. @ 2024-09-06 17:23 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2697 bytes --]

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. 


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Update-completion-styles-defcustom-for-variable-over.patch --]
[-- Type: text/x-patch, Size: 4049 bytes --]

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))))
+
 \f
 ;;; The `lazy' Widget.
 ;;
-- 
2.39.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: master 69ec333eab0: Allow customizing partial-completion to be more like substring
  2024-09-06 17:23       ` Spencer Baugh via Emacs development discussions.
@ 2024-09-14  8:47         ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2024-09-14  8:47 UTC (permalink / raw)
  To: Spencer Baugh; +Cc: emacs-devel

> Date: Fri, 06 Sep 2024 13:23:19 -0400
> From:  Spencer Baugh via "Emacs development discussions." <emacs-devel@gnu.org>
> Eli Zaretskii <eliz@gnu.org> writes:
> > Spencer, would you please take care of these gotchas?
> 
> The attached patch does so.

Thanks, installed.  But the new single-or-list feature should be
documented in the ELisp manual.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-09-14  8:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <172449136475.5211.17507793835510648935@vcs2.savannah.gnu.org>
     [not found] ` <20240824092245.2C0C9C41F06@vcs2.savannah.gnu.org>
2024-08-24 10:15   ` master 69ec333eab0: Allow customizing partial-completion to be more like substring Michael Albinus
2024-08-31  9:30     ` Eli Zaretskii
2024-09-06 17:23       ` Spencer Baugh via Emacs development discussions.
2024-09-14  8:47         ` Eli Zaretskii

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).