branch: master commit 8b585bc5fa8b47137d54614c6755a86d65090727 Merge: 3c5b50a 59de0b7 Author: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com> Commit: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com>
Merge commit '59de0b7591713d38c6d5c99cb49c4a4cc434a272' from context-coloring --- packages/context-coloring/README.md | 41 +++++++++------ packages/context-coloring/context-coloring.el | 73 ++++++++++++++++++++----- 2 files changed, 84 insertions(+), 30 deletions(-) diff --git a/packages/context-coloring/README.md b/packages/context-coloring/README.md index 2db08b1..21ba184 100644 --- a/packages/context-coloring/README.md +++ b/packages/context-coloring/README.md @@ -16,7 +16,7 @@ the overall structure of a program. It can help to curb nasty bugs like name shadowing. A rainbow can indicate excessive complexity. State change within a closure is easily monitored. -By default, Context Coloring still highlights comments and strings +By default, context-coloring still highlights comments and strings syntactically. It is still easy to differentiate code from non-code, and strings cannot be confused for variables. @@ -25,7 +25,7 @@ highlighting. Highlighting keywords can help one to detect spelling errors, but a [linter][] could also spot those errors, and if integrated with [flycheck][], an extra spot opens up in your editing toolbelt. -Give context coloring a try; you may find that it *changes the way you write +Give context-coloring a try; you may find that it *changes the way you write code*. ## Features @@ -41,13 +41,8 @@ Requires Emacs 24+. JavaScript language support requires either [js2-mode][], or [Node.js 0.10+][node] and the [scopifier][] executable. -```bash -npm install -g scopifier -``` - ### ELPA -- `M-x package-refresh-contents RET` - `M-x package-install RET context-coloring RET` ### Git @@ -71,20 +66,34 @@ make compile ```lisp (add-to-list 'load-path "~/.emacs.d/context-coloring") (require 'context-coloring) -(add-hook 'js2-mode-hook 'context-coloring-mode) ``` -## Customizing +### scopifier (for non-js2-mode users) -Built-in themes are accessible via `context-coloring-load-theme`. Available -themes are: `monokai`, `solarized`, `tango` and `zenburn`. +```bash +npm install -g scopifier +``` + +## Usage + +Add the following to your `~/.emacs` file: ```lisp -(require 'context-coloring) -(context-coloring-load-theme 'zenburn) +;; non-js2-mode users: +(add-hook 'js-mode-hook 'context-coloring-mode) + +;; js2-mode users: +(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)) +(add-hook 'js2-mode-hook 'context-coloring-mode) ``` -You can define your own themes, too: +## 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`. + +You can define your own theme colors too: ```lisp (context-coloring-define-theme @@ -157,8 +166,8 @@ print scopifier ARGF.read ``` When a `--version` argument is passed, a scopifier should print its version -number and exit. For installable scopifiers, this allows context-coloring to -check for updates as needed. +number and exit. This allows context-coloring to determine if an update is +required. [linter]: http://jshint.com/about/ [flycheck]: http://www.flycheck.org/ diff --git a/packages/context-coloring/context-coloring.el b/packages/context-coloring/context-coloring.el index 5a33eff..6af9444 100644 --- a/packages/context-coloring/context-coloring.el +++ b/packages/context-coloring/context-coloring.el @@ -5,7 +5,7 @@ ;; Author: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com> ;; URL: https://github.com/jacksonrayhamilton/context-coloring ;; Keywords: context coloring syntax highlighting -;; Version: 4.0.0 +;; Version: 4.1.0 ;; Package-Requires: ((emacs "24") (js2-mode "20150126")) ;; This file is part of GNU Emacs. @@ -143,6 +143,11 @@ used.") (context-coloring-set-colors-default) +;; Color theme authors can have up to 26 levels: 1 (0th) for globals, 24 +;; (1st-24th) for in-betweens, and 1 (25th) for infinity. +(dotimes (number 18) + (context-coloring-defface-default (+ number context-coloring-face-count))) + ;;; Face functions @@ -474,24 +479,60 @@ would be redundant." (defvar context-coloring-theme-hash-table (make-hash-table :test 'eq) "Mapping of theme names to theme properties.") +(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 ,color))))) + colors)))))) + (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." - (puthash - theme - (lambda () - (apply 'context-coloring-set-colors (plist-get properties :colors))) - context-coloring-theme-hash-table)) - -(defun context-coloring-load-theme (theme) - "Apply THEME's colors and other properties for context -coloring." - (let ((function (gethash theme context-coloring-theme-hash-table))) - (when (null function) - (error (format "No such theme `%s'" theme))) - (funcall function))) + (let ((aliases (plist-get properties :aliases))) + (dolist (name (append `(,theme) aliases)) + (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-apply-theme name))))) + +(defun context-coloring-load-theme (&optional rest) + (declare (obsolete + "themes are now loaded alongside custom themes automatically." + "4.1.0"))) + +(defadvice enable-theme (after context-coloring-enable-theme (theme) activate) + "Add colors to themes just-in-time." + (when (and (not (eq theme 'user)) ; Called internally. + (custom-theme-p theme)) ; Guard against non-existent themes. + (context-coloring-apply-theme theme))) + +(context-coloring-define-theme + 'leuven + :colors '("#333333" + "#0000FF" + "#6434A3" + "#BA36A5" + "#D0372D" + "#036A07" + "#006699" + "#006FE0" + "#808080")) (context-coloring-define-theme 'monokai @@ -507,6 +548,10 @@ coloring." (context-coloring-define-theme 'solarized + :aliases '(solarized-light + solarized-dark + sanityinc-solarized-light + sanityinc-solarized-dark) :colors '("#839496" "#268bd2" "#2aa198"