emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 87a0ee4 06/10: Automatically load themes alongside custom


From: Jackson Ray Hamilton
Subject: [elpa] master 87a0ee4 06/10: Automatically load themes alongside custom themes.
Date: Sat, 07 Feb 2015 09:02:44 +0000

branch: master
commit 87a0ee45a62605758d37b0d2a6e9fab2dec1a26e
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>

    Automatically load themes alongside custom themes.
---
 context-coloring.el |   54 ++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/context-coloring.el b/context-coloring.el
index 2a8b8f9..8ce8cad 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -479,24 +479,48 @@ would be redundant."
 (defvar context-coloring-theme-hash-table (make-hash-table :test 'eq)
   "Mapping of theme names to theme properties.")
 
+(defun context-coloring-apply-theme (theme)
+  "Applies THEME's properties to its respective custom theme,
+which must already exist and which *should* already be enabled."
+  (let ((properties (gethash theme context-coloring-theme-hash-table)))
+    (when (null properties)
+      (error (format "No such theme `%s'" theme)))
+    (let ((colors (plist-get properties :colors)))
+      (setq context-coloring-face-count (length colors)) ; Side-effect?
+      (let ((level -1))
+        ;; AFAIK, no way to know if a theme already has a face set, so just
+        ;; override blindly for now.
+        (apply
+         'custom-theme-set-faces
+         theme
+         (mapcar
+          (lambda (color)
+            (setq level (+ level 1))
+            `(,(context-coloring-face-symbol level) ((t (:foreground 
,color)))))
+          colors))))))
+
 (defun context-coloring-define-theme (theme &rest properties)
   "Define a theme named THEME for coloring scope levels.
 PROPERTIES is a property list specifiying the following details:
 
 `:colors': List of colors that this theme uses."
-  (puthash
-   theme
-   (lambda ()
-     (apply 'context-coloring-set-colors (plist-get properties :colors)))
-   context-coloring-theme-hash-table))
-
-(defun context-coloring-load-theme (theme)
-  "Apply THEME's colors and other properties for context
-coloring."
-  (let ((function (gethash theme context-coloring-theme-hash-table)))
-    (when (null function)
-      (error (format "No such theme `%s'" theme)))
-    (funcall function)))
+  (let ((aliases (plist-get properties :aliases)))
+    (dolist (name (append '(theme) aliases))
+      (puthash name properties context-coloring-theme-hash-table)
+      ;; Compensate for already-enabled themes by applying their colors now.
+      (when (custom-theme-enabled-p name)
+        (context-coloring-apply-theme name)))))
+
+(defun context-coloring-load-theme (&optional rest)
+  (declare (obsolete
+            "themes are now loaded alongside custom themes automatically."
+            "4.1.0")))
+
+(defadvice enable-theme (after context-coloring-enable-theme (theme) activate)
+  "Add colors to themes just-in-time."
+  (when (and (not (eq theme 'user))  ; Called internally.
+             (custom-theme-p theme)) ; Guard against non-existent themes.
+    (context-coloring-apply-theme theme)))
 
 (context-coloring-define-theme
  'leuven
@@ -524,6 +548,10 @@ coloring."
 
 (context-coloring-define-theme
  'solarized
+ :aliases '(solarized-light
+            solarized-dark
+            sanityinc-solarized-light
+            sanityinc-solarized-dark)
  :colors '("#839496"
            "#268bd2"
            "#2aa198"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]