[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 32aacc9 216/271: Add customization interface.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 32aacc9 216/271: Add customization interface. |
Date: |
Thu, 05 Feb 2015 18:31:20 +0000 |
branch: master
commit 32aacc96c6d4444b0ce5e9b38dc24625b79cafd1
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Add customization interface.
---
README.md | 37 +++++++++++++++++++++++++++++++++++++
context-coloring.el | 43 +++++++++++++++++++++++++++++--------------
2 files changed, 66 insertions(+), 14 deletions(-)
diff --git a/README.md b/README.md
index 1216a68..b687f45 100644
--- a/README.md
+++ b/README.md
@@ -70,6 +70,43 @@ make compile
(add-hook 'js-mode-hook 'context-coloring-mode)
```
+## Customizing
+
+You can adjust the colors to your liking using
+`context-coloring-set-colors`. The first argument is an alist of levels, and
the
+optional second argument is the new total number of levels. This plugin does
not
+figure out the total for you; you need to specify it if your number of colors
is
+different from the default (`7`).
+
+I like to take the colors from an existing theme and use those to create a
+rainbow that matches that theme. The end result is consistent, and usually
looks
+as good as the theme does. Here's an example for `tango`:
+
+```lisp
+;; ~/.emacs
+(load-theme 'tango)
+(require 'context-coloring)
+(defun jrh-context-coloring-tango ()
+ (interactive)
+ (context-coloring-set-colors
+ '((comment . "#5f615c")
+ (0 . "#2e3436") ; Globals.
+ (1 . "#346604")
+ (2 . "#204a87")
+ (3 . "#5c3566")
+ (4 . "#a40000")
+ (5 . "#b35000")
+ (6 . "#c4a000")
+ (7 . "#8ae234") ; "You're screwed" colors.
+ (8 . "#8cc4ff")
+ (9 . "#ad7fa8")
+ (10 . "#ef2929")
+ (11 . "#fcaf3e")
+ (12 . "#fce94f"))
+ 13))
+(jrh-context-coloring-tango)
+```
+
## Extending
To add support for a new language, write a "scopifier" for it, and add an entry
diff --git a/context-coloring.el b/context-coloring.el
index 477bc12..5f673dc 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -189,22 +189,37 @@ Determines level at which to cycle through faces again."
;;; Face functions
+(defsubst context-coloring-face-symbol (level)
+ "Returns a symbol for a face with LEVEL."
+ (intern-soft (concat "context-coloring-level-" (number-to-string level)
"-face")))
+
+(defun context-coloring-set-colors (pairs &optional count)
+ "Set an alist of PAIRS for different levels' colors. Also sets
+`context-coloring-face-count' to COUNT, if specified."
+ (dolist (pair pairs)
+ (let ((level (car pair))
+ (color (cdr pair)))
+ (cond
+ ((eq level 'comment)
+ (setq level -1)))
+ (set-face-foreground (context-coloring-face-symbol level) color)))
+ (when count
+ (setq context-coloring-face-count count)))
+
(defsubst context-coloring-level-face (level)
"Return face-name for LEVEL as a string
\"context-coloring-level-LEVEL-face\".
-For example: \"context-coloring-level-1-face\"."
- (intern-soft
- (concat "context-coloring-level-"
- (number-to-string
- (or
- ;; Has a face directly mapping to it.
- (and (< level context-coloring-face-count)
- level)
- ;; After the number of available faces are used up, pretend the
0th
- ;; face doesn't exist.
- (+ 1
- (mod (- level 1)
- (- context-coloring-face-count 1)))))
- "-face")))
+For example: \"context-coloring-level-1-face\". Automatically
+wraps around to reuse faces when levels get too deep."
+ (context-coloring-face-symbol
+ (or
+ ;; Has a face directly mapping to it.
+ (and (< level context-coloring-face-count)
+ level)
+ ;; After the number of available faces are used up, pretend the 0th
+ ;; face doesn't exist.
+ (+ 1
+ (mod (- level 1)
+ (- context-coloring-face-count 1))))))
;;; Colorization utilities
- [elpa] master d885920 231/271: Merge branch 'feature/comments-and-strings' into develop, (continued)
- [elpa] master d885920 231/271: Merge branch 'feature/comments-and-strings' into develop, Jackson Ray Hamilton, 2015/02/05
- [elpa] master 96da8de 219/271: Merge branch 'master' into develop, Jackson Ray Hamilton, 2015/02/05
- [elpa] master c947690 238/271: Documentation. Cleanup. Copyright notices., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 68824f6 193/271: Add failing test for key names., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 784910c 266/271: externals-list: Add context-coloring, Jackson Ray Hamilton, 2015/02/05
- [elpa] master 079a5a8 237/271: Document tests., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 5c8855f 212/271: Merge branch 'feature/key-values' into develop, Jackson Ray Hamilton, 2015/02/05
- [elpa] master 3944181 223/271: Renames. Cleanup., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 1f06301 198/271: Pass property lookup test., Jackson Ray Hamilton, 2015/02/05
- [elpa] master f836bd2 141/271: Add js2-mode test., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 32aacc9 216/271: Add customization interface.,
Jackson Ray Hamilton <=
- [elpa] master 0830f53 104/271: Merge branch 'develop', Jackson Ray Hamilton, 2015/02/05
- [elpa] master 1df629d 222/271: Enable rainbow-mode., Jackson Ray Hamilton, 2015/02/05
- [elpa] master dc9644e 271/271: Merge branch 'master' of git://git.sv.gnu.org/emacs/elpa, Jackson Ray Hamilton, 2015/02/05
- [elpa] master 97150a1 256/271: Update .elpaignore., Jackson Ray Hamilton, 2015/02/05
- [elpa] master ae2adc4 259/271: Merge themes into main file., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 5908ce8 232/271: Fix readme., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 27db37a 202/271: Use a hash table as a scope level fast track., Jackson Ray Hamilton, 2015/02/05
- [elpa] master f3ab262 246/271: Merge branch 'develop', Jackson Ray Hamilton, 2015/02/05
- [elpa] master 73c82f9 234/271: Merge branch 'feature/set-colors' into develop, Jackson Ray Hamilton, 2015/02/05
- [elpa] master 1c0155f 203/271: Don't color name nodes in their own scope., Jackson Ray Hamilton, 2015/02/05