]> git.eshelyaron.com Git - emacs.git/commitdiff
Dynamic validation of styles in completion-category-overrides
authorMattias Engdegård <mattiase@acm.org>
Wed, 26 Oct 2022 08:51:51 +0000 (10:51 +0200)
committerMattias Engdegård <mattiase@acm.org>
Wed, 26 Oct 2022 08:51:51 +0000 (10:51 +0200)
The type of the defcustom completion-category-overrides must be able
to accommodate dynamic changes to completion-styles-alist, because
some packages (eglot) make their own additions.

This change fixes a failure in test-custom-opts.  See discussion at:
https://lists.gnu.org/archive/html/emacs-devel/2022-10/msg01969.html

* lisp/minibuffer.el (completion--styles-type):
Add an "Other" case that accepts any symbol which is then validated
dynamically against completion-styles-alist.

lisp/minibuffer.el

index a9f72d600decf40180f35b02a50e6d23a5dae795..fd878e077a1730937a678c1a51a6dd43c555f85b 100644 (file)
@@ -975,7 +975,19 @@ and DOC describes the way this style of completion works.")
 (defconst completion--styles-type
   `(repeat :tag "insert a new menu to add more styles"
            (choice ,@(mapcar (lambda (x) (list 'const (car x)))
-                             completion-styles-alist))))
+                             completion-styles-alist)
+                   (symbol :tag "Other"
+                           :validate
+                           ,(lambda (widget)
+                              (let ((value (widget-value widget)))
+                                (if (assq value completion-styles-alist)
+                                    nil    ; Valid.
+                                  (widget-put
+                                   widget :error
+                                   (format "Invalid completion style: %S"
+                                           value))
+                                  widget)))))))
+
 (defconst completion--cycling-threshold-type
   '(choice (const :tag "No cycling" nil)
            (const :tag "Always cycle" t)