]> code.delx.au - gnu-emacs-elpa/commitdiff
Add customization interface.
authorJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Thu, 15 Jan 2015 09:35:39 +0000 (01:35 -0800)
committerJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Thu, 15 Jan 2015 09:35:39 +0000 (01:35 -0800)
README.md
context-coloring.el

index 1216a6806256a07e5d5672d5c5a288509ba401c1..b687f453cb09685069f57c6af934116f0ea918d1 100644 (file)
--- 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
index 477bc12d72c228b9f7bf8befa1fa596c6551c792..5f673dc65202c6a5634b49339a5be589aa022389 100644 (file)
@@ -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