]> code.delx.au - gnu-emacs-elpa/blob - context-coloring.el
Trivial refactoring for clarity.
[gnu-emacs-elpa] / context-coloring.el
1 ;;; context-coloring.el --- Highlight by scope -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2014-2015 Free Software Foundation, Inc.
4
5 ;; Author: Jackson Ray Hamilton <jackson@jacksonrayhamilton.com>
6 ;; Version: 6.2.1
7 ;; Keywords: convenience faces tools
8 ;; Package-Requires: ((emacs "24") (js2-mode "20150126"))
9 ;; URL: https://github.com/jacksonrayhamilton/context-coloring
10
11 ;; This file is part of GNU Emacs.
12
13 ;; This program is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
17
18 ;; This program is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
25
26 ;;; Commentary:
27
28 ;; Highlights code by scope. Top-level scopes are one color, second-level
29 ;; scopes are another color, and so on. Variables retain the color of the scope
30 ;; in which they are defined. A variable defined in an outer scope referenced
31 ;; by an inner scope is colored the same as the outer scope.
32
33 ;; By default, comments and strings are still highlighted syntactically.
34
35 ;; To use with js2-mode, add the following to your init file:
36
37 ;; (require 'context-coloring)
38 ;; (add-hook 'js2-mode-hook 'context-coloring-mode)
39
40 ;; To use with js-mode or js3-mode, install Node.js 0.10+ and the scopifier
41 ;; executable:
42
43 ;; $ npm install -g scopifier
44
45 ;;; Code:
46
47 (require 'js2-mode)
48
49
50 ;;; Local variables
51
52 (defvar-local context-coloring-buffer nil
53 "Reference to this buffer (for timers).")
54
55
56 ;;; Utilities
57
58 (defun context-coloring-join (strings delimiter)
59 "Join a list of STRINGS with the string DELIMITER."
60 (mapconcat 'identity strings delimiter))
61
62 (defsubst context-coloring-trim-right (string)
63 "Remove leading whitespace from STRING."
64 (if (string-match "[ \t\n\r]+\\'" string)
65 (replace-match "" t t string)
66 string))
67
68 (defsubst context-coloring-trim-left (string)
69 "Remove trailing whitespace from STRING."
70 (if (string-match "\\`[ \t\n\r]+" string)
71 (replace-match "" t t string)
72 string))
73
74 (defsubst context-coloring-trim (string)
75 "Remove leading and trailing whitespace from STRING."
76 (context-coloring-trim-left (context-coloring-trim-right string)))
77
78
79 ;;; Faces
80
81 (defun context-coloring-defface (level tty light dark)
82 "Define a face for LEVEL with colors for TTY, LIGHT and DARK
83 backgrounds."
84 (let ((face (intern (format "context-coloring-level-%s-face" level)))
85 (doc (format "Context coloring face, level %s." level)))
86 (custom-declare-face
87 face
88 `((((type tty)) (:foreground ,tty))
89 (((background light)) (:foreground ,light))
90 (((background dark)) (:foreground ,dark)))
91 doc
92 :group 'context-coloring)))
93
94 (defun context-coloring-defface-neutral (level)
95 "Define a face for LEVEL with the default neutral colors."
96 (context-coloring-defface level nil "#3f3f3f" "#cdcdcd"))
97
98 (context-coloring-defface 0 nil "#000000" "#ffffff")
99 (context-coloring-defface 1 "yellow" "#008b8b" "#00ffff")
100 (context-coloring-defface 2 "green" "#0000ff" "#87cefa")
101 (context-coloring-defface 3 "cyan" "#483d8b" "#b0c4de")
102 (context-coloring-defface 4 "blue" "#a020f0" "#eedd82")
103 (context-coloring-defface 5 "magenta" "#a0522d" "#98fb98")
104 (context-coloring-defface 6 "red" "#228b22" "#7fffd4")
105 (context-coloring-defface-neutral 7)
106
107 (defvar context-coloring-maximum-face nil
108 "Index of the highest face available for coloring.")
109
110 (defvar context-coloring-original-maximum-face nil
111 "Fallback value for `context-coloring-maximum-face' when all
112 themes have been disabled.")
113
114 (setq context-coloring-maximum-face 7)
115
116 (setq context-coloring-original-maximum-face
117 context-coloring-maximum-face)
118
119 ;; Theme authors can have up to 26 levels: 1 (0th) for globals, 24 (1st-24th)
120 ;; for nested levels, and 1 (25th) for infinity.
121 (dotimes (number 18)
122 (context-coloring-defface-neutral (+ number context-coloring-maximum-face 1)))
123
124
125 ;;; Face functions
126
127 (defsubst context-coloring-level-face (level)
128 "Return the symbol for a face with LEVEL."
129 ;; `concat' is faster than `format' here.
130 (intern-soft
131 (concat "context-coloring-level-" (number-to-string level) "-face")))
132
133 (defsubst context-coloring-bounded-level-face (level)
134 "Return the symbol for a face with LEVEL, bounded by
135 `context-coloring-maximum-face'."
136 (context-coloring-level-face (min level context-coloring-maximum-face)))
137
138
139 ;;; Colorization utilities
140
141 (defsubst context-coloring-colorize-region (start end level)
142 "Color characters from the 1-indexed START point (inclusive) to
143 the END point (exclusive) with the face corresponding to LEVEL."
144 (add-text-properties
145 start
146 end
147 `(face ,(context-coloring-bounded-level-face level))))
148
149 (defcustom context-coloring-comments-and-strings nil
150 "If non-nil, also color comments and strings using `font-lock'."
151 :group 'context-coloring)
152
153 (make-obsolete-variable
154 'context-coloring-comments-and-strings
155 "use `context-coloring-syntactic-comments' and
156 `context-coloring-syntactic-strings' instead."
157 "6.1.0")
158
159 (defcustom context-coloring-syntactic-comments t
160 "If non-nil, also color comments using `font-lock'."
161 :group 'context-coloring)
162
163 (defcustom context-coloring-syntactic-strings t
164 "If non-nil, also color strings using `font-lock'."
165 :group 'context-coloring)
166
167 (defun context-coloring-font-lock-syntactic-comment-function (state)
168 "Tell `font-lock' to color a comment but not a string."
169 (if (nth 3 state) nil font-lock-comment-face))
170
171 (defun context-coloring-font-lock-syntactic-string-function (state)
172 "Tell `font-lock' to color a string but not a comment."
173 (if (nth 3 state) font-lock-string-face nil))
174
175 (defsubst context-coloring-maybe-colorize-comments-and-strings ()
176 "Color the current buffer's comments and strings if
177 `context-coloring-comments-and-strings' is non-nil."
178 (when (or context-coloring-comments-and-strings
179 context-coloring-syntactic-comments
180 context-coloring-syntactic-strings)
181 (let ((old-function font-lock-syntactic-face-function)
182 saved-function-p)
183 (cond
184 ((and context-coloring-syntactic-comments
185 (not context-coloring-syntactic-strings))
186 (setq font-lock-syntactic-face-function
187 'context-coloring-font-lock-syntactic-comment-function)
188 (setq saved-function-p t))
189 ((and context-coloring-syntactic-strings
190 (not context-coloring-syntactic-comments))
191 (setq font-lock-syntactic-face-function
192 'context-coloring-font-lock-syntactic-string-function)
193 (setq saved-function-p t)))
194 (save-excursion
195 (font-lock-fontify-syntactically-region (point-min) (point-max)))
196 (when saved-function-p
197 (setq font-lock-syntactic-face-function old-function)))))
198
199
200 ;;; js2-mode colorization
201
202 (defvar-local context-coloring-js2-scope-level-hash-table nil
203 "Associate `js2-scope' structures and with their scope
204 levels.")
205
206 (defcustom context-coloring-js-block-scopes nil
207 "If non-nil, also color block scopes in the scope hierarchy in JavaScript.
208
209 The block-scoped `let' and `const' are introduced in ES6. Enable
210 this for ES6 code; disable it elsewhere.
211
212 Supported modes: `js2-mode'"
213 :group 'context-coloring)
214
215 (defsubst context-coloring-js2-scope-level (scope)
216 "Return the level of SCOPE."
217 (cond ((gethash scope context-coloring-js2-scope-level-hash-table))
218 (t
219 (let ((level 0)
220 (current-scope scope)
221 enclosing-scope)
222 (while (and current-scope
223 (js2-node-parent current-scope)
224 (setq enclosing-scope
225 (js2-node-get-enclosing-scope current-scope)))
226 (when (or context-coloring-js-block-scopes
227 (let ((type (js2-scope-type current-scope)))
228 (or (= type js2-SCRIPT)
229 (= type js2-FUNCTION)
230 (= type js2-CATCH))))
231 (setq level (+ level 1)))
232 (setq current-scope enclosing-scope))
233 (puthash scope level context-coloring-js2-scope-level-hash-table)))))
234
235 (defsubst context-coloring-js2-local-name-node-p (node)
236 "Determine if NODE is a `js2-name-node' representing a local
237 variable."
238 (and (js2-name-node-p node)
239 (let ((parent (js2-node-parent node)))
240 (not (or (and (js2-object-prop-node-p parent)
241 (eq node (js2-object-prop-node-left parent)))
242 (and (js2-prop-get-node-p parent)
243 ;; For nested property lookup, the node on the left is a
244 ;; `js2-prop-get-node', so this always works.
245 (eq node (js2-prop-get-node-right parent))))))))
246
247 (defvar-local context-coloring-point-max nil
248 "Cached value of `point-max'.")
249
250 (defsubst context-coloring-js2-colorize-node (node level)
251 "Color NODE with the color for LEVEL."
252 (let ((start (js2-node-abs-pos node)))
253 (context-coloring-colorize-region
254 start
255 (min
256 ;; End
257 (+ start (js2-node-len node))
258 ;; Somes nodes (like the ast when there is an unterminated multiline
259 ;; comment) will stretch to the value of `point-max'.
260 context-coloring-point-max)
261 level)))
262
263 (defun context-coloring-js2-colorize ()
264 "Color the current buffer using the abstract syntax tree
265 generated by `js2-mode'."
266 ;; Reset the hash table; the old one could be obsolete.
267 (setq context-coloring-js2-scope-level-hash-table (make-hash-table :test 'eq))
268 (setq context-coloring-point-max (point-max))
269 (with-silent-modifications
270 (js2-visit-ast
271 js2-mode-ast
272 (lambda (node end-p)
273 (when (null end-p)
274 (cond
275 ((js2-scope-p node)
276 (context-coloring-js2-colorize-node
277 node
278 (context-coloring-js2-scope-level node)))
279 ((context-coloring-js2-local-name-node-p node)
280 (let* ((enclosing-scope (js2-node-get-enclosing-scope node))
281 (defining-scope (js2-get-defining-scope
282 enclosing-scope
283 (js2-name-node-name node))))
284 ;; The tree seems to be walked lexically, so an entire scope will
285 ;; be colored, including its name nodes, before they are reached.
286 ;; Coloring the nodes defined in that scope would be redundant, so
287 ;; don't do it.
288 (when (not (eq defining-scope enclosing-scope))
289 (context-coloring-js2-colorize-node
290 node
291 (context-coloring-js2-scope-level defining-scope))))))
292 ;; The `t' indicates to search children.
293 t)))
294 (context-coloring-maybe-colorize-comments-and-strings)))
295
296
297 ;;; Emacs Lisp colorization
298
299 (defun context-coloring-make-scope (depth level)
300 (list
301 :depth depth
302 :level level
303 :variables (make-hash-table)))
304
305 (defun context-coloring-scope-get-depth (scope)
306 (plist-get scope :depth))
307
308 (defun context-coloring-scope-get-level (scope)
309 (plist-get scope :level))
310
311 (defun context-coloring-scope-add-variable (scope variable)
312 (puthash variable t (plist-get scope :variables)))
313
314 (defun context-coloring-scope-get-variable (scope variable)
315 (gethash variable (plist-get scope :variables)))
316
317 (defun context-coloring-get-variable-level (scope-stack variable)
318 (let* (scope
319 level)
320 (while (and scope-stack (not level))
321 (setq scope (car scope-stack))
322 (cond
323 ((context-coloring-scope-get-variable scope variable)
324 (setq level (context-coloring-scope-get-level scope)))
325 (t
326 (setq scope-stack (cdr scope-stack)))))
327 ;; Assume a global variable.
328 (or level 0)))
329
330 (defun context-coloring-make-backtick (end enabled)
331 (list
332 :end end
333 :enabled enabled))
334
335 (defun context-coloring-backtick-get-end (backtick)
336 (plist-get backtick :end))
337
338 (defun context-coloring-backtick-get-enabled (backtick)
339 (plist-get backtick :enabled))
340
341 (defun context-coloring-backtick-enabled-p (backtick-stack)
342 (context-coloring-backtick-get-enabled (car backtick-stack)))
343
344 (defun context-coloring-forward-sws ()
345 "Move forward through whitespace and comments."
346 (while (forward-comment 1)))
347
348 (defun context-coloring-forward-sexp-position ()
349 (scan-sexps (point) 1))
350
351 (defun context-coloring-emacs-lisp-identifier-syntax-p (syntax-code)
352 (or (= 2 syntax-code)
353 (= 3 syntax-code)))
354
355 (defun context-coloring-open-parenthesis-p (syntax-code)
356 (= 4 syntax-code))
357
358 (defun context-coloring-close-parenthesis-p (syntax-code)
359 (= 5 syntax-code))
360
361 (defun context-coloring-expression-prefix-p (syntax-code)
362 (= 6 syntax-code))
363
364 (defun context-coloring-at-open-parenthesis-p ()
365 (= 4 (logand #xFFFF (car (syntax-after (point))))))
366
367 (defun context-coloring-ppss-depth (ppss)
368 ;; Same as (nth 0 ppss).
369 (car ppss))
370
371 (defconst context-coloring-defun-regexp
372 "\\`defun\\'\\|\\`defmacro\\'\\|\\`defsubst\\'")
373
374 (defconst context-coloring-arglist-arg-regexp
375 "\\`[^&:]")
376
377 (defconst context-coloring-unbindable-constant-regexp
378 "\\`[-+]?[0-9]\\|\\`t\\'\\|\\`nil\\'")
379
380 (defconst context-coloring-COMMA-CHAR 44)
381 (defconst context-coloring-BACKTICK-CHAR 96)
382
383 (defun context-coloring-emacs-lisp-colorize ()
384 "Color the current buffer by parsing emacs lisp sexps."
385 (with-silent-modifications
386 (save-excursion
387 ;; TODO: Can probably make this lazy to the nearest defun.
388 (goto-char (point-min))
389 (let* ((inhibit-point-motion-hooks t)
390 (end (point-max))
391 (last-ppss-pos (point))
392 (ppss (syntax-ppss))
393 ; -1 never matches a depth. This is a minor optimization.
394 (scope-stack `(,(context-coloring-make-scope -1 0)))
395 (backtick-stack '())
396 one-word-found-p
397 in-defun-p
398 in-lambda-p
399 in-let-p
400 in-let*-p
401 defun-arglist
402 defun-arg
403 let-varlist
404 let-var
405 variable
406 variable-end
407 variable-string
408 variable-scope-level
409 token-pos
410 token-syntax
411 token-syntax-code
412 token-char
413 child-0-pos
414 child-0-end
415 child-0-syntax
416 child-0-syntax-code
417 child-0-string
418 child-1-pos
419 child-1-end
420 child-1-syntax
421 child-1-syntax-code
422 child-2-end)
423 (while (> end (progn (skip-syntax-forward "^()w_'" end)
424 (point)))
425 (setq token-pos (point))
426 (setq token-syntax (syntax-after token-pos))
427 (setq token-syntax-code (logand #xFFFF (car token-syntax)))
428 (setq token-char (char-after))
429 (setq ppss (parse-partial-sexp last-ppss-pos token-pos nil nil ppss))
430 (setq last-ppss-pos token-pos)
431 (cond
432
433 ;; Resolve an invalid state.
434 ((cond
435 ;; Inside string?
436 ((nth 3 ppss)
437 (skip-syntax-forward "^\"" end)
438 (forward-char)
439 t)
440 ;; Inside comment?
441 ((nth 4 ppss)
442 (skip-syntax-forward "^>" end)
443 t)))
444
445 ;; Need to check early in case there's a comma.
446 ((context-coloring-expression-prefix-p token-syntax-code)
447 (forward-char)
448 (cond
449 ;; Skip top-level symbols.
450 ((not (or backtick-stack
451 (= token-char context-coloring-BACKTICK-CHAR)))
452 (goto-char (context-coloring-forward-sexp-position)))
453 ;; Push a backtick state.
454 ((or (= token-char context-coloring-BACKTICK-CHAR)
455 (= token-char context-coloring-COMMA-CHAR))
456 (setq backtick-stack (cons (context-coloring-make-backtick
457 (context-coloring-forward-sexp-position)
458 (= token-char context-coloring-BACKTICK-CHAR))
459 backtick-stack)))))
460
461 ;; Pop a backtick state.
462 ((and backtick-stack
463 (>= (point) (context-coloring-backtick-get-end (car backtick-stack))))
464 (setq backtick-stack (cdr backtick-stack)))
465
466 ;; Restricted by an enabled backtick.
467 ((and backtick-stack
468 (context-coloring-backtick-enabled-p backtick-stack))
469 (forward-char))
470
471 ((context-coloring-open-parenthesis-p token-syntax-code)
472 (forward-char)
473 ;; Look for function calls.
474 (context-coloring-forward-sws)
475 (setq child-0-pos (point))
476 (setq child-0-syntax (syntax-after child-0-pos))
477 (setq child-0-syntax-code (logand #xFFFF (car child-0-syntax)))
478 (cond
479 ((context-coloring-emacs-lisp-identifier-syntax-p child-0-syntax-code)
480 (setq one-word-found-p t)
481 (setq child-0-end (scan-sexps child-0-pos 1))
482 (setq child-0-string (buffer-substring-no-properties child-0-pos child-0-end))
483 (cond
484 ((string-match-p context-coloring-defun-regexp child-0-string)
485 (setq in-defun-p t))
486 ((string-match-p "\\`lambda\\'" child-0-string)
487 (setq in-lambda-p t))
488 ((string-match-p "\\`let\\'" child-0-string)
489 (setq in-let-p t))
490 ((string-match-p "\\`let\\*\\'" child-0-string)
491 (setq in-let*-p t)))))
492 (when (or in-defun-p
493 in-lambda-p
494 in-let-p
495 in-let*-p)
496 (setq scope-stack (cons (context-coloring-make-scope
497 (context-coloring-ppss-depth ppss)
498 (1+ (context-coloring-scope-get-level
499 (car scope-stack))))
500 scope-stack)))
501 ;; TODO: Probably redundant and wasteful.
502 (context-coloring-colorize-region token-pos
503 (scan-sexps token-pos 1)
504 (context-coloring-scope-get-level
505 (car scope-stack)))
506 (cond
507 ((or in-defun-p
508 in-lambda-p)
509 (goto-char child-0-end)
510 (when in-defun-p
511 ;; Look for a function name.
512 (context-coloring-forward-sws)
513 (setq child-1-pos (point))
514 (setq child-1-syntax (syntax-after child-1-pos))
515 (setq child-1-syntax-code (logand #xFFFF (car child-1-syntax)))
516 (cond
517 ((context-coloring-emacs-lisp-identifier-syntax-p child-1-syntax-code)
518 (setq child-1-end (scan-sexps child-1-pos 1))
519 ;; Defuns are global, so use level 0.
520 (context-coloring-colorize-region child-1-pos child-1-end 0)
521 (goto-char child-1-end))))
522 ;; Look for an arglist.
523 (context-coloring-forward-sws)
524 (when (context-coloring-at-open-parenthesis-p)
525 ;; (Actually it should be `child-1-end' for `lambda'.)
526 (setq child-2-end (context-coloring-forward-sexp-position))
527 (setq defun-arglist (read (buffer-substring-no-properties
528 (point)
529 child-2-end)))
530 (while defun-arglist
531 (setq defun-arg (car defun-arglist))
532 (when (and (symbolp defun-arg)
533 (string-match-p
534 context-coloring-arglist-arg-regexp
535 (symbol-name defun-arg)))
536 (context-coloring-scope-add-variable
537 (car scope-stack)
538 defun-arg))
539 (setq defun-arglist (cdr defun-arglist)))
540 (goto-char child-2-end))
541 ;; Cleanup.
542 (setq in-defun-p nil)
543 (setq in-lambda-p nil))
544 ((or in-let-p
545 in-let*-p)
546 (goto-char child-0-end)
547 ;; Look for bindings.
548 (context-coloring-forward-sws)
549 (setq child-1-pos (point))
550 (setq child-1-syntax (syntax-after child-1-pos))
551 (setq child-1-syntax-code (logand #xFFFF (car child-1-syntax)))
552 (when (= 4 child-1-syntax-code)
553 (setq child-1-end (context-coloring-forward-sexp-position))
554 (setq let-varlist (read (buffer-substring-no-properties
555 (point)
556 child-1-end)))
557 (while let-varlist
558 (setq let-var (car let-varlist))
559 (cond
560 ((symbolp let-var)
561 (context-coloring-scope-add-variable
562 (car scope-stack)
563 let-var))
564 ((listp let-var)
565 (context-coloring-scope-add-variable
566 (car scope-stack)
567 (car let-var))
568 ;; TODO: Recurse or use stack to eval var value.
569 ))
570 (setq let-varlist (cdr let-varlist)))
571 (goto-char child-1-end))
572 ;; Cleanup.
573 (setq in-let-p nil)
574 (setq in-let*-p nil))
575 (t
576 (goto-char (cond
577 ;; If there was a word, continue parsing after it.
578 (one-word-found-p
579 (1+ child-0-end))
580 (t
581 (1+ token-pos))))))
582 ;; Cleanup.
583 (setq one-word-found-p nil))
584
585 ((context-coloring-emacs-lisp-identifier-syntax-p token-syntax-code)
586 (setq variable-end (context-coloring-forward-sexp-position))
587 (setq variable-string (buffer-substring-no-properties
588 token-pos
589 variable-end))
590 (cond
591 ;; Ignore constants such as numbers, keywords, t, nil. These can't
592 ;; be rebound, so they should be treated like syntax.
593 ((string-match-p context-coloring-unbindable-constant-regexp variable-string))
594 ((keywordp (read variable-string)))
595 (t
596 (setq variable (intern variable-string))
597 (setq variable-scope-level
598 (context-coloring-get-variable-level scope-stack variable))
599 (when (/= variable-scope-level (context-coloring-scope-get-level
600 (car scope-stack)))
601 (context-coloring-colorize-region
602 token-pos
603 variable-end
604 variable-scope-level))))
605 (goto-char variable-end))
606
607 ((context-coloring-close-parenthesis-p token-syntax-code)
608 (forward-char)
609 (setq ppss (parse-partial-sexp last-ppss-pos (point) nil nil ppss))
610 (setq last-ppss-pos (point))
611 (when (= (context-coloring-ppss-depth ppss)
612 (context-coloring-scope-get-depth (car scope-stack)))
613 (setq scope-stack (cdr scope-stack))))
614
615 ))))
616 (context-coloring-maybe-colorize-comments-and-strings)))
617
618
619 ;;; Shell command scopification / colorization
620
621 (defun context-coloring-apply-tokens (tokens)
622 "Process a vector of TOKENS to apply context-based coloring to
623 the current buffer. Tokens are 3 integers: start, end, level.
624 The vector is flat, with a new token occurring after every 3rd
625 element."
626 (with-silent-modifications
627 (let ((i 0)
628 (len (length tokens)))
629 (while (< i len)
630 (context-coloring-colorize-region
631 (elt tokens i)
632 (elt tokens (+ i 1))
633 (elt tokens (+ i 2)))
634 (setq i (+ i 3))))
635 (context-coloring-maybe-colorize-comments-and-strings)))
636
637 (defun context-coloring-parse-array (array)
638 "Parse ARRAY as a flat JSON array of numbers."
639 (let ((braceless (substring (context-coloring-trim array) 1 -1)))
640 (cond
641 ((> (length braceless) 0)
642 (vconcat
643 (mapcar 'string-to-number (split-string braceless ","))))
644 (t
645 (vector)))))
646
647 (defvar-local context-coloring-scopifier-process nil
648 "The single scopifier process that can be running.")
649
650 (defun context-coloring-kill-scopifier ()
651 "Kill the currently-running scopifier process."
652 (when (not (null context-coloring-scopifier-process))
653 (delete-process context-coloring-scopifier-process)
654 (setq context-coloring-scopifier-process nil)))
655
656 (defun context-coloring-scopify-shell-command (command callback)
657 "Invoke a scopifier via COMMAND, read its response
658 asynchronously and invoke CALLBACK with its output."
659
660 ;; Prior running tokenization is implicitly obsolete if this function is
661 ;; called.
662 (context-coloring-kill-scopifier)
663
664 ;; Start the process.
665 (setq context-coloring-scopifier-process
666 (start-process-shell-command "scopifier" nil command))
667
668 (let ((output ""))
669
670 ;; The process may produce output in multiple chunks. This filter
671 ;; accumulates the chunks into a message.
672 (set-process-filter
673 context-coloring-scopifier-process
674 (lambda (_process chunk)
675 (setq output (concat output chunk))))
676
677 ;; When the process's message is complete, this sentinel parses it as JSON
678 ;; and applies the tokens to the buffer.
679 (set-process-sentinel
680 context-coloring-scopifier-process
681 (lambda (_process event)
682 (when (equal "finished\n" event)
683 (funcall callback output))))))
684
685 (defun context-coloring-send-buffer-to-scopifier ()
686 "Give the scopifier process its input so it can begin
687 scopifying."
688 (process-send-region
689 context-coloring-scopifier-process
690 (point-min) (point-max))
691 (process-send-eof
692 context-coloring-scopifier-process))
693
694 (defun context-coloring-scopify-and-colorize (command &optional callback)
695 "Invoke a scopifier via COMMAND with the current buffer's contents,
696 read the scopifier's response asynchronously and apply a parsed
697 list of tokens to `context-coloring-apply-tokens'.
698
699 Invoke CALLBACK when complete."
700 (let ((buffer context-coloring-buffer))
701 (context-coloring-scopify-shell-command
702 command
703 (lambda (output)
704 (let ((tokens (context-coloring-parse-array output)))
705 (with-current-buffer buffer
706 (context-coloring-apply-tokens tokens))
707 (setq context-coloring-scopifier-process nil)
708 (when callback (funcall callback))))))
709 (context-coloring-send-buffer-to-scopifier))
710
711
712 ;;; Dispatch
713
714 (defvar context-coloring-dispatch-hash-table (make-hash-table :test 'eq)
715 "Map dispatch strategy names to their corresponding property
716 lists, which contain details about the strategies.")
717
718 (defvar context-coloring-mode-hash-table (make-hash-table :test 'eq)
719 "Map major mode names to dispatch property lists.")
720
721 (defun context-coloring-define-dispatch (symbol &rest properties)
722 "Define a new dispatch named SYMBOL with PROPERTIES.
723
724 A \"dispatch\" is a property list describing a strategy for
725 coloring a buffer. There are three possible strategies: Parse
726 and color in a single function (`:colorizer'), parse in a
727 function that returns scope data (`:scopifier'), or parse with a
728 shell command that returns scope data (`:command'). In the
729 latter two cases, the scope data will be used to automatically
730 color the buffer.
731
732 PROPERTIES must include `:modes' and one of `:colorizer',
733 `:scopifier' or `:command'.
734
735 `:modes' - List of major modes this dispatch is valid for.
736
737 `:colorizer' - Symbol referring to a function that parses and
738 colors the buffer.
739
740 `:scopifier' - Symbol referring to a function that parses the
741 buffer a returns a flat vector of start, end and level data.
742
743 `:executable' - Optional name of an executable required by
744 `:command'.
745
746 `:command' - Shell command to execute with the current buffer
747 sent via stdin, and with a flat JSON array of start, end and
748 level data returned via stdout.
749
750 `:version' - Minimum required version that should be printed when
751 executing `:command' with a \"--version\" flag. The version
752 should be numeric, e.g. \"2\", \"19700101\", \"1.2.3\",
753 \"v1.2.3\" etc.
754
755 `:setup' - Arbitrary code to set up this dispatch when
756 `context-coloring-mode' is enabled.
757
758 `:teardown' - Arbitrary code to tear down this dispatch when
759 `context-coloring-mode' is disabled."
760 (let ((modes (plist-get properties :modes))
761 (colorizer (plist-get properties :colorizer))
762 (scopifier (plist-get properties :scopifier))
763 (command (plist-get properties :command)))
764 (when (null modes)
765 (error "No mode defined for dispatch"))
766 (when (not (or colorizer
767 scopifier
768 command))
769 (error "No colorizer, scopifier or command defined for dispatch"))
770 (puthash symbol properties context-coloring-dispatch-hash-table)
771 (dolist (mode modes)
772 (when (null (gethash mode context-coloring-mode-hash-table))
773 (puthash mode properties context-coloring-mode-hash-table)))))
774
775 (context-coloring-define-dispatch
776 'javascript-node
777 :modes '(js-mode js3-mode)
778 :executable "scopifier"
779 :command "scopifier"
780 :version "v1.1.1")
781
782 (context-coloring-define-dispatch
783 'javascript-js2
784 :modes '(js2-mode)
785 :colorizer 'context-coloring-js2-colorize
786 :setup
787 (lambda ()
788 (add-hook 'js2-post-parse-callbacks 'context-coloring-colorize nil t))
789 :teardown
790 (lambda ()
791 (remove-hook 'js2-post-parse-callbacks 'context-coloring-colorize t)))
792
793 (context-coloring-define-dispatch
794 'emacs-lisp
795 :modes '(emacs-lisp-mode)
796 :colorizer 'context-coloring-emacs-lisp-colorize)
797
798 (defun context-coloring-dispatch (&optional callback)
799 "Determine the optimal track for scopification / coloring of
800 the current buffer, then execute it.
801
802 Invoke CALLBACK when complete. It is invoked synchronously for
803 elisp tracks, and asynchronously for shell command tracks."
804 (let ((dispatch (gethash major-mode context-coloring-mode-hash-table))
805 colorizer
806 scopifier
807 command)
808 (cond
809 ((setq colorizer (plist-get dispatch :colorizer))
810 (funcall colorizer)
811 (when callback (funcall callback)))
812 ((setq scopifier (plist-get dispatch :scopifier))
813 (context-coloring-apply-tokens (funcall scopifier))
814 (when callback (funcall callback)))
815 ((setq command (plist-get dispatch :command))
816 (context-coloring-scopify-and-colorize command callback)))))
817
818
819 ;;; Colorization
820
821 (defvar context-coloring-colorize-hook nil
822 "Hooks to run after coloring a buffer.")
823
824 (defun context-coloring-colorize (&optional callback)
825 "Color the current buffer by function context.
826
827 Invoke CALLBACK when complete; see `context-coloring-dispatch'."
828 (interactive)
829 (context-coloring-dispatch
830 (lambda ()
831 (when callback (funcall callback))
832 (run-hooks 'context-coloring-colorize-hook))))
833
834 (defvar-local context-coloring-changed nil
835 "Indication that the buffer has changed recently, which implies
836 that it should be colored again by
837 `context-coloring-colorize-idle-timer' if that timer is being
838 used.")
839
840 (defun context-coloring-change-function (_start _end _length)
841 "Register a change so that a buffer can be colorized soon."
842 ;; Tokenization is obsolete if there was a change.
843 (context-coloring-kill-scopifier)
844 (setq context-coloring-changed t))
845
846 (defun context-coloring-maybe-colorize ()
847 "Colorize the current buffer if it has changed."
848 (when (and (eq context-coloring-buffer (window-buffer (selected-window)))
849 context-coloring-changed)
850 (setq context-coloring-changed nil)
851 (context-coloring-colorize)))
852
853
854 ;;; Versioning
855
856 (defun context-coloring-parse-version (string)
857 "Extract segments of a version STRING into a list. \"v1.0.0\"
858 produces (1 0 0), \"19700101\" produces (19700101), etc."
859 (let (version)
860 (while (string-match "[0-9]+" string)
861 (setq version (append version
862 (list (string-to-number (match-string 0 string)))))
863 (setq string (substring string (match-end 0))))
864 version))
865
866 (defun context-coloring-check-version (expected actual)
867 "Check that version EXPECTED is less than or equal to ACTUAL."
868 (let ((expected (context-coloring-parse-version expected))
869 (actual (context-coloring-parse-version actual))
870 (continue t)
871 (acceptable t))
872 (while (and continue expected)
873 (let ((an-expected (car expected))
874 (an-actual (car actual)))
875 (cond
876 ((> an-actual an-expected)
877 (setq acceptable t)
878 (setq continue nil))
879 ((< an-actual an-expected)
880 (setq acceptable nil)
881 (setq continue nil))))
882 (setq expected (cdr expected))
883 (setq actual (cdr actual)))
884 acceptable))
885
886 (defvar context-coloring-check-scopifier-version-hook nil
887 "Hooks to run after checking the scopifier version.")
888
889 (defun context-coloring-check-scopifier-version (&optional callback)
890 "Asynchronously invoke CALLBACK with a predicate indicating
891 whether the current scopifier version satisfies the minimum
892 version number required for the current major mode."
893 (let ((dispatch (gethash major-mode context-coloring-mode-hash-table)))
894 (when dispatch
895 (let ((version (plist-get dispatch :version))
896 (command (plist-get dispatch :command)))
897 (context-coloring-scopify-shell-command
898 (context-coloring-join (list command "--version") " ")
899 (lambda (output)
900 (if (context-coloring-check-version version output)
901 (progn
902 (when callback (funcall callback t)))
903 (when callback (funcall callback nil)))
904 (run-hooks 'context-coloring-check-scopifier-version-hook)))))))
905
906
907 ;;; Themes
908
909 (defvar context-coloring-theme-hash-table (make-hash-table :test 'eq)
910 "Map theme names to theme properties.")
911
912 (defun context-coloring-theme-p (theme)
913 "Return t if THEME is defined, nil otherwise."
914 (and (gethash theme context-coloring-theme-hash-table)))
915
916 (defconst context-coloring-level-face-regexp
917 "context-coloring-level-\\([[:digit:]]+\\)-face"
918 "Extract a level from a face.")
919
920 (defvar context-coloring-originally-set-theme-hash-table
921 (make-hash-table :test 'eq)
922 "Cache custom themes who originally set their own
923 `context-coloring-level-N-face' faces.")
924
925 (defun context-coloring-theme-originally-set-p (theme)
926 "Return t if there is a `context-coloring-level-N-face'
927 originally set for THEME, nil otherwise."
928 (let (originally-set)
929 (cond
930 ;; `setq' might return a non-nil value for the sake of this `cond'.
931 ((setq
932 originally-set
933 (gethash
934 theme
935 context-coloring-originally-set-theme-hash-table))
936 (eq originally-set 'yes))
937 (t
938 (let* ((settings (get theme 'theme-settings))
939 (tail settings)
940 found)
941 (while (and tail (not found))
942 (and (eq (nth 0 (car tail)) 'theme-face)
943 (string-match
944 context-coloring-level-face-regexp
945 (symbol-name (nth 1 (car tail))))
946 (setq found t))
947 (setq tail (cdr tail)))
948 found)))))
949
950 (defun context-coloring-cache-originally-set (theme originally-set)
951 "Remember if THEME had colors originally set for it. If
952 ORIGINALLY-SET is non-nil, it did, otherwise it didn't."
953 ;; Caching whether a theme was originally set is kind of dirty, but we have to
954 ;; do it to remember the past state of the theme. There are probably some
955 ;; edge cases where caching will be an issue, but they are probably rare.
956 (puthash
957 theme
958 (if originally-set 'yes 'no)
959 context-coloring-originally-set-theme-hash-table))
960
961 (defun context-coloring-warn-theme-originally-set (theme)
962 "Warn the user that the colors for THEME are already originally
963 set."
964 (warn "Context coloring colors for theme `%s' are already defined" theme))
965
966 (defun context-coloring-theme-highest-level (theme)
967 "Return the highest level N of a face like
968 `context-coloring-level-N-face' set for THEME, or `-1' if there
969 is none."
970 (let* ((settings (get theme 'theme-settings))
971 (tail settings)
972 face-string
973 number
974 (found -1))
975 (while tail
976 (and (eq (nth 0 (car tail)) 'theme-face)
977 (setq face-string (symbol-name (nth 1 (car tail))))
978 (string-match
979 context-coloring-level-face-regexp
980 face-string)
981 (setq number (string-to-number
982 (substring face-string
983 (match-beginning 1)
984 (match-end 1))))
985 (> number found)
986 (setq found number))
987 (setq tail (cdr tail)))
988 found))
989
990 (defun context-coloring-apply-theme (theme)
991 "Apply THEME's properties to its respective custom theme,
992 which must already exist and which *should* already be enabled."
993 (let* ((properties (gethash theme context-coloring-theme-hash-table))
994 (colors (plist-get properties :colors))
995 (level -1))
996 ;; Only clobber when we have to.
997 (when (custom-theme-enabled-p theme)
998 (setq context-coloring-maximum-face (- (length colors) 1)))
999 (apply
1000 'custom-theme-set-faces
1001 theme
1002 (mapcar
1003 (lambda (color)
1004 (setq level (+ level 1))
1005 `(,(context-coloring-level-face level) ((t (:foreground ,color)))))
1006 colors))))
1007
1008 (defun context-coloring-define-theme (theme &rest properties)
1009 "Define a context theme named THEME for coloring scope levels.
1010
1011 PROPERTIES is a property list specifiying the following details:
1012
1013 `:aliases': List of symbols of other custom themes that these
1014 colors are applicable to.
1015
1016 `:colors': List of colors that this context theme uses.
1017
1018 `:override': If non-nil, this context theme is intentionally
1019 overriding colors set by a custom theme. Don't set this non-nil
1020 unless there is a custom theme you want to use which sets
1021 `context-coloring-level-N-face' faces that you want to replace.
1022
1023 `:recede': If non-nil, this context theme should not apply its
1024 colors if a custom theme already sets
1025 `context-coloring-level-N-face' faces. This option is
1026 optimistic; set this non-nil if you would rather confer the duty
1027 of picking colors to a custom theme author (if / when he ever
1028 gets around to it).
1029
1030 By default, context themes will always override custom themes,
1031 even if those custom themes set `context-coloring-level-N-face'
1032 faces. If a context theme does override a custom theme, a
1033 warning will be raised, at which point you may want to enable the
1034 `:override' option, or just delete your context theme and opt to
1035 use your custom theme's author's colors instead.
1036
1037 Context themes only work for the custom theme with the highest
1038 precedence, i.e. the car of `custom-enabled-themes'."
1039 (let ((aliases (plist-get properties :aliases))
1040 (override (plist-get properties :override))
1041 (recede (plist-get properties :recede)))
1042 (dolist (name (append `(,theme) aliases))
1043 (puthash name properties context-coloring-theme-hash-table)
1044 (when (custom-theme-p name)
1045 (let ((originally-set (context-coloring-theme-originally-set-p name)))
1046 (context-coloring-cache-originally-set name originally-set)
1047 ;; In the particular case when you innocently define colors that a
1048 ;; custom theme originally set, warn. Arguably this only has to be
1049 ;; done at enable time, but it is probably more useful to do it at
1050 ;; definition time for prompter feedback.
1051 (when (and originally-set
1052 (not recede)
1053 (not override))
1054 (context-coloring-warn-theme-originally-set name))
1055 ;; Set (or overwrite) colors.
1056 (when (not (and originally-set
1057 recede))
1058 (context-coloring-apply-theme name)))))))
1059
1060 (defun context-coloring-enable-theme (theme)
1061 "Apply THEME if its colors are not already set, else just set
1062 `context-coloring-maximum-face' to the correct value for THEME."
1063 (let* ((properties (gethash theme context-coloring-theme-hash-table))
1064 (recede (plist-get properties :recede))
1065 (override (plist-get properties :override)))
1066 (cond
1067 (recede
1068 (let ((highest-level (context-coloring-theme-highest-level theme)))
1069 (cond
1070 ;; This can be true whether originally set by a custom theme or by a
1071 ;; context theme.
1072 ((> highest-level -1)
1073 (setq context-coloring-maximum-face highest-level))
1074 ;; It is possible that the corresponding custom theme did not exist at
1075 ;; the time of defining this context theme, and in that case the above
1076 ;; condition proves the custom theme did not originally set any faces,
1077 ;; so we have license to apply the context theme for the first time
1078 ;; here.
1079 (t
1080 (context-coloring-apply-theme theme)))))
1081 (t
1082 (let ((originally-set (context-coloring-theme-originally-set-p theme)))
1083 ;; Cache now in case the context theme was defined after the custom
1084 ;; theme.
1085 (context-coloring-cache-originally-set theme originally-set)
1086 (when (and originally-set
1087 (not override))
1088 (context-coloring-warn-theme-originally-set theme))
1089 (context-coloring-apply-theme theme))))))
1090
1091 (defadvice enable-theme (after context-coloring-enable-theme (theme) activate)
1092 "Enable colors for context themes just-in-time."
1093 (when (and (not (eq theme 'user)) ; Called internally by `enable-theme'.
1094 (custom-theme-p theme) ; Guard against non-existent themes.
1095 (context-coloring-theme-p theme))
1096 (when (= (length custom-enabled-themes) 1)
1097 ;; Cache because we can't reliably figure it out in reverse.
1098 (setq context-coloring-original-maximum-face
1099 context-coloring-maximum-face))
1100 (context-coloring-enable-theme theme)))
1101
1102 (defadvice disable-theme (after context-coloring-disable-theme (theme) activate)
1103 "Update `context-coloring-maximum-face'."
1104 (when (custom-theme-p theme) ; Guard against non-existent themes.
1105 (let ((enabled-theme (car custom-enabled-themes)))
1106 (if (context-coloring-theme-p enabled-theme)
1107 (progn
1108 (context-coloring-enable-theme enabled-theme))
1109 ;; Assume we are back to no theme; act as if nothing ever happened.
1110 ;; This is still prone to intervention, but rather extraordinarily.
1111 (setq context-coloring-maximum-face
1112 context-coloring-original-maximum-face)))))
1113
1114 (context-coloring-define-theme
1115 'ample
1116 :recede t
1117 :colors '("#bdbdb3"
1118 "#baba36"
1119 "#6aaf50"
1120 "#5180b3"
1121 "#ab75c3"
1122 "#cd7542"
1123 "#df9522"
1124 "#454545"))
1125
1126 (context-coloring-define-theme
1127 'anti-zenburn
1128 :recede t
1129 :colors '("#232333"
1130 "#6c1f1c"
1131 "#401440"
1132 "#0f2050"
1133 "#205070"
1134 "#336c6c"
1135 "#23733c"
1136 "#6b400c"
1137 "#603a60"
1138 "#2f4070"
1139 "#235c5c"))
1140
1141 (context-coloring-define-theme
1142 'grandshell
1143 :recede t
1144 :colors '("#bebebe"
1145 "#5af2ee"
1146 "#b2baf6"
1147 "#f09fff"
1148 "#efc334"
1149 "#f6df92"
1150 "#acfb5a"
1151 "#888888"))
1152
1153 (context-coloring-define-theme
1154 'leuven
1155 :recede t
1156 :colors '("#333333"
1157 "#0000ff"
1158 "#6434a3"
1159 "#ba36a5"
1160 "#d0372d"
1161 "#036a07"
1162 "#006699"
1163 "#006fe0"
1164 "#808080"))
1165
1166 (context-coloring-define-theme
1167 'monokai
1168 :recede t
1169 :colors '("#f8f8f2"
1170 "#66d9ef"
1171 "#a1efe4"
1172 "#a6e22e"
1173 "#e6db74"
1174 "#fd971f"
1175 "#f92672"
1176 "#fd5ff0"
1177 "#ae81ff"))
1178
1179 (context-coloring-define-theme
1180 'solarized
1181 :recede t
1182 :aliases '(solarized-light
1183 solarized-dark
1184 sanityinc-solarized-light
1185 sanityinc-solarized-dark)
1186 :colors '("#839496"
1187 "#268bd2"
1188 "#2aa198"
1189 "#859900"
1190 "#b58900"
1191 "#cb4b16"
1192 "#dc322f"
1193 "#d33682"
1194 "#6c71c4"
1195 "#69b7f0"
1196 "#69cabf"
1197 "#b4c342"
1198 "#deb542"
1199 "#f2804f"
1200 "#ff6e64"
1201 "#f771ac"
1202 "#9ea0e5"))
1203
1204 (context-coloring-define-theme
1205 'spacegray
1206 :recede t
1207 :colors '("#ffffff"
1208 "#89aaeb"
1209 "#c189eb"
1210 "#bf616a"
1211 "#dca432"
1212 "#ebcb8b"
1213 "#b4eb89"
1214 "#89ebca"))
1215
1216 (context-coloring-define-theme
1217 'tango
1218 :recede t
1219 :colors '("#2e3436"
1220 "#346604"
1221 "#204a87"
1222 "#5c3566"
1223 "#a40000"
1224 "#b35000"
1225 "#c4a000"
1226 "#8ae234"
1227 "#8cc4ff"
1228 "#ad7fa8"
1229 "#ef2929"
1230 "#fcaf3e"
1231 "#fce94f"))
1232
1233 (context-coloring-define-theme
1234 'zenburn
1235 :recede t
1236 :colors '("#dcdccc"
1237 "#93e0e3"
1238 "#bfebbf"
1239 "#f0dfaf"
1240 "#dfaf8f"
1241 "#cc9393"
1242 "#dc8cc3"
1243 "#94bff3"
1244 "#9fc59f"
1245 "#d0bf8f"
1246 "#dca3a3"))
1247
1248
1249 ;;; Minor mode
1250
1251 (defvar-local context-coloring-colorize-idle-timer nil
1252 "The currently-running idle timer.")
1253
1254 (defcustom context-coloring-delay 0.25
1255 "Delay between a buffer update and colorization.
1256
1257 Increase this if your machine is high-performing. Decrease it if
1258 it ain't.
1259
1260 Supported modes: `js-mode', `js3-mode'"
1261 :group 'context-coloring)
1262
1263 (defun context-coloring-setup-idle-change-detection ()
1264 "Setup idle change detection."
1265 (add-hook
1266 'after-change-functions 'context-coloring-change-function nil t)
1267 (setq context-coloring-colorize-idle-timer
1268 (run-with-idle-timer
1269 context-coloring-delay
1270 t
1271 'context-coloring-maybe-colorize)))
1272
1273 ;;;###autoload
1274 (define-minor-mode context-coloring-mode
1275 "Context-based code coloring, inspired by Douglas Crockford."
1276 nil " Context" nil
1277 (if (not context-coloring-mode)
1278 (progn
1279 (context-coloring-kill-scopifier)
1280 (when context-coloring-colorize-idle-timer
1281 (cancel-timer context-coloring-colorize-idle-timer))
1282 (let ((dispatch (gethash major-mode context-coloring-mode-hash-table)))
1283 (when dispatch
1284 (let ((command (plist-get dispatch :command))
1285 (teardown (plist-get dispatch :teardown)))
1286 (when command
1287 (remove-hook
1288 'after-change-functions 'context-coloring-change-function t))
1289 (when teardown
1290 (funcall teardown)))))
1291 (font-lock-mode)
1292 (jit-lock-mode t))
1293
1294 ;; Remember this buffer. This value should not be dynamically-bound.
1295 (setq context-coloring-buffer (current-buffer))
1296
1297 ;; Font lock is incompatible with this mode; the converse is also true.
1298 (font-lock-mode 0)
1299 (jit-lock-mode nil)
1300
1301 ;; Safely change the valye of this function as necessary.
1302 (make-local-variable 'font-lock-syntactic-face-function)
1303
1304 (let ((dispatch (gethash major-mode context-coloring-mode-hash-table)))
1305 (if dispatch
1306 (progn
1307 (let ((command (plist-get dispatch :command))
1308 (version (plist-get dispatch :version))
1309 (executable (plist-get dispatch :executable))
1310 (setup (plist-get dispatch :setup))
1311 (colorize-initially-p t))
1312 (when command
1313 ;; Shell commands recolor on change, idly.
1314 (cond
1315 ((and executable
1316 (null (executable-find executable)))
1317 (message "Executable \"%s\" not found" executable)
1318 (setq colorize-initially-p nil))
1319 (version
1320 (context-coloring-check-scopifier-version
1321 (lambda (sufficient-p)
1322 (if sufficient-p
1323 (progn
1324 (context-coloring-setup-idle-change-detection)
1325 (context-coloring-colorize))
1326 (message "Update to the minimum version of \"%s\" (%s)"
1327 executable version))))
1328 (setq colorize-initially-p nil))
1329 (t
1330 (context-coloring-setup-idle-change-detection))))
1331 (when setup
1332 (funcall setup))
1333 ;; Colorize once initially.
1334 (when colorize-initially-p
1335 (context-coloring-colorize))))
1336 (when (null dispatch)
1337 (message "Context coloring is not available for this major mode"))))))
1338
1339 (provide 'context-coloring)
1340
1341 ;;; context-coloring.el ends here