[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 807f484 03/31: Allow themes to be overridden, but warn.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 807f484 03/31: Allow themes to be overridden, but warn. |
Date: |
Mon, 09 Feb 2015 01:09:29 +0000 |
branch: master
commit 807f484f511a9bfd58d0dd89eb11eacce3b96b33
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Allow themes to be overridden, but warn.
---
context-coloring.el | 63 ++++++++++++++++++++++++----------------
test/context-coloring-test.el | 31 ++++++++++++++++++++
2 files changed, 69 insertions(+), 25 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index b09ed1c..2dcf183 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -481,15 +481,25 @@ would be redundant."
"Return t if THEME is defined, nil otherwise."
(and (gethash theme context-coloring-theme-hash-table)))
-(defun context-coloring-check-theme (theme)
- "Signal error if THEME is undefined."
- (when (not (context-coloring-themep theme))
- (error (format "No such theme `%s'" theme))))
-
(defconst context-coloring-level-face-regexp
"context-coloring-level-\\([[:digit:]]+\\)-face"
"Regular expression for extracting a level from a face.")
+(defun context-coloring-theme-definedp (theme)
+ "Return t if there is a `context-coloring-level-N-face' defined
+for THEME, nil otherwise."
+ (let* ((settings (get theme 'theme-settings))
+ (tail settings)
+ found)
+ (while (and tail (not found))
+ (and (eq (nth 0 (car tail)) 'theme-face)
+ (string-match
+ context-coloring-level-face-regexp
+ (symbol-name (nth 1 (car tail))))
+ (setq found t))
+ (setq tail (cdr tail)))
+ found))
+
(defun context-coloring-theme-highest-level (theme)
"Return the highest level N of a face like
`context-coloring-level-N-face' defined for THEME, or -1 if there
@@ -514,18 +524,6 @@ is none."
(setq tail (cdr tail)))
found))
-(defun context-coloring-setup-theme (theme)
- "Sets up THEME if its colors are not already defined, else just
-sets `context-coloring-face-count' to the correct value for
-THEME."
- (context-coloring-check-theme theme)
- (let ((highest-level (context-coloring-theme-highest-level theme)))
- (cond
- ((> highest-level -1)
- (setq context-coloring-face-count (+ highest-level 1)))
- (t
- (context-coloring-apply-theme theme)))))
-
(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."
@@ -549,22 +547,37 @@ PROPERTIES is a property list specifiying the following
details:
`:colors': List of colors that this theme uses."
(let ((aliases (plist-get properties :aliases)))
(dolist (name (append `(,theme) aliases))
+ (when (context-coloring-theme-definedp name)
+ (warn "Colors for `%s' are already defined" name))
(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-setup-theme name)))))
+ ;; Set (or overwrite) colors.
+ (when (custom-theme-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")))
+ (declare
+ (obsolete
+ "themes are now loaded alongside custom themes automatically."
+ "4.1.0")))
+
+(defun context-coloring-enable-theme (theme)
+ "Applies THEME if its colors are not already defined, else just
+sets `context-coloring-face-count' to the correct value for
+THEME."
+ (let ((highest-level (context-coloring-theme-highest-level theme)))
+ (cond
+ ((> highest-level -1)
+ (setq context-coloring-face-count (+ highest-level 1)))
+ (t
+ (context-coloring-apply-theme theme)))))
(defadvice enable-theme (after context-coloring-enable-theme (theme) activate)
- "Add colors to themes just-in-time."
+ "Enable colors for themes just-in-time. We can't set faces for
+themes that might not exist yet."
(when (and (not (eq theme 'user)) ; Called internally by
`enable-theme'.
(context-coloring-themep theme)
(custom-theme-p theme)) ; Guard against non-existent
themes.
- (context-coloring-setup-theme theme)))
+ (context-coloring-enable-theme theme)))
(context-coloring-define-theme
'leuven
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
index a5a11fb..168b6fa 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -268,6 +268,37 @@ is FOREGROUND."
(context-coloring-test-assert-face 8 "#888888")
(context-coloring-test-assert-face 9 "#999999"))
+(defun context-coloring-test-assert-theme-definedp (settings &optional negate)
+ "Assert that `context-coloring-theme-definedp' returns t for a
+theme with SETTINGS (or the inverse if NEGATE is non-nil)."
+ (let (theme)
+ (put theme 'theme-settings settings)
+ (when (funcall (if negate 'identity 'not) (context-coloring-theme-definedp
theme))
+ (ert-fail (format (concat "Expected theme with settings `%s' "
+ "%sto be considered to have defined a level, "
+ "but it %s.")
+ settings
+ (if negate "not " "")
+ (if negate "was" "wasn't"))))))
+
+(defun context-coloring-test-assert-not-theme-definedp (&rest arguments)
+ "Assert that `context-coloring-theme-definedp' does not return
+t for a theme with SETTINGS."
+ (apply 'context-coloring-test-assert-theme-definedp (append arguments '(t))))
+
+(ert-deftest context-coloring-test-theme-definedp ()
+ (context-coloring-test-assert-theme-definedp
+ '((theme-face context-coloring-level-0-face)))
+ (context-coloring-test-assert-theme-definedp
+ '((theme-face face)
+ (theme-face context-coloring-level-0-face)))
+ (context-coloring-test-assert-theme-definedp
+ '((theme-face context-coloring-level-0-face)
+ (theme-face face)))
+ (context-coloring-test-assert-not-theme-definedp
+ '((theme-face face)))
+ )
+
(defun context-coloring-test-assert-theme-highest-level (settings
expected-level)
(let (theme)
(put theme 'theme-settings settings)
- [elpa] master 874982e 08/31: Update test names., (continued)
- [elpa] master 874982e 08/31: Update test names., Jackson Ray Hamilton, 2015/02/08
- [elpa] master 06efd73 09/31: Fix assertion so tests fail., Jackson Ray Hamilton, 2015/02/08
- [elpa] master 23a12b8 12/31: Rename test., Jackson Ray Hamilton, 2015/02/08
- [elpa] master 06a7606 10/31: Pass / update tests for warnings., Jackson Ray Hamilton, 2015/02/08
- [elpa] master 6e6bc61 15/31: Rename themep to theme-p., Jackson Ray Hamilton, 2015/02/08
- [elpa] master 0f036c9 13/31: Improve documentation for themes., Jackson Ray Hamilton, 2015/02/08
- [elpa] master ca7122c 16/31: Remove `when'., Jackson Ray Hamilton, 2015/02/08
- [elpa] master 71a1a0c 14/31: Rename ambiguous "defined" to "originally set"., Jackson Ray Hamilton, 2015/02/08
- [elpa] master c4459fe 02/31: Fix faces on light tty backgrounds. Be more conservative about applying themes., Jackson Ray Hamilton, 2015/02/08
- [elpa] master cda491a 17/31: Long lines., Jackson Ray Hamilton, 2015/02/08
- [elpa] master 807f484 03/31: Allow themes to be overridden, but warn.,
Jackson Ray Hamilton <=
- [elpa] master 2090e5d 11/31: Add missing case for a theme that does not set faces., Jackson Ray Hamilton, 2015/02/08
- [elpa] master 6eef78b 21/31: Add spacegray theme., Jackson Ray Hamilton, 2015/02/08
- [elpa] master 2b687ae 19/31: Pass test for disabling., Jackson Ray Hamilton, 2015/02/08
- [elpa] master a197a8c 20/31: Add disclaimer about precedence., Jackson Ray Hamilton, 2015/02/08
- [elpa] master 9d55bd6 18/31: Generalize assertions. Write failing test for disabling., Jackson Ray Hamilton, 2015/02/08
- [elpa] master 3bd7e26 22/31: Add anti-zenburn theme., Jackson Ray Hamilton, 2015/02/08
- [elpa] master 35b3e71 23/31: Add ample theme., Jackson Ray Hamilton, 2015/02/08
- [elpa] master 0b42ae1 24/31: Add grandshell theme., Jackson Ray Hamilton, 2015/02/08
- [elpa] master 0b8d03d 25/31: Update readme., Jackson Ray Hamilton, 2015/02/08
- [elpa] master fb14816 26/31: Update readme., Jackson Ray Hamilton, 2015/02/08