X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/fb57258860c173c88165d928f0da5c17435fb074..3007b2917d71a7d66eb94876536dfd80b0661d40:/README.md diff --git a/README.md b/README.md index 6735ff5b8..21f1eb5cf 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,66 @@ -# Context Coloring +# Context Coloring [![Build Status](https://travis-ci.org/jacksonrayhamilton/context-coloring.png?branch=master)](https://travis-ci.org/jacksonrayhamilton/context-coloring) [![Coverage Status](https://coveralls.io/repos/jacksonrayhamilton/context-coloring/badge.svg?branch=master)](https://coveralls.io/r/jacksonrayhamilton/context-coloring?branch=master)

Screenshot of JavaScript code highlighted by context.

-Highlights JavaScript code according to function context. +Highlights code by scope. Top-level scopes are one color, second-level scopes +are another color, and so on. Variables retain the color of the scope in which +they are defined. A variable defined in an outer scope referenced by an inner +scope is colored the same as the outer scope. -- 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. +By default, comments and strings are still highlighted syntactically. -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. +## Features -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. +- Light and dark customizable color schemes. +- JavaScript support: + - Script, function and block scopes (and even `catch` block scopes). + - Node.js "file-level" scope detection. +- Emacs Lisp support: + - `defun`, `lambda`, `let`, `let*`, `cond`, `condition-case`, `defadvice`, + `dolist`, `quote`, `backquote` and backquote splicing. + - Works in `eval-expression` too. -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). +## Installation -This coloring scheme is probably more useful than conventional JavaScript -*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.) +Requires Emacs 24.3+. JavaScript language support requires +[js2-mode](https://github.com/mooz/js2-mode). -## Usage +To install, run the command `M-x package-install RET context-coloring RET`, and +then add the following to your init file: -Requires Emacs 24+ and [Node.js 0.10+][node]. +```lisp +;; JavaScript: +(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)) +(add-hook 'js2-mode-hook #'context-coloring-mode) -- Clone this repository. -- Run `make` in it. -- Add it to your [load path][]. -- Add the following to your `~/.emacs`: +;; Emacs Lisp: +(add-hook 'emacs-lisp-mode-hook #'context-coloring-mode) -```lisp -(require 'context-coloring) -(add-hook 'js-mode-hook 'context-coloring-mode) +;; eval-expression: +(add-hook 'eval-expression-minibuffer-setup-hook #'context-coloring-mode) ; 24.4+ +(add-hook 'minibuffer-setup-hook #'context-coloring-mode) ; 24.3 ``` -[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 +## Color Schemes + +The [Zenburn](https://github.com/bbatsov/zenburn-emacs) theme, featured in the +screenshot above, now supports context coloring. + +You can define your own colors by customizing faces like +`context-coloring-level-N-face`, where N is a number starting from 0. + +[See here](https://gist.github.com/jacksonrayhamilton/6b89ca3b85182c490816) for +some color schemes for popular custom themes. + +## Options + +- `context-coloring-syntactic-comments` (default: `t`): If non-nil, also color + comments using `font-lock`. +- `context-coloring-syntactic-strings` (default: `t`): If non-nil, also color + strings using `font-lock`. +- `context-coloring-javascript-block-scopes` (default: `nil`): If non-nil, also + color block scopes in the scope hierarchy in JavaScript. +- `context-coloring-javascript-detect-top-level-scope` (default: `t`): If + non-nil, detect when to use file-level scope.