]> code.delx.au - gnu-emacs-elpa/blob - README.md
Improve documentation and Makefile.
[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 This coloring scheme is probably more useful than conventional JavaScript
17 *syntax* highlighting. Highlighting keywords can help detect spelling errors, or
18 alert one to unclosed string literals; but so can a [linter][]. (If you haven't
19 already, you should [integrate][emacs integration] one into your editor.)
20
21 In JavaScript, we are constantly leveraging closures to bind nearby
22 data. Lexical scope information at-a-glance can assist a programmer in
23 understanding the overall structure of a program. It can also help curb nasty
24 bugs like implicit globals and name shadowing, and act as an indicator of
25 excessive complexity.
26
27 There are some breakthrough advantages, too. Context coloring could enable a
28 programmer to write in a functional style. It would be easy to tell when he had
29 escaped the boundaries of his function and produced side-effects.
30
31 Context coloring also improves a programmer's ability to write functions that
32 construct objects with implicit private state (which is a good way to avoid
33 `this` too).
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