-all:
- exit
-
-test:
- node_modules/.bin/mocha
- emacs -batch -l ert -l test/context-coloring-test.el -f ert-run-tests-batch-and-exit
+all: clean install compile test
benchjs:
node_modules/.bin/matcha
benchel:
emacs -Q -L . -l context-coloring -l benchmark/scenarios.el
-.PHONY: all test benchmark
+compile:
+ emacs -batch -f batch-byte-compile *.el
+
+clean:
+ rm -rf node_modules
+ rm *.elc
+
+install:
+ npm install --production
+
+test:
+ node_modules/.bin/mocha
+ emacs -batch -L . -l ert -l context-coloring -l test/context-coloring-test.el -f ert-run-tests-batch-and-exit
+
+.PHONY: all benchjs benchel compile clean install test
<img alt="Screenshot of JavaScript code highlighted by context." src="screenshot.png" title="Screenshot">
</p>
-Highlights JavaScript code according to function context. Code in the global
-scope is white. Code in functions within the global scope is yellow, and code
-within such functions is green, etc. Identifiers retain the color of the scope
-in which they were defined. Comments are gray.
+Highlights JavaScript code according to function context.
+
+- Code in the global scope is one color. Code in functions within the global
+ scope is a different color, and code within such functions is another color,
+ and so on.
+- Identifiers retain the color of the scope in which they were declared.
+- Identifiers are bold when first declared.
+- Comments are gray and italic.
This coloring scheme is probably more useful than conventional JavaScript
-*syntax* highlighting. Lexical scope information at-a-glance is probably more
-useful than detecting if you spelled "function" wrong, or determing that you
-forgot to close a string literal. (A [linter][] would serve you better in that
-regard.)
+*syntax* highlighting. Highlighting keywords can help detect spelling errors, or
+alert one to unclosed string literals; but so can a [linter][]. (If you haven't
+already, you should [integrate][emacs integration] one into your editor.)
+
+In JavaScript, we are constantly leveraging closures to bind nearby
+data. Lexical scope information at-a-glance can assist a programmer in
+understanding the overall structure of a program. It can also help curb nasty
+bugs like implicit globals and name shadowing, and act as an indicator of
+excessive complexity.
+
+There are some breakthrough advantages, too. Context coloring could enable a
+programmer to write in a functional style. It would be easy to tell when he had
+escaped the boundaries of his function and produced side-effects.
+
+Context coloring also improves a programmer's ability to write functions that
+construct objects with implicit private state (which is a good way to avoid
+`this` too).
## Usage
Requires Emacs 24+ and [Node.js 0.10+][node].
- Clone this repository.
-- Run `npm install --production` in it.
+- Run `make` in it.
- Add it to your [load path][].
- Add the following to your `~/.emacs`:
```
[linter]: https://github.com/jacksonrayhamilton/jslinted
+[emacs integration]: https://github.com/jacksonrayhamilton/jslinted#emacs-integration
[node]: http://nodejs.org/download/
[load path]: https://www.gnu.org/software/emacs/manual/html_node/emacs/Lisp-Libraries.html
-;;; context-coloring.el --- JavaScript syntax highlighting for grown-ups. -*- lexical-binding: t; -*-
+;;; context-coloring.el --- JavaScript syntax highlighting for grown-ups. -*- lexical-binding: t; -*-
;; Copyright (C) 2014 Jackson Ray Hamilton
;;; Commentary:
-;; Highlights JavaScript code according to function context. Code in the global
-;; scope is white, code in functions within the global scope is yellow, code
-;; within such functions is green, etc.
+;; Highlights JavaScript code according to function context.
;;
;; Usage:
;;
-;; Install Node.js 0.10.
-;;
-;; Put context-coloring.el on your load path. Then, in your ~/.emacs:
+;; Install Node.js 0.10+.
+;; Run `make` in this file's directory.
+;; In your ~/.emacs:
;;
;; (require 'context-coloring)
;; (add-hook 'js-mode-hook 'context-coloring-mode)
{
"name": "context-coloring",
"version": "0.0.0",
- "description": "JavaScript syntax highlighting for grown-ups.",
- "main": "index.js",
+ "description": "JavaScript syntax highlighting, except not for syntax.",
+ "main": "scopifier.js",
"directories": {
"test": "test"
},
"url": "https://github.com/jacksonrayhamilton/context-coloring/issues"
},
"homepage": "https://github.com/jacksonrayhamilton/context-coloring",
- "devDependencies": {
- "matcha": "^0.6.0",
- "mocha": "^2.0.1"
- },
"dependencies": {
"escope": "^1.0.1",
"esprima": "^1.2.2"
+ },
+ "devDependencies": {
+ "matcha": "^0.6.0",
+ "mocha": "^2.0.1"
}
}