X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/79513b20a0e04f2ffb59ce7595cba10d4d285cfa..3007b2917d71a7d66eb94876536dfd80b0661d40:/README.md diff --git a/README.md b/README.md index 2c28844b7..21f1eb5cf 100644 --- a/README.md +++ b/README.md @@ -1,63 +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. -- Comments are gray. +By default, comments and strings are still highlighted syntactically. -JavaScript programmers often leverage closures to bind nearby data to -functions. 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. A rainbow can indicate excessive -complexity. A spot of contrast followed by an assignment expression could be a -side-effect... or, a specially-constructed object's private state could be -undergoing change. +## Features -This coloring scheme is probably more useful than conventional JavaScript -*syntax* highlighting. Highlighting keywords can help one to detect spelling -errors, and highlighting the content between quotation marks can alert one to -unclosed string literals. But a [linter][] can also spot these errors, along -with many others, and can be [seamlessly integrated via flycheck][integration]. +- 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. -## Features +## Installation -- Light and dark color schemes. -- Fast async AST parsing. Some total parse + recolor times: - - jQuery (9191 lines): 0.63 seconds - - Lodash (6786 lines): 0.37 seconds - - Async (1124 lines): 0.17 seconds - - mkdirp (98 lines): 0.09 seconds +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. +;; Emacs Lisp: +(add-hook 'emacs-lisp-mode-hook #'context-coloring-mode) -```bash -cd ~/.emacs.d/ -git clone https://github.com/jacksonrayhamilton/context-coloring.git +;; eval-expression: +(add-hook 'eval-expression-minibuffer-setup-hook #'context-coloring-mode) ; 24.4+ +(add-hook 'minibuffer-setup-hook #'context-coloring-mode) ; 24.3 ``` -- Add it to your [load path][]. -- Add a mode hook for `context-coloring-mode`. +## Color Schemes -In your `~/.emacs` file: +The [Zenburn](https://github.com/bbatsov/zenburn-emacs) theme, featured in the +screenshot above, now supports context coloring. -```lisp -(add-to-list 'load-path "~/.emacs.d/context-coloring") -(require 'context-coloring) -(add-hook 'js-mode-hook 'context-coloring-mode) -``` +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 -[linter]: https://github.com/jacksonrayhamilton/jslinted -[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-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.