branch: master commit 32aacc96c6d4444b0ce5e9b38dc24625b79cafd1 Author: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com> Commit: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com>
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