]> code.delx.au - gnu-emacs-elpa/blob - README.md
Reorder readme.
[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 In JavaScript, we are constantly leveraging closures to bind nearby
17 data. 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, and act as an indicator of
20 excessive complexity.
21
22 There are some breakthrough advantages, too. Context coloring could enable a
23 programmer to write in a functional style. It would be easy to tell when he had
24 escaped the boundaries of his function and produced side-effects.
25
26 Context coloring also improves a programmer's ability to write functions that
27 construct objects with implicit private state (which is a good way to avoid
28 `this` too).
29
30 This coloring scheme is probably more useful than conventional JavaScript
31 *syntax* highlighting. Highlighting keywords can help detect spelling errors, or
32 alert one to unclosed string literals; but so can a [linter][]. (If you haven't
33 already, you should [integrate][emacs integration] one into your editor.)
34
35 ## Usage
36
37 Requires Emacs 24+ and [Node.js 0.10+][node].
38
39 - Clone this repository.
40 - Run `make` in it.
41 - Add it to your [load path][].
42 - Add the following to your `~/.emacs`:
43
44 ```lisp
45 (require 'context-coloring)
46 (add-hook 'js-mode-hook 'context-coloring-mode)
47 ```
48
49 [linter]: https://github.com/jacksonrayhamilton/jslinted
50 [emacs integration]: https://github.com/jacksonrayhamilton/jslinted#emacs-integration
51 [node]: http://nodejs.org/download/
52 [load path]: https://www.gnu.org/software/emacs/manual/html_node/emacs/Lisp-Libraries.html