X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/084d752583cc36e382f6452887add551c50143f7..3007b2917d71a7d66eb94876536dfd80b0661d40:/README.md diff --git a/README.md b/README.md index 40506e76a..21f1eb5cf 100644 --- a/README.md +++ b/README.md @@ -13,178 +13,54 @@ By default, comments and strings are still highlighted syntactically. ## Features -- Light and dark (customizable) color schemes. +- Light and dark customizable color schemes. - JavaScript support: - Script, function and block scopes (and even `catch` block scopes). - - Very fast for files under 1000 lines. + - Node.js "file-level" scope detection. - Emacs Lisp support: - `defun`, `lambda`, `let`, `let*`, `cond`, `condition-case`, `defadvice`, `dolist`, `quote`, `backquote` and backquote splicing. - - Instantaneous lazy coloring, 8000 lines-per-second full coloring. + - Works in `eval-expression` too. ## Installation -Requires Emacs 24+. +Requires Emacs 24.3+. JavaScript language support requires +[js2-mode](https://github.com/mooz/js2-mode). -JavaScript language support requires either [js2-mode][], or -[Node.js 0.10+][node] and the [scopifier][] executable. - -### ELPA - -- `M-x package-install RET context-coloring RET` - -### Git - -- Clone this repository. - -```bash -cd ~/.emacs.d/ -git clone https://github.com/jacksonrayhamilton/context-coloring.git -``` - -- Byte-compile the package for improved speed. - -```bash -cd context-coloring/ -make compile -``` - -- Add the following to your init file: +To install, run the command `M-x package-install RET context-coloring RET`, and +then add the following to your init file: ```lisp -(add-to-list 'load-path "~/.emacs.d/context-coloring") -(require 'context-coloring) -``` +;; JavaScript: +(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)) +(add-hook 'js2-mode-hook #'context-coloring-mode) -### Dependencies (js-mode) +;; Emacs Lisp: +(add-hook 'emacs-lisp-mode-hook #'context-coloring-mode) -```bash -npm install -g scopifier +;; eval-expression: +(add-hook 'eval-expression-minibuffer-setup-hook #'context-coloring-mode) ; 24.4+ +(add-hook 'minibuffer-setup-hook #'context-coloring-mode) ; 24.3 ``` -## Usage +## Color Schemes -Add the following to your init file: +The [Zenburn](https://github.com/bbatsov/zenburn-emacs) theme, featured in the +screenshot above, now supports context coloring. -```lisp -;; js-mode: -(add-hook 'js-mode-hook 'context-coloring-mode) - -;; js2-mode: -(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)) -(add-hook 'js2-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. -;; emacs-lisp-mode: -(add-hook 'emacs-lisp-mode-hook 'context-coloring-mode) -``` - -## Customizing +[See here](https://gist.github.com/jacksonrayhamilton/6b89ca3b85182c490816) for +some color schemes for popular custom themes. -### Options +## 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-default-delay` (default: `0.25`; supported modes: `js-mode`, - `js3-mode`): Default (sometimes overridden) delay between a buffer update and - colorization. -- `context-coloring-js-block-scopes` (default: `nil`; supported modes: - `js2-mode`): If non-nil, also color block scopes in the scope hierarchy in - JavaScript. - -### Color Schemes - -Color schemes for custom themes are automatically applied when those themes are -active. Built-in theme support is available for: `ample`, `anti-zenburn`, -`grandshell`, `leuven`, `monokai`, `solarized`, `spacegray`, `tango` and -`zenburn`. - -You can define your own theme colors too: - -```lisp -(context-coloring-define-theme - 'zenburn - :colors '("#dcdccc" - "#93e0e3" - "#bfebbf" - "#f0dfaf" - "#dfaf8f" - "#cc9393" - "#dc8cc3" - "#94bff3" - "#9fc59f" - "#d0bf8f" - "#dca3a3")) -``` - -See `C-h f context-coloring-define-theme` for more info on theme parameters. - -## Extending - -To add support for a new language, write a "scopifier" for it, and define a new -coloring dispatch strategy with `context-coloring-define-dispatch`. Then the -plugin should handle the rest. (See `C-h f context-coloring-define-dispatch` -for more info on dispatch strategies.) - -A "scopifier" is a CLI program that reads a buffer's contents from stdin and -writes a JSON array of numbers to stdout. Every three numbers in the array -represent a range of color. For instance, if I fed the following string of -JavaScript code to a scopifier - -```js -var a = function () {}; -``` - -then the scopifier would produce the following array - -```js -[1,24,0,9,23,1] -``` - -where, for every three numbers, the first number is a 1-indexed start [point][], -the second number is an exclusive end point, and the third number is a scope -level. The result of applying level 0 coloring to the range [1, 24) and -then applying level 1 coloring to the range [9, 23) would result in the -following coloring: - -

- Screenshot of ranges [1, 24) and [9, 23). -

- -If there is an abstract syntax tree generator for your language, you can walk -the syntax tree, find variables and scopes, and build their positions and levels -into an array like the one above. - -For example, a Ruby scopifier might be defined and implemented like this: - -```lisp -(context-coloring-define-dispatch - 'ruby - :modes '(ruby-mode) - :executable "ruby" - :command "/home/username/scopifier") -``` - -```ruby -#!/usr/bin/env ruby -def scopifier(code) - # Parse code. - # Return an array. -end -print scopifier ARGF.read -``` - -When a `--version` argument is passed, a scopifier should print its version -number and exit. This allows context-coloring to determine if an update is -required. - -Alternatively, you could implement a "colorizer" in Emacs Lisp. A colorizer -also handles the job of calling `context-coloring-colorize-region` to apply -colors to a buffer. A colorizer may have better performance than a scopifier -when parsing and coloring can be performed in the same pass. - -[js2-mode]: https://github.com/mooz/js2-mode -[node]: http://nodejs.org/download/ -[scopifier]: https://github.com/jacksonrayhamilton/scopifier -[point]: http://www.gnu.org/software/emacs/manual/html_node/elisp/Point.html +- `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.