[elpa] master 843bc70 4/7: Add amaranth (immortal) Hydras
branch: master commit 843bc709a31691e8049ccb1e75d87514f42c9c99 Author: Oleh Krehel Commit: Oleh Krehel Add amaranth (immortal) Hydras * hydra.el (hydra-face-amaranth): New face. (hydra--face): Update. (defhydra): If the body color is amaranth, it's only possible to exit this Hydra through a blue head. None of the other key bindings, even "C-g" will work. There's a check in place that the current Hydra should have at least one blue head. Re #17. Example: (defhydra hydra-vi (:pre (set-cursor-color "#40e0d0") :post (set-cursor-color "#ff") :color amaranth) "vi" ("l" forward-char) ("h" backward-char) ("j" next-line) ("k" previous-line) ("q" nil "quit")) (global-set-key (kbd "C-z") 'hydra-vi/body) --- hydra.el | 18 ++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/hydra.el b/hydra.el index 23b563d..1049bfb 100644 --- a/hydra.el +++ b/hydra.el @@ -89,6 +89,10 @@ '((t (:foreground "#758BC6" :bold t))) "Blue Hydra heads will vanquish the Hydra.") +(defface hydra-face-amaranth +'((t (:foreground "#E52B50" :bold t))) + "Amaranth Hydra can exit only through a blue head.") + ;;* Universal Argument (defvar hydra-base-map (let ((map (make-sparse-keymap))) @@ -168,6 +172,7 @@ (cl-case (hydra--color h body-color) (blue 'hydra-face-blue) (red 'hydra-face-red) +(amaranth 'hydra-face-amaranth) (t (error "Unknown color for %S" h (defun hydra--hint (docstring heads body-color) @@ -308,6 +313,19 @@ in turn can be either red or blue." (when (and (or body-pre body-post) (version< emacs-version "24.4")) (error "At least Emacs 24.4 is needed for :pre and :post")) +(when (eq body-color 'amaranth) + (if (cl-some `(lambda (h) + (eq (hydra--color h ',body-color) 'blue)) + heads) + (define-key keymap [t] +`(lambda () + (interactive) + (message "An amaranth Hydra can only exit through a blue head") + (hydra-set-transient-map hydra-curr-map t) + (when hydra-is-helpful + (sit-for 0.8) + (message ,hint +(error "An amaranth Hydra must have at least one blue head in order to exit"))) `(progn ,@(cl-mapcar (lambda (head name)
[elpa] master 68bcaa8 6/7: Bump version
branch: master commit 68bcaa8d8df5518217a3833fd1bb400c8225fe02 Author: Oleh Krehel Commit: Oleh Krehel Bump version --- hydra.el |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/hydra.el b/hydra.el index 1049bfb..6cbe705 100644 --- a/hydra.el +++ b/hydra.el @@ -5,7 +5,7 @@ ;; Author: Oleh Krehel ;; Maintainer: Oleh Krehel ;; URL: https://github.com/abo-abo/hydra -;; Version: 0.7.0 +;; Version: 0.8.0 ;; Keywords: bindings ;; Package-Requires: ((cl-lib "0.5"))
[elpa] master e8bbb70 2/7: Add :pre and :post clauses to Hydra body
branch: master commit e8bbb70545b6d5316d1797ebb5e76c5a30dff266 Author: Oleh Krehel Commit: Oleh Krehel Add :pre and :post clauses to Hydra body * hydra.el (defhydra): the PLIST part of BODY argument now recognizes :pre and :post keys. These should be single Elisp statements, wrappable in a lambda. When you need more than one statement, use a `progn'. :pre will be called by `hydra-foo/body', as well as by all heads. :post will be called by the blue heads, as well as on Hydra termination by a command that isn't a head. Fixes #16. An Example: (global-set-key (kbd "C-z") (defhydra hydra-vi (:pre (set-cursor-color "#40e0d0") :post (set-cursor-color "#ff")) "vi" ("l" forward-char) ("h" backward-char) ("j" next-line) ("k" previous-line) ("q" nil "quit"))) --- hydra.el | 26 -- 1 files changed, 20 insertions(+), 6 deletions(-) diff --git a/hydra.el b/hydra.el index 043b2a3..23b563d 100644 --- a/hydra.el +++ b/hydra.el @@ -5,7 +5,7 @@ ;; Author: Oleh Krehel ;; Maintainer: Oleh Krehel ;; URL: https://github.com/abo-abo/hydra -;; Version: 0.6.1 +;; Version: 0.7.0 ;; Keywords: bindings ;; Package-Requires: ((cl-lib "0.5")) @@ -116,7 +116,7 @@ (define-key map [kp-9] 'hydra--digit-argument) (define-key map [kp-subtract] 'hydra--negative-argument) map) - "Keymap that all Hydras inherit. See `universal-argument-map'.") + "Keymap that all Hydras inherit. See `universal-argument-map'.") (defvar hydra-curr-map (make-sparse-keymap) @@ -130,7 +130,7 @@ (if (eq arg '-) (list -4) '(4 - (hydra-set-transient-map hydra-curr-map)) + (hydra-set-transient-map hydra-curr-map t)) (defun hydra--digit-argument (arg) "Forward to (`digit-argument' ARG)." @@ -298,21 +298,28 @@ in turn can be either red or blue." 'red (or (plist-get (cddr body) :color) 'red))) + (body-pre (plist-get (cddr body) :pre)) + (body-post (plist-get (cddr body) :post)) (method (if (hydra--callablep body) body (car body))) (hint (hydra--hint docstring heads body-color)) (doc (hydra--doc body-key body-name heads))) +(when (and (or body-pre body-post) + (version< emacs-version "24.4")) + (error "At least Emacs 24.4 is needed for :pre and :post")) `(progn ,@(cl-mapcar (lambda (head name) `(defun ,name () ,(format "%s\n\nCall the head: `%S'." doc (cadr head)) (interactive) + ,@(if body-pre (list body-pre)) ,@(if (eq (hydra--color head body-color) 'blue) `((hydra-disable) ,@(unless (null (cadr head)) - `((call-interactively #',(cadr head) + `((call-interactively #',(cadr head + ,@(if body-post (list body-post))) `((catch 'hydra-disable (hydra-disable) (condition-case err @@ -325,7 +332,10 @@ in turn can be either red or blue." (when hydra-is-helpful (message ,hint)) (setq hydra-last - (hydra-set-transient-map (setq hydra-curr-map ',keymap) t))) + (hydra-set-transient-map +(setq hydra-curr-map ',keymap) +t +,@(if body-post `((lambda () ,body-post)) heads names) ,@(unless (or (null body-key) (null method) @@ -347,10 +357,14 @@ in turn can be either red or blue." (defun ,body-name () ,doc (interactive) + ,@(if body-pre (list body-pre)) (when hydra-is-helpful (message ,hint)) (setq hydra-last - (hydra-set-transient-map ',keymap t)) + (hydra-set-transient-map +',keymap +t +,@(if body-post `((lambda () ,body-post) (provide 'hydra)
[elpa] master 2fb700c 7/7: Merge commit '68bcaa8d8df5518217a3833fd1bb400c8225fe02' from hydra
branch: master commit 2fb700c07397304a074092e025a55f34142a5a7e Merge: 8b585bc 68bcaa8 Author: Oleh Krehel Commit: Oleh Krehel Merge commit '68bcaa8d8df5518217a3833fd1bb400c8225fe02' from hydra --- packages/hydra/README.md | 66 + packages/hydra/hydra-test.el | 571 ++ packages/hydra/hydra.el | 60 - 3 files changed, 587 insertions(+), 110 deletions(-) diff --git a/packages/hydra/README.md b/packages/hydra/README.md index 0686965..7272098 100644 --- a/packages/hydra/README.md +++ b/packages/hydra/README.md @@ -171,3 +171,69 @@ Since version `0.6.0`, for any Hydra: - `digit-argment` can be called with 0-9. - `negative-argument` can be called with - - `universal-argument` can be called with C-u + +## Hydras can have `:pre` and `:post` statements + +Since version `0.7.0`, you can specify code that will be called before each head, and +after the body. For example: + +```cl +(global-set-key + (kbd "C-z") + (defhydra hydra-vi + (:pre + (set-cursor-color "#40e0d0") + :post + (progn +(set-cursor-color "#ff") +(message + "Thank you, come again."))) + "vi" + ("l" forward-char) + ("h" backward-char) + ("j" next-line) + ("k" previous-line) + ("q" nil "quit"))) +``` + +## New Hydra color: amaranth + +Since version `0.8.0`, a new color - amaranth, in addition to the previous red and blue, is +available for the Hydra body. + +According to [Wikipedia](http://en.wikipedia.org/wiki/Amaranth): + +> The word amaranth comes from the Greek word amaranton, meaning "unwilting" (from the +> verb marainesthai, meaning "wilt"). The word was applied to amaranth because it did not +> soon fade and so symbolized immortality. + +Hydras with amaranth body are impossible to quit with any binding *except* a blue head. +A check for at least one blue head exists in `defhydra`, so that you don't get stuck by accident. + +Here's an example of an amaranth Hydra: + +```cl +(global-set-key + (kbd "C-z") + (defhydra hydra-vi + (:pre + (set-cursor-color "#40e0d0") + :post + (set-cursor-color "#ff") + :color amaranth) + "vi" + ("l" forward-char) + ("h" backward-char) + ("j" next-line) + ("k" previous-line) + ("q" nil "quit"))) +``` + +The only way to exit it, is to press q. No other methods will work. You can +use an amaranth Hydra instead of a red one, if for you the cost of being able to exit only +though certain bindings is less than the cost of accidentally exiting a red Hydra by +pressing the wrong prefix. + +Note that it does not make sense to define a singe amaranth head, so this color can only +be assigned to the body. An amaranth body will always have some amaranth heads and some +blue heads (otherwise, it's impossible to exit), no reds. diff --git a/packages/hydra/hydra-test.el b/packages/hydra/hydra-test.el index 07d0a74..eee851a 100644 --- a/packages/hydra/hydra-test.el +++ b/packages/hydra/hydra-test.el @@ -26,7 +26,7 @@ (require 'ert) -(ert-deftest defhydra-red-error () +(ert-deftest hydra-red-error () (should (equal (macroexpand @@ -46,39 +46,45 @@ The body can be accessed via `hydra-error/body'. Call the head: `first-error'." (interactive) - (when hydra-is-helpful (message #("error: [h]: first, [j]: next, [k]: prev." 8 9 (face hydra-face-red) - 20 21 (face hydra-face-red) - 31 32 (face hydra-face-red - (setq hydra-last - (hydra-set-transient-map -(setq hydra-curr-map '(keymap (107 . hydra-error/previous-error) - (106 . hydra-error/next-error) - (104 . hydra-error/first-error) - (kp-subtract . hydra--negative-argument) - (kp-9 . hydra--digit-argument) - (kp-8 . hydra--digit-argument) - (kp-7 . hydra--digit-argument) - (kp-6 . hydra--digit-argument) - (kp-5 . hydra--digit-argument) - (kp-4 . hydra--digit-argument) - (kp-3 . hydra--digit-argument) - (kp-2 . hydra--digit-argument) - (kp-1 . hydra--digit-argument) - (kp-0 . hydra--digit-argument) - (57 . hydra--digit-argument) - (56 . hydra--digit-argument) - (55 . hydra--digit-argument) - (54 . hydra--digit-argumen
[elpa] master updated (8b585bc -> 2fb700c)
abo_abo pushed a change to branch master. from 8b585bc Merge commit '59de0b7591713d38c6d5c99cb49c4a4cc434a272' from context-coloring new e21d1d8 Update the call order and allow called functions to exit new e8bbb70 Add :pre and :post clauses to Hydra body new 37b6177 README.md: update for 0.7.0 new 843bc70 Add amaranth (immortal) Hydras new 07e4aaa hydra-test.el: add test new 68bcaa8 Bump version new 2fb700c Merge commit '68bcaa8d8df5518217a3833fd1bb400c8225fe02' from hydra Summary of changes: packages/hydra/README.md | 66 + packages/hydra/hydra-test.el | 571 ++ packages/hydra/hydra.el | 60 - 3 files changed, 587 insertions(+), 110 deletions(-)
[elpa] master e21d1d8 1/7: Update the call order and allow called functions to exit
branch: master commit e21d1d8e89d2af70bccb72d9b169115cf977da1c Author: Oleh Krehel Commit: Oleh Krehel Update the call order and allow called functions to exit * hydra.el (defhydra): First disable the transient map, then call red head, allowing it to throw `hydra-disable' to break, then re-set transient map. If the called function raises an error, display this error for a while, but still set the transient map. * hydra-test.el: Update test. Re #15. --- hydra-test.el | 290 ++--- hydra.el | 18 +++- 2 files changed, 167 insertions(+), 141 deletions(-) diff --git a/hydra-test.el b/hydra-test.el index 07d0a74..f3b4094 100644 --- a/hydra-test.el +++ b/hydra-test.el @@ -46,39 +46,45 @@ The body can be accessed via `hydra-error/body'. Call the head: `first-error'." (interactive) - (when hydra-is-helpful (message #("error: [h]: first, [j]: next, [k]: prev." 8 9 (face hydra-face-red) - 20 21 (face hydra-face-red) - 31 32 (face hydra-face-red - (setq hydra-last - (hydra-set-transient-map -(setq hydra-curr-map '(keymap (107 . hydra-error/previous-error) - (106 . hydra-error/next-error) - (104 . hydra-error/first-error) - (kp-subtract . hydra--negative-argument) - (kp-9 . hydra--digit-argument) - (kp-8 . hydra--digit-argument) - (kp-7 . hydra--digit-argument) - (kp-6 . hydra--digit-argument) - (kp-5 . hydra--digit-argument) - (kp-4 . hydra--digit-argument) - (kp-3 . hydra--digit-argument) - (kp-2 . hydra--digit-argument) - (kp-1 . hydra--digit-argument) - (kp-0 . hydra--digit-argument) - (57 . hydra--digit-argument) - (56 . hydra--digit-argument) - (55 . hydra--digit-argument) - (54 . hydra--digit-argument) - (53 . hydra--digit-argument) - (52 . hydra--digit-argument) - (51 . hydra--digit-argument) - (50 . hydra--digit-argument) - (49 . hydra--digit-argument) - (48 . hydra--digit-argument) - (45 . hydra--negative-argument) - (21 . hydra--universal-argument))) -t)) - (call-interactively (function first-error))) + (catch (quote hydra-disable) + (hydra-disable) + (condition-case err (prog1 t (call-interactively (function first-error))) + ((debug error) + (message "%S" err) + (sit-for 0.8) + nil)) + (when hydra-is-helpful (message #("error: [h]: first, [j]: next, [k]: prev." 8 9 (face hydra-face-red) + 20 21 (face hydra-face-red) + 31 32 (face hydra-face-red + (setq hydra-last + (hydra-set-transient-map + (setq hydra-curr-map '(keymap (107 . hydra-error/previous-error) + (106 . hydra-error/next-error) + (104 . hydra-error/first-error) + (kp-subtract . hydra--negative-argument) + (kp-9 . hydra--digit-argument) + (kp-8 . hydra--digit-argument) + (kp-7 . hydra--digit-argument) + (kp-6 . hydra--digit-argument) + (kp-5 . hydra--digit-argument) + (kp-4 . hydra--digit-argument) + (kp-3 . hydra--digit-argument) + (kp-2 . hydra--digit-argument) + (kp-1 . hydra--digit-argument) +
[elpa] master 07e4aaa 5/7: hydra-test.el: add test
branch: master commit 07e4aaaea05bdafbaf1900db0ec3acd3d130cf1c Author: Oleh Krehel Commit: Oleh Krehel hydra-test.el: add test * README.md: update. --- README.md | 42 ++ hydra-test.el | 429 - 2 files changed, 433 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index c2f7631..7272098 100644 --- a/README.md +++ b/README.md @@ -195,3 +195,45 @@ after the body. For example: ("k" previous-line) ("q" nil "quit"))) ``` + +## New Hydra color: amaranth + +Since version `0.8.0`, a new color - amaranth, in addition to the previous red and blue, is +available for the Hydra body. + +According to [Wikipedia](http://en.wikipedia.org/wiki/Amaranth): + +> The word amaranth comes from the Greek word amaranton, meaning "unwilting" (from the +> verb marainesthai, meaning "wilt"). The word was applied to amaranth because it did not +> soon fade and so symbolized immortality. + +Hydras with amaranth body are impossible to quit with any binding *except* a blue head. +A check for at least one blue head exists in `defhydra`, so that you don't get stuck by accident. + +Here's an example of an amaranth Hydra: + +```cl +(global-set-key + (kbd "C-z") + (defhydra hydra-vi + (:pre + (set-cursor-color "#40e0d0") + :post + (set-cursor-color "#ff") + :color amaranth) + "vi" + ("l" forward-char) + ("h" backward-char) + ("j" next-line) + ("k" previous-line) + ("q" nil "quit"))) +``` + +The only way to exit it, is to press q. No other methods will work. You can +use an amaranth Hydra instead of a red one, if for you the cost of being able to exit only +though certain bindings is less than the cost of accidentally exiting a red Hydra by +pressing the wrong prefix. + +Note that it does not make sense to define a singe amaranth head, so this color can only +be assigned to the body. An amaranth body will always have some amaranth heads and some +blue heads (otherwise, it's impossible to exit), no reds. diff --git a/hydra-test.el b/hydra-test.el index f3b4094..eee851a 100644 --- a/hydra-test.el +++ b/hydra-test.el @@ -26,7 +26,7 @@ (require 'ert) -(ert-deftest defhydra-red-error () +(ert-deftest hydra-red-error () (should (equal (macroexpand @@ -255,8 +255,8 @@ The body can be accessed via `toggle/body'. Call the head: `toggle-truncate-lines'." (interactive) -(hydra-disable) -(call-interactively (function toggle-truncate-lines))) + (hydra-disable) + (call-interactively (function toggle-truncate-lines))) (defun toggle/auto-fill-mode nil "Create a hydra with no body and the heads: \"t\":`toggle-truncate-lines', @@ -268,8 +268,8 @@ The body can be accessed via `toggle/body'. Call the head: `auto-fill-mode'." (interactive) -(hydra-disable) -(call-interactively (function auto-fill-mode))) + (hydra-disable) + (call-interactively (function auto-fill-mode))) (defun toggle/abbrev-mode nil "Create a hydra with no body and the heads: \"t\":`toggle-truncate-lines', @@ -281,8 +281,8 @@ The body can be accessed via `toggle/body'. Call the head: `abbrev-mode'." (interactive) -(hydra-disable) -(call-interactively (function abbrev-mode))) + (hydra-disable) + (call-interactively (function abbrev-mode))) (defun toggle/nil nil "Create a hydra with no body and the heads: \"t\":`toggle-truncate-lines', @@ -294,7 +294,7 @@ The body can be accessed via `toggle/body'. Call the head: `nil'." (interactive) -(hydra-disable)) + (hydra-disable)) (defun toggle/body nil "Create a hydra with no body and the heads: \"t\":`toggle-truncate-lines', @@ -304,40 +304,393 @@ Call the head: `nil'." The body can be accessed via `toggle/body'." (interactive) -(when hydra-is-helpful (message #("toggle: [t]: truncate, [f]: fill, [a]: abbrev, [q]: cancel." 9 10 (face hydra-face-blue) - 24 25 (face hydra-face-blue) - 35 36 (face hydra-face-blue) - 48 49 (face hydra-face-blue + (when hydra-is-helpful (message #("toggle: [t]: truncate, [f]: fill, [a]: abbrev, [q]: cancel." 9 10 (face hydra-face-blue) + 24 25 (face hydra-face-blue) + 35 36 (face hydra-face-blue) + 48 49 (face hydra-face-blue (setq hydra-last (hydra-set-transient-map '(keymap (113 . toggle/nil) - (97 . toggle/abbrev-mode) - (102 . toggle/auto-fill-mode) -
[elpa] master 37b6177 3/7: README.md: update for 0.7.0
branch: master commit 37b6177dcdcdc8b849d8119b09e6ec1c463351c1 Author: Oleh Krehel Commit: Oleh Krehel README.md: update for 0.7.0 --- README.md | 24 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/README.md b/README.md index 0686965..c2f7631 100644 --- a/README.md +++ b/README.md @@ -171,3 +171,27 @@ Since version `0.6.0`, for any Hydra: - `digit-argment` can be called with 0-9. - `negative-argument` can be called with - - `universal-argument` can be called with C-u + +## Hydras can have `:pre` and `:post` statements + +Since version `0.7.0`, you can specify code that will be called before each head, and +after the body. For example: + +```cl +(global-set-key + (kbd "C-z") + (defhydra hydra-vi + (:pre + (set-cursor-color "#40e0d0") + :post + (progn +(set-cursor-color "#ff") +(message + "Thank you, come again."))) + "vi" + ("l" forward-char) + ("h" backward-char) + ("j" next-line) + ("k" previous-line) + ("q" nil "quit"))) +```
[elpa] master updated (2fb700c -> f664821)
jackson pushed a change to branch master. from 2fb700c Merge commit '68bcaa8d8df5518217a3833fd1bb400c8225fe02' from hydra new 15b38a8 Cleanup. new c4459fe Fix faces on light tty backgrounds. Be more conservative about applying themes. new 807f484 Allow themes to be overridden, but warn. new 2875503 Write and pass tests for context-coloring-define-theme and recede and override properties. new 2b6d30e Document context-coloring-define-theme. new 4c7082f Spaces. new ce5c6d9 Write and pass post-recede test. new 874982e Update test names. new 06efd73 Fix assertion so tests fail. new 06a7606 Pass / update tests for warnings. new 2090e5d Add missing case for a theme that does not set faces. new 23a12b8 Rename test. new 0f036c9 Improve documentation for themes. new 71a1a0c Rename ambiguous "defined" to "originally set". new 6e6bc61 Rename themep to theme-p. new ca7122c Remove `when'. new cda491a Long lines. new 9d55bd6 Generalize assertions. Write failing test for disabling. new 2b687ae Pass test for disabling. new a197a8c Add disclaimer about precedence. new 6eef78b Add spacegray theme. new 3bd7e26 Add anti-zenburn theme. new 35b3e71 Add ample theme. new 0b42ae1 Add grandshell theme. new 0b8d03d Update readme. new fb14816 Update readme. new 2889b27 Mark unused lexical argument. new 352a8b0 Delete deprecated function. new c2b6999 Version 5.0.0. new 6f3ad75 Update test function documentation. new f664821 Merge commit '6f3ad757155b9b3089aba55ee6102ecc9bed647d' from context-coloring Summary of changes: packages/context-coloring/README.md| 12 +- packages/context-coloring/context-coloring.el | 333 ++ .../context-coloring/test/context-coloring-test.el | 384 +++- 3 files changed, 643 insertions(+), 86 deletions(-)
[elpa] master 874982e 08/31: Update test names.
branch: master commit 874982e34b05e4325612eae4b8053c9e24738fc0 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Update test names. --- test/context-coloring-test.el | 10 +- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index c81be7c..e5e9740 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -377,7 +377,7 @@ t for a theme with SETTINGS." (disable-theme theme) (context-coloring-set-colors-default)) -(context-coloring-test-deftest-define-theme preexisting-set +(context-coloring-test-deftest-define-theme additive (context-coloring-test-deftheme theme) (context-coloring-define-theme theme @@ -396,7 +396,7 @@ t for a theme with SETTINGS." theme) "*Warnings*")) -(context-coloring-test-deftest-define-theme preexisting-unintentional-override +(context-coloring-test-deftest-define-theme unintentional-override (context-coloring-test-deftheme theme) (custom-theme-set-faces theme @@ -413,7 +413,7 @@ t for a theme with SETTINGS." (context-coloring-test-assert-face 0 "#cc") (context-coloring-test-assert-face 1 "#dd")) -(context-coloring-test-deftest-define-theme preexisting-intentional-override +(context-coloring-test-deftest-define-theme intentional-override (context-coloring-test-deftheme theme) (custom-theme-set-faces theme @@ -463,7 +463,7 @@ t for a theme with SETTINGS." (context-coloring-test-assert-face 0 "#aa") (context-coloring-test-assert-face 1 "#bb")) -(context-coloring-test-deftest-define-theme preexisting-unintentional-obstinance +(context-coloring-test-deftest-define-theme unintentional-obstinance (context-coloring-define-theme theme :colors '("#aa" @@ -478,7 +478,7 @@ t for a theme with SETTINGS." (context-coloring-test-assert-face 0 "#aa") (context-coloring-test-assert-face 1 "#bb")) -(context-coloring-test-deftest-define-theme preexisting-intentional-obstinance +(context-coloring-test-deftest-define-theme intentional-obstinance (context-coloring-define-theme theme :override t
[elpa] master 2875503 04/31: Write and pass tests for context-coloring-define-theme and recede and override properties.
branch: master commit 2875503d488a8f358400c1d863200f3e854530b4 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Write and pass tests for context-coloring-define-theme and recede and override properties. --- context-coloring.el | 35 +++-- test/context-coloring-test.el | 156 +++-- 2 files changed, 179 insertions(+), 12 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 2dcf183..5f2a433 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -500,6 +500,10 @@ for THEME, nil otherwise." (setq tail (cdr tail))) found)) +(defun context-coloring-warn-theme-defined (theme) + "Warns the user that the colors for a theme are already defined." + (warn "Context coloring colors for theme `%s' are already defined" theme)) + (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 @@ -545,10 +549,12 @@ which must already exist and which *should* already be enabled." PROPERTIES is a property list specifiying the following details: `:colors': List of colors that this theme uses." - (let ((aliases (plist-get properties :aliases))) + (let ((aliases (plist-get properties :aliases)) +(override (plist-get properties :override))) (dolist (name (append `(,theme) aliases)) - (when (context-coloring-theme-definedp name) -(warn "Colors for `%s' are already defined" name)) + (when (and (not override) + (context-coloring-theme-definedp name)) +(context-coloring-warn-theme-defined name)) (puthash name properties context-coloring-theme-hash-table) ;; Set (or overwrite) colors. (when (custom-theme-p name) @@ -564,12 +570,22 @@ PROPERTIES is a property list specifiying the following details: "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))) + (let* ((properties (gethash theme context-coloring-theme-hash-table)) + (recede (plist-get properties :recede)) + (override (plist-get properties :override))) (cond - ((> highest-level -1) - (setq context-coloring-face-count (+ highest-level 1))) + (recede + (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) (t - (context-coloring-apply-theme theme) + (let ((defined (context-coloring-theme-definedp theme))) +(when (and defined (not override)) + (context-coloring-warn-theme-defined theme)) +(context-coloring-apply-theme theme)) (defadvice enable-theme (after context-coloring-enable-theme (theme) activate) "Enable colors for themes just-in-time. We can't set faces for @@ -581,6 +597,7 @@ themes that might not exist yet." (context-coloring-define-theme 'leuven + :recede t :colors '("#33" "#FF" "#6434A3" @@ -593,6 +610,7 @@ themes that might not exist yet." (context-coloring-define-theme 'monokai + :recede t :colors '("#F8F8F2" "#66D9EF" "#A1EFE4" @@ -605,6 +623,7 @@ themes that might not exist yet." (context-coloring-define-theme 'solarized + :recede t :aliases '(solarized-light solarized-dark sanityinc-solarized-light @@ -629,6 +648,7 @@ themes that might not exist yet." (context-coloring-define-theme 'tango + :recede t :colors '("#2e3436" "#346604" "#204a87" @@ -645,6 +665,7 @@ themes that might not exist yet." (context-coloring-define-theme 'zenburn + :recede t :colors '("#DCDCCC" "#93E0E3" "#BFEBBF" diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 168b6fa..c6a29e6 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -19,6 +19,9 @@ ;;; Code: +(require 'ert-async) + + ;;; Test running utilities (defconst context-coloring-test-path @@ -205,16 +208,31 @@ EXPECTED-FACE." (context-coloring-test-assert-region-face start end 'font-lock-string-face)) -(defun context-coloring-test-assert-message (expected) - "Assert that the *Messages* buffer has message EXPECTED." - (with-current-buffer "*Messages*" +(defun context-coloring-test-assert-message (expected buffer) + "Assert that BUFFER has message EXPECTED." + (with-current-buffer buffer (let ((messages (split-string (buffer-substring-no-properties (point-min) (point-max)) "\n"))) (let ((message (car (nthcdr (- (length messages) 2) messages -(should (equal mes
[elpa] master 0b42ae1 24/31: Add grandshell theme.
branch: master commit 0b42ae19e84206c519b61a964507d6e15ffb6f77 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add grandshell theme. --- context-coloring.el | 12 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index f83b5b0..a549b9d 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -710,6 +710,18 @@ faces for custom themes that might not exist yet." "#235c5c")) (context-coloring-define-theme + 'grandshell + :recede t + :colors '("#bebebe" + "#5af2ee" + "#b2baf6" + "#f09fff" + "#efc334" + "#f6df92" + "#acfb5a" + "#88")) + +(context-coloring-define-theme 'leuven :recede t :colors '("#33"
[elpa] master 15b38a8 01/31: Cleanup.
branch: master commit 15b38a8af92cf0a0725ed15fcc9389bd7ddbc01d Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Cleanup. --- README.md |2 -- context-coloring.el | 11 ++- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 21ba184..0914475 100644 --- a/README.md +++ b/README.md @@ -171,9 +171,7 @@ required. [linter]: http://jshint.com/about/ [flycheck]: http://www.flycheck.org/ -[zenburn]: http://github.com/bbatsov/zenburn-emacs [point]: http://www.gnu.org/software/emacs/manual/html_node/elisp/Point.html [js2-mode]: https://github.com/mooz/js2-mode [node]: http://nodejs.org/download/ [scopifier]: https://github.com/jacksonrayhamilton/scopifier -[load path]: https://www.gnu.org/software/emacs/manual/html_node/emacs/Lisp-Libraries.html diff --git a/context-coloring.el b/context-coloring.el index 6af9444..836a66c 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -56,13 +56,6 @@ (require 'js2-mode) -;;; Constants - -(defconst context-coloring-path - (file-name-directory (or load-file-name buffer-file-name)) - "This file's directory.") - - ;;; Customizable options (defcustom context-coloring-delay 0.25 @@ -81,8 +74,8 @@ Supported modes: `js-mode', `js3-mode'" (defcustom context-coloring-js-block-scopes nil "If non-nil, also color block scopes in the scope hierarchy in JavaScript. -The block-scope-inducing `let' and `const' are introduced in ES6. -If you are writing ES6 code, enable this; otherwise, don't. +The block-scoped `let' and `const' are introduced in ES6. If you +are writing ES6 code, enable this; otherwise, don't. Supported modes: `js2-mode'" :group 'context-coloring)
[elpa] master 807f484 03/31: Allow themes to be overridden, but warn.
branch: master commit 807f484f511a9bfd58d0dd89eb11eacce3b96b33 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton 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 "#88") (context-coloring-test-assert-face 9 "#99")) +(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)
[elpa] master 23a12b8 12/31: Rename test.
branch: master commit 23a12b83551a722709de6e77960266ac644b45d8 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Rename test. --- test/context-coloring-test.el |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 757f0d7..aa24087 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -477,7 +477,7 @@ t for a theme with SETTINGS." (context-coloring-test-assert-face 0 "#aa") (context-coloring-test-assert-face 1 "#bb")) -(context-coloring-test-deftest-define-theme post-recede-not-defined +(context-coloring-test-deftest-define-theme recede-not-defined (context-coloring-test-deftheme theme) (custom-theme-set-faces theme
[elpa] master 71a1a0c 14/31: Rename ambiguous "defined" to "originally set".
branch: master commit 71a1a0cd62304e446f42c42e27af71e1d601ee0e Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Rename ambiguous "defined" to "originally set". --- context-coloring.el | 68 ++-- test/context-coloring-test.el | 28 + 2 files changed, 52 insertions(+), 44 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 9dcaf33..9554fdf 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -485,17 +485,22 @@ would be redundant." "context-coloring-level-\\([[:digit:]]+\\)-face" "Regular expression for extracting a level from a face.") -(defvar context-coloring-defined-theme-hash-table (make-hash-table :test 'eq) +(defvar context-coloring-originally-set-theme-hash-table (make-hash-table :test 'eq) "Cache of custom themes who originally set their own `context-coloring-level-N-face' faces.") -(defun context-coloring-theme-definedp (theme) - "Return t if there is a `context-coloring-level-N-face' defined -for THEME, nil otherwise." - (let (defined) +(defun context-coloring-theme-originally-set-p (theme) + "Return t if there is a `context-coloring-level-N-face' +originally set for THEME, nil otherwise." + (let (originally-set) (cond - ((setq defined (gethash theme context-coloring-defined-theme-hash-table)) - (eq defined 'defined)) + ;; `setq' might return a non-nil value for the sake of this `cond'. + ((setq + originally-set + (gethash +theme +context-coloring-originally-set-theme-hash-table)) + (eq originally-set 'yes)) (t (let* ((settings (get theme 'theme-settings)) (tail settings) @@ -509,25 +514,26 @@ for THEME, nil otherwise." (setq tail (cdr tail))) found) -(defun context-coloring-cache-defined (theme defined) - "Remember if THEME had colors defined for it; if DEFINED is -non-nil, it did, otherwise it didn't." - ;; Caching the definededness of a theme is kind of dirty, but we have to do it - ;; to remember the past state of the theme. There are probably some edge cases - ;; where caching will be an issue, but they are probably rare. +(defun context-coloring-cache-originally-set (theme originally-set) + "Remember if THEME had colors originally set for it; if +ORIGINALLY-SET is non-nil, it did, otherwise it didn't." + ;; Caching whether a theme was originally set is kind of dirty, but we have to + ;; do it to remember the past state of the theme. There are probably some + ;; edge cases where caching will be an issue, but they are probably rare. (puthash theme - (if defined 'defined 'undefined) - context-coloring-defined-theme-hash-table)) + (if originally-set 'yes 'no) + context-coloring-originally-set-theme-hash-table)) -(defun context-coloring-warn-theme-defined (theme) - "Warns the user that the colors for a theme are already defined." +(defun context-coloring-warn-theme-originally-set (theme) + "Warns the user that the colors for a theme are already +originally set." (warn "Context coloring colors for theme `%s' are already defined" theme)) (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 -is none." +`context-coloring-level-N-face' set for THEME, or -1 if there is +none." (let* ((settings (get theme 'theme-settings)) (tail settings) face-string @@ -598,18 +604,18 @@ use your custom theme's author's colors instead." (dolist (name (append `(,theme) aliases)) (puthash name properties context-coloring-theme-hash-table) (when (custom-theme-p name) -(let ((defined (context-coloring-theme-definedp name))) - (context-coloring-cache-defined name defined) +(let ((originally-set (context-coloring-theme-originally-set-p name))) + (context-coloring-cache-originally-set name originally-set) ;; In the particular case when you innocently define colors that a - ;; custom theme already sets, warn. Arguably this only has to be done - ;; at enable time, but it is probably more useful to do it at + ;; custom theme originally set, warn. Arguably this only has to be + ;; done at enable time, but it is probably more useful to do it at ;; definition time for prompter feedback. - (when (and defined + (when (and originally-set (not recede) (not override)) -(context-coloring-warn-theme-defined name)) +(context-coloring-warn-theme-originally-set name)) ;; Set (or overwrite) colors. - (when (not (and defined + (when (not (and originally-set recede)) (context-coloring-apply-theme name))) @@ -620,7 +626,7 @@ use your custom theme's author's colors inst
[elpa] master 9d55bd6 18/31: Generalize assertions. Write failing test for disabling.
branch: master commit 9d55bd60b5b6b454a75dc6365c2c24f7618b86b8 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Generalize assertions. Write failing test for disabling. --- test/context-coloring-test.el | 97 1 files changed, 77 insertions(+), 20 deletions(-) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index a24a60b..dcad8e3 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -249,21 +249,31 @@ EXPECTED-FACE." "Kill BUFFER if it exists." (if (get-buffer buffer) (kill-buffer buffer))) -(defun context-coloring-test-assert-face (level foreground) +(defun context-coloring-test-assert-face (level foreground &optional negate) "Assert that a face for LEVEL exists and that its `:foreground' is FOREGROUND." (let* ((face (context-coloring-face-symbol level)) actual-foreground) -(when (not face) +(when (not (or negate + face)) (ert-fail (format (concat "Expected face for level `%s' to exist; " "but it didn't") level))) (setq actual-foreground (face-attribute face :foreground)) -(when (not (string-equal foreground actual-foreground)) +(when (funcall (if negate 'identity 'not) + (string-equal foreground actual-foreground)) (ert-fail (format (concat "Expected face for level `%s' " -"to have foreground `%s'; but it was `%s'") +"%sto have foreground `%s'; " +"but it %s.") level -foreground actual-foreground) +(if negate "not " "") foreground +(if negate "did" (format "was `%s'" actual-foreground))) + +(defun context-coloring-test-assert-not-face (&rest arguments) + "Assert that LEVEL does not have a face with `:foreground' +FOREGROUND." + (apply 'context-coloring-test-assert-face + (append arguments '(t ;;; The tests @@ -348,33 +358,42 @@ return t for a theme with SETTINGS." '((theme-face face))) ) -(defun context-coloring-test-assert-theme-highest-level (settings expected-level) - (let (theme) +(defun context-coloring-test-assert-theme-settings-highest-level +(settings expected-level) + (let ((theme (context-coloring-test-get-next-theme))) (put theme 'theme-settings settings) -(let ((highest-level (context-coloring-theme-highest-level theme))) - (when (not (eq highest-level expected-level)) -(ert-fail (format (concat "Expected theme with settings `%s' " - "to have a highest level of `%s', " - "but it was %s.") - settings - expected-level - highest-level)) +(context-coloring-test-assert-theme-highest-level theme expected-level))) + +(defun context-coloring-test-assert-theme-highest-level +(theme expected-level &optional negate) + (let ((highest-level (context-coloring-theme-highest-level theme))) +(when (funcall (if negate 'identity 'not) (eq highest-level expected-level)) + (ert-fail (format (concat "Expected theme with settings `%s' " +"%sto have a highest level of `%s', " +"but it %s.") +(get theme 'theme-settings) +(if negate "not " "") expected-level +(if negate "did" (format "was %s" highest-level))) + +(defun context-coloring-test-assert-theme-not-highest-level (&rest arguments) + (apply 'context-coloring-test-assert-theme-highest-level + (append arguments '(t (ert-deftest context-coloring-test-theme-highest-level () - (context-coloring-test-assert-theme-highest-level + (context-coloring-test-assert-theme-settings-highest-level '((theme-face foo)) -1) - (context-coloring-test-assert-theme-highest-level + (context-coloring-test-assert-theme-settings-highest-level '((theme-face context-coloring-level-0-face)) 0) - (context-coloring-test-assert-theme-highest-level + (context-coloring-test-assert-theme-settings-highest-level '((theme-face context-coloring-level-1-face)) 1) - (context-coloring-test-assert-theme-highest-level + (context-coloring-test-assert-theme-settings-highest-level '((theme-face context-coloring-level-1-face) (theme-face context-coloring-level-0-face)) 1) - (context-coloring-test-assert-theme-highest-level + (context-coloring-test-assert-theme-settings-highest-level '((theme-face context-coloring-level-0-face) (theme-face context-coloring-level-1-face)) 1) @@ -534,6 +553,44 @@ return t for a theme with SETTINGS." (context-coloring-test-assert-face 0 "#aa") (context-coloring-test-assert-face
[elpa] master ca7122c 16/31: Remove `when'.
branch: master commit ca7122ceecf6f06dad063b93c6957299e7bea886 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Remove `when'. --- context-coloring.el | 11 --- 1 files changed, 4 insertions(+), 7 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 52a494b..c58cf67 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -765,7 +765,7 @@ faces for custom themes that might not exist yet." (font-lock-mode) (jit-lock-mode t)) -;; Remember this buffer. This value should not be dynamically-bound. +;; Remember this buffer. This value should not be dynamically-bound. (setq context-coloring-buffer (current-buffer)) ;; Font lock is incompatible with this mode; the converse is also true. @@ -780,16 +780,13 @@ faces for custom themes that might not exist yet." ;; Only recolor on reparse. (add-hook 'js2-post-parse-callbacks 'context-coloring-colorize nil t)) (t - ;; Only recolor on change. - (add-hook 'after-change-functions 'context-coloring-change-function nil t))) - -(when (not (equal major-mode 'js2-mode)) - ;; Only recolor idly. + ;; Only recolor on change, idly. + (add-hook 'after-change-functions 'context-coloring-change-function nil t) (setq context-coloring-colorize-idle-timer (run-with-idle-timer context-coloring-delay t - 'context-coloring-maybe-colorize) + 'context-coloring-maybe-colorize)) (provide 'context-coloring)
[elpa] master 6eef78b 21/31: Add spacegray theme.
branch: master commit 6eef78b0e631c42e53bbf2845ab9c70fce998ff9 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add spacegray theme. --- context-coloring.el | 12 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 7267d78..c1a8bc6 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -734,6 +734,18 @@ faces for custom themes that might not exist yet." "#9EA0E5")) (context-coloring-define-theme + 'spacegray + :recede t + :colors '("#ff" + "#89AAEB" + "#C189EB" + "#bf616a" + "#DCA432" + "#ebcb8b" + "#B4EB89" + "#89EBCA")) + +(context-coloring-define-theme 'tango :recede t :colors '("#2e3436"
[elpa] master 0f036c9 13/31: Improve documentation for themes.
branch: master commit 0f036c9ac66734a78e9c6aabc14246c990ae5781 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Improve documentation for themes. --- context-coloring.el | 55 +++--- 1 files changed, 34 insertions(+), 21 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index ede7e9b..9dcaf33 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -565,32 +565,33 @@ which must already exist and which *should* already be enabled." colors (defun context-coloring-define-theme (theme &rest properties) - "Define a theme named THEME for coloring scope levels. + "Define a context theme named THEME for coloring scope levels. PROPERTIES is a property list specifiying the following details: `:aliases': List of symbols of other custom themes that these colors are applicable to. -`:colors': List of colors that this theme uses. +`:colors': List of colors that this context theme uses. -`:override': If non-nil, this theme is intentionally overriding -colors set by a custom theme. Don't set this non-nil unless -there is a theme you want to use which sets +`:override': If non-nil, this context theme is intentionally +overriding colors set by a custom theme. Don't set this non-nil +unless there is a custom theme you want to use which sets `context-coloring-level-N-face' faces that you want to replace. -`:recede': If non-nil, this theme should not apply its colors if -a custom theme already sets `context-coloring-level-N-face' -faces. This option is optimistic; set this non-nil if you would -rather confer the duty of picking colors to a theme author (if / -when he ever gets around to it). - -By default, themes will always override custom themes, even if -those custom themes set `context-coloring-level-N-face' faces. -If a theme does override a custom theme, a warning will be -raised, at which point you may want to enable the `:override' -option, or just delete your theme and opt to use your custom -theme's author's colors instead." +`:recede': If non-nil, this context theme should not apply its +colors if a custom theme already sets +`context-coloring-level-N-face' faces. This option is +optimistic; set this non-nil if you would rather confer the duty +of picking colors to a custom theme author (if / when he ever +gets around to it). + +By default, context themes will always override custom themes, +even if those custom themes set `context-coloring-level-N-face' +faces. If a context theme does override a custom theme, a +warning will be raised, at which point you may want to enable the +`:override' option, or just delete your context theme and opt to +use your custom theme's author's colors instead." (let ((aliases (plist-get properties :aliases)) (override (plist-get properties :override)) (recede (plist-get properties :recede))) @@ -599,6 +600,10 @@ theme's author's colors instead." (when (custom-theme-p name) (let ((defined (context-coloring-theme-definedp name))) (context-coloring-cache-defined name defined) + ;; In the particular case when you innocently define colors that a + ;; custom theme already sets, warn. Arguably this only has to be done + ;; at enable time, but it is probably more useful to do it at + ;; definition time for prompter feedback. (when (and defined (not recede) (not override)) @@ -611,7 +616,7 @@ theme's author's colors instead." (defun context-coloring-load-theme (&optional rest) (declare (obsolete -"themes are now loaded alongside custom themes automatically." +"context themes are now loaded alongside custom themes automatically." "4.1.0"))) (defun context-coloring-enable-theme (theme) @@ -625,13 +630,21 @@ THEME." (recede (let ((highest-level (context-coloring-theme-highest-level theme))) (cond + ;; This can be true whether originally set by a custom theme or by a + ;; context theme. ((> highest-level -1) (setq context-coloring-face-count (+ highest-level 1))) + ;; It is possible that the corresponding custom theme did not exist at + ;; the time of defining this context theme, and in that case the above + ;; condition proves the custom theme did not originally set any faces, + ;; so we have license to apply the context theme for the first time + ;; here. (t (context-coloring-apply-theme theme) (t (let ((defined (context-coloring-theme-definedp theme))) -;; Cache now in case the theme was defined after. +;; Cache now in case the context theme was defined after the custom +;; theme. (context-coloring-cache-defined theme defined) (when (and defined (not override)) @@ -639,8 +652,8 @@ THEME." (context-coloring-a
[elpa] master 2b687ae 19/31: Pass test for disabling.
branch: master commit 2b687aee163eb50f5baf924850584251839f2882 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Pass test for disabling. --- context-coloring.el | 15 --- test/context-coloring-test.el | 31 +++ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 054cdbc..bcbe86e 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -665,11 +665,20 @@ THEME." (defadvice enable-theme (after context-coloring-enable-theme (theme) activate) "Enable colors for context themes just-in-time. We can't set faces for custom themes that might not exist yet." - (when (and (not (eq theme 'user)) ; Called internally by `enable-theme'. - (context-coloring-theme-p theme) - (custom-theme-p theme)) ; Guard against non-existent themes. + (when (and (not (eq theme 'user)) ; Called internally by `enable-theme'. + (custom-theme-p theme) ; Guard against non-existent themes. + (context-coloring-theme-p theme)) (context-coloring-enable-theme theme))) +(defadvice disable-theme (after context-coloring-disable-theme (theme) activate) + "Colors are disabled normally, but +`context-coloring-face-count' isn't. Update it here." + (when (custom-theme-p theme) ; Guard against non-existent themes. +(let ((enabled-theme (car custom-enabled-themes))) + (if (context-coloring-theme-p enabled-theme) + (context-coloring-enable-theme enabled-theme) +(context-coloring-set-colors-default) + (context-coloring-define-theme 'leuven :recede t diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index dcad8e3..8c79b4c 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -568,21 +568,36 @@ return t for a theme with SETTINGS." (apply 'context-coloring-test-assert-face-count (append arguments '(t -(context-coloring-test-deftest-define-theme disable +(context-coloring-test-deftest-define-theme disable-cascade (context-coloring-test-deftheme theme) (context-coloring-define-theme theme :colors '("#aa" "#bb")) - (let ((other-theme (context-coloring-test-get-next-theme))) -(context-coloring-test-deftheme other-theme) + (let ((second-theme (context-coloring-test-get-next-theme))) +(context-coloring-test-deftheme second-theme) (context-coloring-define-theme - other-theme + second-theme :colors '("#cc" - "#dd")) -(enable-theme theme) -(enable-theme other-theme) -(disable-theme other-theme) + "#dd" + "#ee")) +(let ((third-theme (context-coloring-test-get-next-theme))) + (context-coloring-test-deftheme third-theme) + (context-coloring-define-theme + third-theme + :colors '("#11" + "#22" + "#33" + "#44")) + (enable-theme theme) + (enable-theme second-theme) + (enable-theme third-theme) + (disable-theme third-theme) + (context-coloring-test-assert-face 0 "#cc") + (context-coloring-test-assert-face 1 "#dd") + (context-coloring-test-assert-face 2 "#ee") + (context-coloring-test-assert-face-count 3)) +(disable-theme second-theme) (context-coloring-test-assert-face 0 "#aa") (context-coloring-test-assert-face 1 "#bb") (context-coloring-test-assert-face-count 2))
[elpa] master 6f3ad75 30/31: Update test function documentation.
branch: master commit 6f3ad757155b9b3089aba55ee6102ecc9bed647d Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Update test function documentation. --- test/context-coloring-test.el | 12 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 8c79b4c..fdb0d83 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -360,12 +360,15 @@ return t for a theme with SETTINGS." (defun context-coloring-test-assert-theme-settings-highest-level (settings expected-level) + "Assert that a theme with SETTINGS has the highest level +EXPECTED-LEVEL." (let ((theme (context-coloring-test-get-next-theme))) (put theme 'theme-settings settings) (context-coloring-test-assert-theme-highest-level theme expected-level))) (defun context-coloring-test-assert-theme-highest-level (theme expected-level &optional negate) + "Assert that THEME has the highest level EXPECTED-LEVEL." (let ((highest-level (context-coloring-theme-highest-level theme))) (when (funcall (if negate 'identity 'not) (eq highest-level expected-level)) (ert-fail (format (concat "Expected theme with settings `%s' " @@ -376,6 +379,7 @@ return t for a theme with SETTINGS." (if negate "did" (format "was %s" highest-level))) (defun context-coloring-test-assert-theme-not-highest-level (&rest arguments) + "Assert that THEME's highest level is not EXPECTED-LEVEL." (apply 'context-coloring-test-assert-theme-highest-level (append arguments '(t @@ -400,6 +404,9 @@ return t for a theme with SETTINGS." ) (defmacro context-coloring-test-deftest-define-theme (name &rest body) + "Define a test with an automatically-generated theme symbol +available as a free variable `theme'. Side-effects from enabling +themes are reversed after the test completes." (declare (indent defun)) (let ((deftest-name (intern (format "context-coloring-test-define-theme-%s" name @@ -414,6 +421,7 @@ return t for a theme with SETTINGS." (context-coloring-set-colors-default)) (defun context-coloring-test-deftheme (theme) + "Dynamically define theme THEME." (eval (macroexpand `(deftheme ,theme (context-coloring-test-deftest-define-theme additive @@ -429,6 +437,8 @@ return t for a theme with SETTINGS." (context-coloring-test-assert-face 1 "#bb")) (defun context-coloring-test-assert-defined-warning (theme) + "Assert that a warning about colors already being defined for +theme THEME is signaled." (context-coloring-test-assert-message (format (concat "Warning (emacs): Context coloring colors for theme " "`%s' are already defined") @@ -554,6 +564,7 @@ return t for a theme with SETTINGS." (context-coloring-test-assert-face 1 "#bb")) (defun context-coloring-test-assert-face-count (count &optional negate) + "Assert that `context-coloring-face-count' is COUNT." (when (funcall (if negate 'identity 'not) (eq context-coloring-face-count count)) (ert-fail (format (concat "Expected `context-coloring-face-count' " @@ -565,6 +576,7 @@ return t for a theme with SETTINGS." (format "was `%s'" context-coloring-face-count)) (defun context-coloring-test-assert-not-face-count (&rest arguments) + "Assert that `context-coloring-face-count' is not COUNT." (apply 'context-coloring-test-assert-face-count (append arguments '(t
[elpa] master 2b6d30e 05/31: Document context-coloring-define-theme.
branch: master commit 2b6d30e4793e75df1be761d7cc1f8f0585180a00 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Document context-coloring-define-theme. --- context-coloring.el | 24 +++- 1 files changed, 23 insertions(+), 1 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 5f2a433..d0c7ba2 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -546,9 +546,31 @@ which must already exist and which *should* already be enabled." (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." +`:aliases': List of symbols of other custom themes that these +colors are applicable to. + +`:colors': List of colors that this theme uses. + +`:override': If non-nil, this theme is intentionally overriding +colors set by a custom theme. Don't set this non-nil unless there +is a theme you want to use which sets +`context-coloring-level-N-face' faces that you want to replace. + +`:recede': If non-nil, this theme should not apply its colors if +a custom theme already sets `context-coloring-level-N-face' +faces. This option is optimistic; set this non-nil if you would +rather confer the duty of picking colors to a theme author (if / +when he ever gets around to it). + +By default, themes will always override custom themes, even if +those custom themes set `context-coloring-level-N-face' faces. +If a theme does override a custom theme, a warning will be +raised, at which point you may want to enable the `:override' +option, or just delete your theme and opt to use your custom +theme's author's colors instead." (let ((aliases (plist-get properties :aliases)) (override (plist-get properties :override))) (dolist (name (append `(,theme) aliases))
[elpa] master ce5c6d9 07/31: Write and pass post-recede test.
branch: master commit ce5c6d9ce510627dd5d879eeb738321192fc9e6a Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Write and pass post-recede test. --- context-coloring.el |9 ++--- test/context-coloring-test.el | 19 ++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 06bd92c..0f2f9fa3 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -572,14 +572,16 @@ raised, at which point you may want to enable the `:override' option, or just delete your theme and opt to use your custom theme's author's colors instead." (let ((aliases (plist-get properties :aliases)) -(override (plist-get properties :override))) +(override (plist-get properties :override)) +(recede (plist-get properties :recede))) (dolist (name (append `(,theme) aliases)) (when (and (not override) (context-coloring-theme-definedp name)) (context-coloring-warn-theme-defined name)) (puthash name properties context-coloring-theme-hash-table) ;; Set (or overwrite) colors. - (when (custom-theme-p name) + (when (and (custom-theme-p name) + (not recede)) (context-coloring-apply-theme name) (defun context-coloring-load-theme (&optional rest) @@ -605,7 +607,8 @@ THEME." (context-coloring-apply-theme theme) (t (let ((defined (context-coloring-theme-definedp theme))) -(when (and defined (not override)) +(when (and defined + (not override)) (context-coloring-warn-theme-defined theme)) (context-coloring-apply-theme theme)) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index c6a29e6..c81be7c 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -430,7 +430,7 @@ t for a theme with SETTINGS." (context-coloring-test-assert-face 0 "#cc") (context-coloring-test-assert-face 1 "#dd")) -(context-coloring-test-deftest-define-theme preexisting-recede +(context-coloring-test-deftest-define-theme pre-recede (context-coloring-define-theme theme :recede t @@ -446,6 +446,23 @@ t for a theme with SETTINGS." (context-coloring-test-assert-face 0 "#cc") (context-coloring-test-assert-face 1 "#dd")) +(context-coloring-test-deftest-define-theme post-recede + (context-coloring-test-deftheme theme) + (custom-theme-set-faces + theme + '(context-coloring-level-0-face ((t (:foreground "#aa" + '(context-coloring-level-1-face ((t (:foreground "#bb") + (context-coloring-define-theme + theme + :recede t + :colors '("#cc" + "#dd")) + (context-coloring-test-assert-no-message "*Warnings*") + (enable-theme theme) + (context-coloring-test-assert-no-message "*Warnings*") + (context-coloring-test-assert-face 0 "#aa") + (context-coloring-test-assert-face 1 "#bb")) + (context-coloring-test-deftest-define-theme preexisting-unintentional-obstinance (context-coloring-define-theme theme
[elpa] master c4459fe 02/31: Fix faces on light tty backgrounds. Be more conservative about applying themes.
branch: master commit c4459fe73b6ee58e64db3355b8036ec826e29773 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Fix faces on light tty backgrounds. Be more conservative about applying themes. --- context-coloring.el | 109 ++--- test/context-coloring-test.el | 38 -- 2 files changed, 113 insertions(+), 34 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 836a66c..b09ed1c 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -108,23 +108,28 @@ used.") ;;; Faces (defun context-coloring-defface (level tty light dark) + "Dynamically define a face for LEVEL with colors for TTY, LIGHT +and DARK backgrounds." (let ((face (intern (format "context-coloring-level-%s-face" level))) (doc (format "Context coloring face, level %s." level))) -(eval (macroexpand `(defface ,face - 'type tty)) (:foreground ,tty)) -(((background light)) (:foreground ,light)) -(((background dark)) (:foreground ,dark))) - ,doc - :group 'context-coloring) +(eval + (macroexpand + `(defface ,face + 'type tty)) (:foreground ,tty)) + (((background light)) (:foreground ,light)) + (((background dark)) (:foreground ,dark))) + ,doc + :group 'context-coloring) (defvar context-coloring-face-count nil - "Number of faces available for context coloring.") + "Number of faces available for coloring.") (defun context-coloring-defface-default (level) - (context-coloring-defface level "white" "#3f3f3f" "#cdcdcd")) + "Define a face for LEVEL with the default neutral colors." + (context-coloring-defface level nil "#3f3f3f" "#cdcdcd")) (defun context-coloring-set-colors-default () - (context-coloring-defface 0 "white" "#00" "#ff") + (context-coloring-defface 0 nil "#00" "#ff") (context-coloring-defface 1 "yellow" "#007f80" "#80") (context-coloring-defface 2 "green" "#001580" "#cdfacd") (context-coloring-defface 3 "cyan""#550080" "#d8d8ff") @@ -472,25 +477,70 @@ would be redundant." (defvar context-coloring-theme-hash-table (make-hash-table :test 'eq) "Mapping of theme names to theme properties.") +(defun context-coloring-themep (theme) + "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-highest-level (theme) + "Return the highest level N of a face like +`context-coloring-level-N-face' defined for THEME, or -1 if there +is none." + (let* ((settings (get theme 'theme-settings)) + (tail settings) + face-string + number + (found -1)) +(while tail + (and (eq (nth 0 (car tail)) 'theme-face) + (setq face-string (symbol-name (nth 1 (car tail + (string-match +context-coloring-level-face-regexp +face-string) + (setq number (string-to-number + (substring face-string +(match-beginning 1) +(match-end 1 + (> number found) + (setq found number)) + (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." - (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 ,colo
[elpa] master 6e6bc61 15/31: Rename themep to theme-p.
branch: master commit 6e6bc61f5674b04b713a719e3a656cd022d684e1 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Rename themep to theme-p. --- context-coloring.el |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 9554fdf..52a494b 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -477,7 +477,7 @@ would be redundant." (defvar context-coloring-theme-hash-table (make-hash-table :test 'eq) "Mapping of theme names to theme properties.") -(defun context-coloring-themep (theme) +(defun context-coloring-theme-p (theme) "Return t if THEME is defined, nil otherwise." (and (gethash theme context-coloring-theme-hash-table))) @@ -661,7 +661,7 @@ THEME." "Enable colors for context themes just-in-time. We can't set faces for custom themes that might not exist yet." (when (and (not (eq theme 'user)) ; Called internally by `enable-theme'. - (context-coloring-themep theme) + (context-coloring-theme-p theme) (custom-theme-p theme)) ; Guard against non-existent themes. (context-coloring-enable-theme theme)))
[elpa] master c2b6999 29/31: Version 5.0.0.
branch: master commit c2b6999814d6164029ddbcce829f0370bcd68fb5 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Version 5.0.0. --- context-coloring.el |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index c947d88..6b6ffe9 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -5,7 +5,7 @@ ;; Author: Jackson Ray Hamilton ;; URL: https://github.com/jacksonrayhamilton/context-coloring ;; Keywords: context coloring syntax highlighting -;; Version: 4.1.0 +;; Version: 5.0.0 ;; Package-Requires: ((emacs "24") (js2-mode "20150126")) ;; This file is part of GNU Emacs.
[elpa] master f664821 31/31: Merge commit '6f3ad757155b9b3089aba55ee6102ecc9bed647d' from context-coloring
branch: master commit f664821f71834b2b52d945551351ff82ebfacdf5 Merge: 2fb700c 6f3ad75 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Merge commit '6f3ad757155b9b3089aba55ee6102ecc9bed647d' from context-coloring --- packages/context-coloring/README.md| 12 +- packages/context-coloring/context-coloring.el | 333 ++ .../context-coloring/test/context-coloring-test.el | 384 +++- 3 files changed, 643 insertions(+), 86 deletions(-) diff --git a/packages/context-coloring/README.md b/packages/context-coloring/README.md index 21ba184..ff305c1 100644 --- a/packages/context-coloring/README.md +++ b/packages/context-coloring/README.md @@ -90,8 +90,9 @@ Add the following to your `~/.emacs` file: ## Customizing Color schemes for custom themes are automatically applied when those themes are -active. Built-in theme support is available for: `leuven`, `monokai`, -`solarized`, `tango` and `zenburn`. +active. Built-in theme support is available for: `ample`, `anti-zenburn`, +`grandshell`, `leuven`, `monokai`, `solarized`, `spacegray`, `tango` and +`zenburn`. You can define your own theme colors too: @@ -111,11 +112,14 @@ You can define your own theme colors too: "#DCA3A3")) ``` +See `C-h f context-coloring-define-theme` for more info on theme parameters. + ## Extending To add support for a new language, write a "scopifier" for it, and define a new coloring dispatch strategy with `context-coloring-define-dispatch`. Then the -plugin should handle the rest. +plugin should handle the rest. (See `C-h f context-coloring-define-dispatch` for +more info on dispatch strategies.) A "scopifier" is a CLI program that reads a buffer's contents from stdin and writes a JSON array of numbers to stdout. Every three numbers in the array @@ -171,9 +175,7 @@ required. [linter]: http://jshint.com/about/ [flycheck]: http://www.flycheck.org/ -[zenburn]: http://github.com/bbatsov/zenburn-emacs [point]: http://www.gnu.org/software/emacs/manual/html_node/elisp/Point.html [js2-mode]: https://github.com/mooz/js2-mode [node]: http://nodejs.org/download/ [scopifier]: https://github.com/jacksonrayhamilton/scopifier -[load path]: https://www.gnu.org/software/emacs/manual/html_node/emacs/Lisp-Libraries.html diff --git a/packages/context-coloring/context-coloring.el b/packages/context-coloring/context-coloring.el index 6af9444..6b6ffe9 100644 --- a/packages/context-coloring/context-coloring.el +++ b/packages/context-coloring/context-coloring.el @@ -5,7 +5,7 @@ ;; Author: Jackson Ray Hamilton ;; URL: https://github.com/jacksonrayhamilton/context-coloring ;; Keywords: context coloring syntax highlighting -;; Version: 4.1.0 +;; Version: 5.0.0 ;; Package-Requires: ((emacs "24") (js2-mode "20150126")) ;; This file is part of GNU Emacs. @@ -56,13 +56,6 @@ (require 'js2-mode) -;;; Constants - -(defconst context-coloring-path - (file-name-directory (or load-file-name buffer-file-name)) - "This file's directory.") - - ;;; Customizable options (defcustom context-coloring-delay 0.25 @@ -81,8 +74,8 @@ Supported modes: `js-mode', `js3-mode'" (defcustom context-coloring-js-block-scopes nil "If non-nil, also color block scopes in the scope hierarchy in JavaScript. -The block-scope-inducing `let' and `const' are introduced in ES6. -If you are writing ES6 code, enable this; otherwise, don't. +The block-scoped `let' and `const' are introduced in ES6. If you +are writing ES6 code, enable this; otherwise, don't. Supported modes: `js2-mode'" :group 'context-coloring) @@ -115,23 +108,28 @@ used.") ;;; Faces (defun context-coloring-defface (level tty light dark) + "Dynamically define a face for LEVEL with colors for TTY, LIGHT +and DARK backgrounds." (let ((face (intern (format "context-coloring-level-%s-face" level))) (doc (format "Context coloring face, level %s." level))) -(eval (macroexpand `(defface ,face - 'type tty)) (:foreground ,tty)) -(((background light)) (:foreground ,light)) -(((background dark)) (:foreground ,dark))) - ,doc - :group 'context-coloring) +(eval + (macroexpand + `(defface ,face + 'type tty)) (:foreground ,tty)) + (((background light)) (:foreground ,light)) + (((background dark)) (:foreground ,dark))) + ,doc + :group 'context-coloring) (defvar context-coloring-face-count nil - "Number of faces available for context coloring.") + "Number of faces available for coloring.") (defun context-coloring-defface-default (level) - (context-coloring-defface level "white" "#3f3f3f" "#cdcdcd")) + "Define a face for LEVEL with the default neutral colors." + (context-coloring-defface level nil "#3f3f3f" "#cdcdcd")) (defun context-coloring-set-colors-default () - (context-coloring-def
[elpa] master fb14816 26/31: Update readme.
branch: master commit fb148168fddd979aa6090dad84930e4e685b1596 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Update readme. --- README.md |6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2c859c4..ff305c1 100644 --- a/README.md +++ b/README.md @@ -112,14 +112,14 @@ You can define your own theme colors too: "#DCA3A3")) ``` -See `C-h f context-coloring-define-theme` for more info. +See `C-h f context-coloring-define-theme` for more info on theme parameters. ## Extending To add support for a new language, write a "scopifier" for it, and define a new coloring dispatch strategy with `context-coloring-define-dispatch`. Then the -plugin should handle the rest. See `C-h f context-coloring-define-dispatch` for -more info. +plugin should handle the rest. (See `C-h f context-coloring-define-dispatch` for +more info on dispatch strategies.) A "scopifier" is a CLI program that reads a buffer's contents from stdin and writes a JSON array of numbers to stdout. Every three numbers in the array
[elpa] master 2090e5d 11/31: Add missing case for a theme that does not set faces.
branch: master commit 2090e5d935b468503f6a09350946aa00ad49d0e2 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add missing case for a theme that does not set faces. --- context-coloring.el |9 + test/context-coloring-test.el | 20 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 4d6c172..ede7e9b 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -602,10 +602,11 @@ theme's author's colors instead." (when (and defined (not recede) (not override)) -(context-coloring-warn-theme-defined name))) -;; Set (or overwrite) colors. -(when (not recede) - (context-coloring-apply-theme name)) +(context-coloring-warn-theme-defined name)) + ;; Set (or overwrite) colors. + (when (not (and defined + recede)) +(context-coloring-apply-theme name))) (defun context-coloring-load-theme (&optional rest) (declare diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 9b636cc..757f0d7 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -470,6 +470,26 @@ t for a theme with SETTINGS." :colors '("#cc" "#dd")) (context-coloring-test-assert-no-message "*Warnings*") + (context-coloring-test-assert-face 0 "#aa") + (context-coloring-test-assert-face 1 "#bb") + (enable-theme theme) + (context-coloring-test-assert-no-message "*Warnings*") + (context-coloring-test-assert-face 0 "#aa") + (context-coloring-test-assert-face 1 "#bb")) + +(context-coloring-test-deftest-define-theme post-recede-not-defined + (context-coloring-test-deftheme theme) + (custom-theme-set-faces + theme + '(foo-face ((t (:foreground "#ff") + (context-coloring-define-theme + theme + :recede t + :colors '("#aa" + "#bb")) + (context-coloring-test-assert-no-message "*Warnings*") + (context-coloring-test-assert-face 0 "#aa") + (context-coloring-test-assert-face 1 "#bb") (enable-theme theme) (context-coloring-test-assert-no-message "*Warnings*") (context-coloring-test-assert-face 0 "#aa")
[elpa] master 352a8b0 28/31: Delete deprecated function.
branch: master commit 352a8b07ff736481cc5cfda5fea2a3acc916adfa Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Delete deprecated function. --- context-coloring.el |6 -- 1 files changed, 0 insertions(+), 6 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 54f4a5e..c947d88 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -627,12 +627,6 @@ precedence, i.e. the car of `custom-enabled-themes'." recede)) (context-coloring-apply-theme name))) -(defun context-coloring-load-theme (&optional _rest) - (declare - (obsolete -"context 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 set, else just sets `context-coloring-face-count' to the correct value for
[elpa] master 2889b27 27/31: Mark unused lexical argument.
branch: master commit 2889b273756059550a554aef86d6d01b2bcb98ae Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Mark unused lexical argument. --- context-coloring.el |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index a549b9d..54f4a5e 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -627,7 +627,7 @@ precedence, i.e. the car of `custom-enabled-themes'." recede)) (context-coloring-apply-theme name))) -(defun context-coloring-load-theme (&optional rest) +(defun context-coloring-load-theme (&optional _rest) (declare (obsolete "context themes are now loaded alongside custom themes automatically."
[elpa] master 4c7082f 06/31: Spaces.
branch: master commit 4c7082fd43f4e1379896ac16d33ca23223a61713 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Spaces. --- context-coloring.el |6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index d0c7ba2..06bd92c 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -555,13 +555,13 @@ colors are applicable to. `:colors': List of colors that this theme uses. `:override': If non-nil, this theme is intentionally overriding -colors set by a custom theme. Don't set this non-nil unless there -is a theme you want to use which sets +colors set by a custom theme. Don't set this non-nil unless +there is a theme you want to use which sets `context-coloring-level-N-face' faces that you want to replace. `:recede': If non-nil, this theme should not apply its colors if a custom theme already sets `context-coloring-level-N-face' -faces. This option is optimistic; set this non-nil if you would +faces. This option is optimistic; set this non-nil if you would rather confer the duty of picking colors to a theme author (if / when he ever gets around to it).
[elpa] master 0b8d03d 25/31: Update readme.
branch: master commit 0b8d03df92315b7581aa1bbdc5bfe9514384eacf Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Update readme. --- README.md | 10 +++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0914475..2c859c4 100644 --- a/README.md +++ b/README.md @@ -90,8 +90,9 @@ Add the following to your `~/.emacs` file: ## Customizing Color schemes for custom themes are automatically applied when those themes are -active. Built-in theme support is available for: `leuven`, `monokai`, -`solarized`, `tango` and `zenburn`. +active. Built-in theme support is available for: `ample`, `anti-zenburn`, +`grandshell`, `leuven`, `monokai`, `solarized`, `spacegray`, `tango` and +`zenburn`. You can define your own theme colors too: @@ -111,11 +112,14 @@ You can define your own theme colors too: "#DCA3A3")) ``` +See `C-h f context-coloring-define-theme` for more info. + ## Extending To add support for a new language, write a "scopifier" for it, and define a new coloring dispatch strategy with `context-coloring-define-dispatch`. Then the -plugin should handle the rest. +plugin should handle the rest. See `C-h f context-coloring-define-dispatch` for +more info. A "scopifier" is a CLI program that reads a buffer's contents from stdin and writes a JSON array of numbers to stdout. Every three numbers in the array
[elpa] master 35b3e71 23/31: Add ample theme.
branch: master commit 35b3e713f319bcba66963a9abf4df1a2d54beb9d Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add ample theme. --- context-coloring.el | 12 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index a09ee19..f83b5b0 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -683,6 +683,18 @@ faces for custom themes that might not exist yet." (context-coloring-set-colors-default) (context-coloring-define-theme + 'ample + :recede t + :colors '("#bdbdb3" + "#baba36" + "#6aaf50" + "#5180b3" + "#ab75c3" + "#cd7542" + "#dF9522" + "#454545")) + +(context-coloring-define-theme 'anti-zenburn :recede t :colors '("#232333"
[elpa] master 06a7606 10/31: Pass / update tests for warnings.
branch: master commit 06a760614d1fc4443d421e08765f0efeeeb58a29 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Pass / update tests for warnings. --- context-coloring.el | 61 + test/context-coloring-test.el | 43 + 2 files changed, 68 insertions(+), 36 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 0f2f9fa3..4d6c172 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -485,20 +485,40 @@ would be redundant." "context-coloring-level-\\([[:digit:]]+\\)-face" "Regular expression for extracting a level from a face.") +(defvar context-coloring-defined-theme-hash-table (make-hash-table :test 'eq) + "Cache of custom themes who originally set their own + `context-coloring-level-N-face' faces.") + (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)) + (let (defined) +(cond + ((setq defined (gethash theme context-coloring-defined-theme-hash-table)) + (eq defined 'defined)) + (t + (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-cache-defined (theme defined) + "Remember if THEME had colors defined for it; if DEFINED is +non-nil, it did, otherwise it didn't." + ;; Caching the definededness of a theme is kind of dirty, but we have to do it + ;; to remember the past state of the theme. There are probably some edge cases + ;; where caching will be an issue, but they are probably rare. + (puthash + theme + (if defined 'defined 'undefined) + context-coloring-defined-theme-hash-table)) (defun context-coloring-warn-theme-defined (theme) "Warns the user that the colors for a theme are already defined." @@ -575,14 +595,17 @@ theme's author's colors instead." (override (plist-get properties :override)) (recede (plist-get properties :recede))) (dolist (name (append `(,theme) aliases)) - (when (and (not override) - (context-coloring-theme-definedp name)) -(context-coloring-warn-theme-defined name)) (puthash name properties context-coloring-theme-hash-table) - ;; Set (or overwrite) colors. - (when (and (custom-theme-p name) - (not recede)) -(context-coloring-apply-theme name) + (when (custom-theme-p name) +(let ((defined (context-coloring-theme-definedp name))) + (context-coloring-cache-defined name defined) + (when (and defined + (not recede) + (not override)) +(context-coloring-warn-theme-defined name))) +;; Set (or overwrite) colors. +(when (not recede) + (context-coloring-apply-theme name)) (defun context-coloring-load-theme (&optional rest) (declare @@ -607,6 +630,8 @@ THEME." (context-coloring-apply-theme theme) (t (let ((defined (context-coloring-theme-definedp theme))) +;; Cache now in case the theme was defined after. +(context-coloring-cache-defined theme defined) (when (and defined (not override)) (context-coloring-warn-theme-defined theme)) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 5a55f28..9b636cc 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -210,6 +210,13 @@ EXPECTED-FACE." (defun context-coloring-test-assert-message (expected buffer) "Assert that BUFFER has message EXPECTED." + (when (null (get-buffer buffer)) +(ert-fail + (format + (concat + "Expected buffer `%s' to have message \"%s\", " + "but the buffer did not have any messages.") + buffer expected))) (with-current-buffer buffer (let ((messages (split-string (buffer-substring-no-properties @@ -292,16 +299,27 @@ is FOREGROUND." (context-coloring-test-assert-face 8 "#88") (context-coloring-test-assert-face 9 "#99")) +(defvar context-coloring-test-theme-index 0 + "Unique index for unique theme names.") + +(defun context-coloring-test-get-next-theme () + "Return a unique symbol for a throwaway theme."
[elpa] master a197a8c 20/31: Add disclaimer about precedence.
branch: master commit a197a8c9c80615647223ea605efca90e6694a385 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add disclaimer about precedence. --- context-coloring.el |5 - 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index bcbe86e..7267d78 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -602,7 +602,10 @@ even if those custom themes set `context-coloring-level-N-face' faces. If a context theme does override a custom theme, a warning will be raised, at which point you may want to enable the `:override' option, or just delete your context theme and opt to -use your custom theme's author's colors instead." +use your custom theme's author's colors instead. + +Context themes only work for the custom theme with the highest +precedence, i.e. the car of `custom-enabled-themes'." (let ((aliases (plist-get properties :aliases)) (override (plist-get properties :override)) (recede (plist-get properties :recede)))
[elpa] master 06efd73 09/31: Fix assertion so tests fail.
branch: master commit 06efd73340f04fc7be99f3917d98f821afc84772 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Fix assertion so tests fail. --- test/context-coloring-test.el |9 +++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index e5e9740..5a55f28 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -228,7 +228,12 @@ EXPECTED-FACE." (defun context-coloring-test-assert-no-message (buffer) "Assert that BUFFER has no message." - (null (get-buffer buffer))) + (when (get-buffer buffer) +(ert-fail (format (concat "Expected buffer `%s' to have no messages, " + "but it did: `%s'") + buffer + (with-current-buffer buffer +(buffer-string)) (defun context-coloring-test-kill-buffer (buffer) "Kill BUFFER if it exists." @@ -409,7 +414,7 @@ t for a theme with SETTINGS." (context-coloring-test-assert-defined-warning theme) (context-coloring-test-kill-buffer "*Warnings*") (enable-theme theme) - (context-coloring-test-assert-defined-warning theme) + (context-coloring-test-assert-no-message "*Warnings*") (context-coloring-test-assert-face 0 "#cc") (context-coloring-test-assert-face 1 "#dd"))
[elpa] master 3bd7e26 22/31: Add anti-zenburn theme.
branch: master commit 3bd7e260c4cd07ff958c6691068623e3181b2e33 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add anti-zenburn theme. --- context-coloring.el | 15 +++ 1 files changed, 15 insertions(+), 0 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index c1a8bc6..a09ee19 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -683,6 +683,21 @@ faces for custom themes that might not exist yet." (context-coloring-set-colors-default) (context-coloring-define-theme + 'anti-zenburn + :recede t + :colors '("#232333" + "#6c1f1c" + "#401440" + "#0f2050" + "#205070" + "#336c6c" + "#23733c" + "#6b400c" + "#603a60" + "#2f4070" + "#235c5c")) + +(context-coloring-define-theme 'leuven :recede t :colors '("#33"
[elpa] master cda491a 17/31: Long lines.
branch: master commit cda491ae4d02914f95ffe3d4cabb89566b19f32d Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Long lines. --- context-coloring.el | 23 +++ test/context-coloring-test.el | 18 -- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index c58cf67..054cdbc 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -290,7 +290,8 @@ element." (defun context-coloring-parse-array (input) "Specialized JSON parser for a flat array of numbers." - (vconcat (mapcar 'string-to-number (split-string (substring input 1 -1) "," + (vconcat + (mapcar 'string-to-number (split-string (substring input 1 -1) "," (defun context-coloring-kill-scopifier () "Kills the currently-running scopifier process for this @@ -337,8 +338,11 @@ Invokes CALLBACK when complete." (if callback (funcall callback))) ;; Give the process its input so it can begin. - (process-send-region context-coloring-scopifier-process (point-min) (point-max)) - (process-send-eof context-coloring-scopifier-process)) + (process-send-region + context-coloring-scopifier-process + (point-min) (point-max)) + (process-send-eof + context-coloring-scopifier-process)) ;;; Dispatch @@ -485,7 +489,8 @@ would be redundant." "context-coloring-level-\\([[:digit:]]+\\)-face" "Regular expression for extracting a level from a face.") -(defvar context-coloring-originally-set-theme-hash-table (make-hash-table :test 'eq) +(defvar context-coloring-originally-set-theme-hash-table + (make-hash-table :test 'eq) "Cache of custom themes who originally set their own `context-coloring-level-N-face' faces.") @@ -660,9 +665,9 @@ THEME." (defadvice enable-theme (after context-coloring-enable-theme (theme) activate) "Enable colors for context themes just-in-time. We can't set faces for custom themes that might not exist yet." - (when (and (not (eq theme 'user)) ; Called internally by `enable-theme'. + (when (and (not (eq theme 'user)) ; Called internally by `enable-theme'. (context-coloring-theme-p theme) - (custom-theme-p theme)) ; Guard against non-existent themes. + (custom-theme-p theme)) ; Guard against non-existent themes. (context-coloring-enable-theme theme))) (context-coloring-define-theme @@ -760,8 +765,10 @@ faces for custom themes that might not exist yet." (context-coloring-kill-scopifier) (when context-coloring-colorize-idle-timer (cancel-timer context-coloring-colorize-idle-timer)) -(remove-hook 'js2-post-parse-callbacks 'context-coloring-colorize t) -(remove-hook 'after-change-functions 'context-coloring-change-function t) +(remove-hook + 'js2-post-parse-callbacks 'context-coloring-colorize t) +(remove-hook + 'after-change-functions 'context-coloring-change-function t) (font-lock-mode) (jit-lock-mode t)) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index d7fd714..a24a60b 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -71,7 +71,8 @@ is done." (kill-buffer temp-buffer)) (set-buffer previous-buffer)) -(defun context-coloring-test-with-fixture-async (fixture callback &optional setup) +(defun context-coloring-test-with-fixture-async +(fixture callback &optional setup) "Evaluate CALLBACK in a temporary buffer with the relative FIXTURE. A teardown callback is passed to CALLBACK for it to invoke when it is done. An optional SETUP callback can be passed @@ -120,7 +121,8 @@ instantiated in SETUP." format." (let ((test-name (intern (format "context-coloring-test-js-mode-%s" name))) (fixture (format "./fixtures/%s.js" name)) -(function-name (intern-soft (format "context-coloring-test-js-%s" name +(function-name (intern-soft +(format "context-coloring-test-js-%s" name `(ert-deftest-async ,test-name (done) (context-coloring-test-js-mode ,fixture @@ -134,7 +136,8 @@ format." "Define a test for `js2-mode' in the typical format." (let ((test-name (intern (format "context-coloring-test-js2-mode-%s" name))) (fixture (format "./fixtures/%s.js" name)) -(function-name (intern-soft (format "context-coloring-test-js-%s" name +(function-name (intern-soft +(format "context-coloring-test-js-%s" name `(ert-deftest ,test-name () (context-coloring-test-js2-mode ,fixture @@ -310,7 +313,8 @@ is FOREGROUND." (setq context-coloring-test-theme-index (+ context-coloring-test-theme-index 1 -(defun context-coloring-test-assert-theme-originally-set-p (settings &optional negate) +(defun context-coloring-