]> git.eshelyaron.com Git - emacs.git/commitdiff
Make completion-category-overrides choices dynamic
authorMauro Aranda <maurooaranda@gmail.com>
Wed, 26 Oct 2022 10:29:51 +0000 (07:29 -0300)
committerMauro Aranda <maurooaranda@gmail.com>
Wed, 26 Oct 2022 14:28:54 +0000 (11:28 -0300)
See https://lists.gnu.org/archive/html/emacs-devel/2022-10/msg01969.html

* lisp/minibuffer.el (completion--update-styles-options): New internal
function.

(completion--styles-type): Use it.

lisp/minibuffer.el

index fd878e077a1730937a678c1a51a6dd43c555f85b..4898dfdb983a8e7f44761f081a944515e9f6c3b3 100644 (file)
@@ -972,21 +972,17 @@ ALL-COMPLETIONS is the function that lists the completions (it should
 follow the calling convention of `completion-all-completions'),
 and DOC describes the way this style of completion works.")
 
+(defun completion--update-styles-options (widget)
+  "Function to keep updated the options in `completion-category-overrides'."
+  (let ((lst (mapcar (lambda (x)
+                       (list 'const (car x)))
+                    completion-styles-alist)))
+    (widget-put widget :args (mapcar #'widget-convert lst))
+    widget))
+
 (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)
-                   (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)))))))
+           (choice :convert-widget completion--update-styles-options)))
 
 (defconst completion--cycling-threshold-type
   '(choice (const :tag "No cycling" nil)