4 <img alt="Screenshot of JavaScript code highlighted by context." src="screenshot.png" title="Screenshot">
7 Highlights JavaScript code according to function context.
9 - Code in the global scope is one color. Code in functions within the global
10 scope is a different color, and code within such functions is another color,
12 - Identifiers retain the color of the scope in which they were declared.
13 - Identifiers are bold when first declared.
14 - Comments are gray and italic.
16 JavaScript programmers often leverage closures to bind nearby data to
17 functions. Lexical scope information at-a-glance can assist a programmer in
18 understanding the overall structure of a program. It can also help curb nasty
19 bugs like implicit globals and name shadowing. A rainbow can indicate excessive
20 complexity. A spot of contrast followed by an assignment expression could be a
21 side-effect... or, a specially-constructed object's private state could be
24 This coloring scheme is probably more useful than conventional JavaScript
25 *syntax* highlighting. Highlighting keywords can help one to detect spelling
26 errors, and highlighting the content between quotation marks can alert one to
27 unclosed string literals. But a [linter][] can also spot these errors, along
28 with many others, and can be [seamlessly integrated via flycheck][integration].
32 - Light and dark color schemes.
33 - Fast async AST parsing. Some total parse + recolor times:
34 - jQuery (9191 lines): 0.63 seconds
35 - Lodash (6786 lines): 0.37 seconds
36 - Async (1124 lines): 0.17 seconds
37 - mkdirp (98 lines): 0.09 seconds
41 Requires Emacs 24+ and [Node.js 0.10+][node].
43 - Clone this repository.
47 git clone https://github.com/jacksonrayhamilton/context-coloring.git
50 - Add it to your [load path][].
51 - Add a mode hook for `context-coloring-mode`.
53 In your `~/.emacs` file:
56 (add-to-list 'load-path "~/.emacs.d/context-coloring")
57 (require 'context-coloring)
58 (add-hook 'js-mode-hook 'context-coloring-mode)
61 [linter]: https://github.com/jacksonrayhamilton/jslinted
62 [integration]: https://github.com/jacksonrayhamilton/jslinted#emacs-integration
63 [node]: http://nodejs.org/download/
64 [load path]: https://www.gnu.org/software/emacs/manual/html_node/emacs/Lisp-Libraries.html