Update completion-styles defcustom for variable overrides

In 69ec333eab 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.
This commit is contained in:
Spencer Baugh 2024-09-06 13:12:52 -04:00 committed by Eli Zaretskii
parent 0d07bc1a2d
commit 7c767ec781
2 changed files with 31 additions and 5 deletions

View file

@ -1119,8 +1119,10 @@ and DOC describes the way this style of completion works.")
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 @@ 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."
:type completion--styles-type
:version "23.1")
:version "31.1")
(defvar completion-category-defaults
'((buffer (styles . (basic substring)))
@ -1205,7 +1207,7 @@ completing buffer and file names, respectively.
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 @@ 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"
:version "31.1"
:type 'boolean)
(defun completion-pcm--string->pattern (string &optional point)

View file

@ -3891,6 +3891,30 @@ or a list with the default value of each component of the list WIDGET."
(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.
;;