branch: externals/modus-themes
commit 08ed0d631cbef73f3e8b456b696bfe1bef624de3
Author: Protesilaos Stavrou <[email protected]>
Commit: Protesilaos Stavrou <[email protected]>

    Make modus-themes-get-all-known-themes filter by theme family
    
    This is more flexible than having a no derivatives toggle.
---
 modus-themes.el | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/modus-themes.el b/modus-themes.el
index cdadfc0940..fb239bd849 100644
--- a/modus-themes.el
+++ b/modus-themes.el
@@ -4642,13 +4642,27 @@ Also see `modus-themes-get-all-known-themes'.")
   (unless (custom-theme-p theme)
     (load-theme theme t t)))
 
-(defun modus-themes-get-all-known-themes (&optional no-derivatives)
+(defun modus-themes--belongs-to-family-p (theme family)
+  "Return non-nil if THEME has FAMILY property."
+  (when-let* ((properties (get theme 'theme-properties))
+              (theme-family (plist-get properties :family)))
+    (eq theme-family family)))
+
+(defun modus-themes-get-all-known-themes (&optional theme-family)
   "Return all known Modus themes or derivatives, enabling them if needed.
-With optional NO-DERIVATIVES, operate only on the `modus-themes-items'."
-  (let ((themes (if no-derivatives
-                    modus-themes-items
-                  (seq-union modus-themes-items 
modus-themes-registered-items))))
-    (mapc #'modus-themes--activate themes)))
+With optional THEME-FAMILY, operate only on the themes whose :family
+property is that.  Else consider only the `modus-themes-items''."
+  (let* ((modus-p (or (null theme-family) (eq theme-family 'modus-themes)))
+         (themes (if modus-p
+                     modus-themes-items
+                   (seq-union modus-themes-items 
modus-themes-registered-items))))
+    (mapc #'modus-themes--activate themes)
+    (if modus-p
+        themes
+      (seq-filter
+       (lambda (theme)
+         (modus-themes--belongs-to-family-p theme theme-family))
+       themes))))
 
 (defun modus-themes-known-p (themes &optional show-error)
   "Return THEMES if they are among `modus-themes-get-all-known-themes' else 
nil.

Reply via email to