branch: externals/ef-themes
commit 3a2a6e99f018865fd50f3a201731068365c73c87
Author: Protesilaos Stavrou <[email protected]>
Commit: Protesilaos Stavrou <[email protected]>

    Make completion candidates a table with 'theme' category
    
    This allows the user to target the 'theme' completion category in
    order to affect the relevant functions.  For example, to set
    completion styles with 'completion-category-overrides' or define a
    custom annotation function with the 'marginalia' package.
---
 ef-themes.el | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/ef-themes.el b/ef-themes.el
index e2511d8016..eeea6b9770 100644
--- a/ef-themes.el
+++ b/ef-themes.el
@@ -557,16 +557,25 @@ overrides."
              (doc-string (get symbol 'theme-documentation)))
     (format " -- %s" (car (split-string doc-string "\\.")))))
 
+(defun ef-themes--completion-table (category candidates)
+  "Pass appropriate metadata CATEGORY to completion CANDIDATES."
+  (lambda (string pred action)
+    (if (eq action 'metadata)
+        `(metadata (category . ,category))
+      (complete-with-action action candidates string pred))))
+
 (defvar ef-themes--select-theme-history nil
   "Minibuffer history of `ef-themes--select-prompt'.")
 
 (defun ef-themes--load-subset (subset)
   "Return the `light' or `dark' SUBSET of the Ef themes.
 If SUBSET is neither `light' nor `dark', return all the known Ef themes."
-  (pcase subset
-    ('dark ef-themes-dark-themes)
-    ('light ef-themes-light-themes)
-    (_ (ef-themes--list-known-themes))))
+  (ef-themes--completion-table
+   'theme
+   (pcase subset
+     ('dark ef-themes-dark-themes)
+     ('light ef-themes-light-themes)
+     (_ (ef-themes--list-known-themes)))))
 
 (defun ef-themes--maybe-prompt-subset (variant)
   "Helper function for `ef-themes--select-prompt' VARIANT argument."
@@ -784,7 +793,8 @@ Helper function for `ef-themes-preview-colors'."
         (completion-extra-properties `(:annotation-function 
,#'ef-themes--annotate-theme)))
     (completing-read
      (format "Use palette from theme [%s]: " def)
-     (ef-themes--list-known-themes) nil t nil
+     (ef-themes--load-subset :all-themes)
+     nil t nil
      'ef-themes--preview-colors-prompt-history def)))
 
 (defun ef-themes-preview-colors (theme &optional mappings)

Reply via email to