]> code.delx.au - gnu-emacs-elpa/blob - README.md
Fix link.
[gnu-emacs-elpa] / README.md
1 # Context Coloring
2
3 <p align="center">
4 <img alt="Screenshot of JavaScript code highlighted by context." src="screenshot.png" title="Screenshot">
5 </p>
6
7 Highlights JavaScript code according to function context.
8
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,
11 and so on.
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.
15
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
22 undergoing change.
23
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].
29
30 ## Features
31
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
38
39 ## Usage
40
41 Requires Emacs 24+ and [Node.js 0.10+][node].
42
43 - Clone this repository.
44
45 ```bash
46 cd ~/.emacs.d/
47 git clone https://github.com/jacksonrayhamilton/context-coloring.git
48 ```
49
50 - Add it to your [load path][].
51 - Add a mode hook for `context-coloring-mode`.
52
53 In your `~/.emacs` file:
54
55 ```lisp
56 (add-to-list 'load-path "~/.emacs.d/context-coloring")
57 (require 'context-coloring)
58 (add-hook 'js-mode-hook 'context-coloring-mode)
59 ```
60
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