]> code.delx.au - gnu-emacs-elpa/blob - packages/context-coloring/README.md
Merge commit '09f86fca437f1b2e168093824e9d4ee0aea5130a' from swiper
[gnu-emacs-elpa] / packages / context-coloring / README.md
1 # 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)
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 code by scope. Top-level scopes are one color, second-level scopes
8 are another color, and so on. Variables retain the color of the scope in which
9 they are defined. A variable defined in an outer scope referenced by an inner
10 scope is colored the same as the outer scope.
11
12 By default, comments and strings are still highlighted syntactically.
13
14 ## Features
15
16 - Light and dark customizable color schemes.
17 - JavaScript support:
18 - Script, function and block scopes (and even `catch` block scopes).
19 - Emacs Lisp support:
20 - `defun`, `lambda`, `let`, `let*`, `cond`, `condition-case`, `defadvice`,
21 `dolist`, `quote`, `backquote` and backquote splicing.
22 - Works in `eval-expression` too.
23
24 ## Installation
25
26 Requires Emacs 24.3+. JavaScript language support requires
27 [js2-mode](https://github.com/mooz/js2-mode).
28
29 To install, run the command `M-x package-install RET context-coloring RET`, and
30 then add the following to your init file:
31
32 ```lisp
33 ;; JavaScript:
34 (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
35 (add-hook 'js2-mode-hook #'context-coloring-mode)
36
37 ;; Emacs Lisp:
38 (add-hook 'emacs-lisp-mode-hook #'context-coloring-mode)
39
40 ;; eval-expression:
41 (add-hook 'minibuffer-setup-hook #'context-coloring-mode)
42 ```
43
44 ## Color Schemes
45
46 You can define your own colors by customizing faces like
47 `context-coloring-level-N-face`, where N is a number starting from 0.
48
49 These are the colors used in the screenshot above:
50
51 ```lisp
52 (custom-theme-set-faces
53 'zenburn
54 '(context-coloring-level-0-face ((t :foreground "#dcdccc")))
55 '(context-coloring-level-1-face ((t :foreground "#93e0e3")))
56 '(context-coloring-level-2-face ((t :foreground "#bfebbf")))
57 '(context-coloring-level-3-face ((t :foreground "#f0dfaf")))
58 '(context-coloring-level-4-face ((t :foreground "#dfaf8f")))
59 '(context-coloring-level-5-face ((t :foreground "#cc9393")))
60 '(context-coloring-level-6-face ((t :foreground "#dc8cc3")))
61 '(context-coloring-level-7-face ((t :foreground "#94bff3")))
62 '(context-coloring-level-8-face ((t :foreground "#9fc59f")))
63 '(context-coloring-level-9-face ((t :foreground "#d0bf8f")))
64 '(context-coloring-level-10-face ((t :foreground "#dca3a3"))))
65 ```
66
67 [See here](https://gist.github.com/jacksonrayhamilton/6b89ca3b85182c490816) for
68 some color schemes for popular custom themes.
69
70 ## Options
71
72 - `context-coloring-syntactic-comments` (default: `t`): If non-nil, also color
73 comments using `font-lock`.
74 - `context-coloring-syntactic-strings` (default: `t`): If non-nil, also color
75 strings using `font-lock`.
76 - `context-coloring-javascript-block-scopes` (default: `nil`): If non-nil, also
77 color block scopes in the scope hierarchy in JavaScript.