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 following by an assignment expression could be a
-side-effect... or, a specially-constructed object's private state could be being
-manipulated.
+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.
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][].
+*syntax* highlighting. Highlighting keywords can help one to detect spelling
+errors, or alert one to unclosed string literals; but so can a [linter][], which
+can also be integrated into your workflow via [flycheck][].
## Features
```
[linter]: https://github.com/jacksonrayhamilton/jslinted
-[emacs integration]: https://github.com/jacksonrayhamilton/jslinted#emacs-integration
+[flycheck]: https://github.com/flycheck/flycheck
[node]: http://nodejs.org/download/
[load path]: https://www.gnu.org/software/emacs/manual/html_node/emacs/Lisp-Libraries.html
"Context coloring face, depth 6."
:group 'context-coloring-faces)
-(defconst context-coloring-face-count 7
- "Number of faces defined for highlighting delimiter levels.
-Determines depth at which to cycle through faces again.")
-
(defface context-coloring-depth--1-italic-face
'((default (:inherit context-coloring-depth--1-face :slant italic)))
"Context coloring face, depth -1; italic; comments."
"Context coloring face, depth 6; bold."
:group 'context-coloring-faces)
+(defconst context-coloring-face-count 7
+ "Number of faces defined for highlighting delimiter levels.
+Determines depth at which to cycle through faces again.")
+
;;; Face functions
;;; Customizable variables
(defcustom context-coloring-delay 0.25
- "Delay between a buffer update and colorization.
+ "Delay between a buffer updates and colorization.
+
+Increase this if your machine is high-performing. Decrease it it if ain't."
+ :group 'context-coloring)
-If your performance is poor, you might want to increase this."
+(defcustom context-coloring-benchmark-colorization nil
+ "If non-nil, display how long each colorization took."
:group 'context-coloring)
imply that it should be colorized again.")
(make-variable-buffer-local 'context-coloring-changed)
+(defvar context-coloring-start-time nil
+ "Used to benchmark colorization time.")
+(make-variable-buffer-local 'context-coloring-changed)
+
;;; Scopification
(setq context-coloring-scopifier-process nil)))
(defun context-coloring-parse-array (input)
- "Specialized alternative JSON parser."
+ "Specialized JSON parser for a flat array of numbers."
(vconcat (mapcar 'string-to-number (split-string (substring input 1 -1) ","))))
(defun context-coloring-scopify ()
(start-process-shell-command "scopifier" nil context-coloring-scopifier-path))
(let ((output "")
- (buffer context-coloring-buffer))
+ (buffer context-coloring-buffer)
+ (start-time context-coloring-start-time))
;; The process may produce output in multiple chunks. This filter
;; accumulates the chunks into a message.
(let ((tokens (context-coloring-parse-array output)))
(with-current-buffer buffer
(context-coloring-apply-tokens tokens))
- (setq context-coloring-scopifier-process nil))))))
+ (setq context-coloring-scopifier-process nil)
+ (when context-coloring-benchmark-colorization
+ (message "Colorized (after %f seconds)." (- (float-time) start-time))))))))
- ;; Give the process its input.
+ ;; Give the process its input so it can begin.
(process-send-region context-coloring-scopifier-process (point-min) (point-max))
(process-send-eof context-coloring-scopifier-process))
(defun context-coloring-colorize ()
"Colors the current buffer by function context."
(interactive)
+ (when context-coloring-benchmark-colorization
+ (setq context-coloring-start-time (float-time))
+ (message "%s" "Colorizing..."))
(context-coloring-scopify))
(defun context-coloring-change-function (start end length)
(font-lock-mode)
(jit-lock-mode t))
+ ;; Remember this buffer. This value should not be dynamically-bound.
(setq context-coloring-buffer (current-buffer))
;; Colorize once initially.
(context-coloring-colorize)
- ;; Font lock is not compatible with this mode; the converse is also true.
+ ;; Font lock is incompatible with this mode; the converse is also true.
(font-lock-mode 0)
(jit-lock-mode nil)
(setq context-coloring-colorize-idle-timer
(run-with-idle-timer context-coloring-delay t 'context-coloring-maybe-colorize))))
-;;;###autoload
-(defun context-coloring-mode-enable ()
- (context-coloring-mode 1))
-
-;;;###autoload
-(defun context-coloring-mode-disable ()
- (context-coloring-mode 0))
-
-;;;###autoload
-(define-globalized-minor-mode global-context-coloring-mode
- context-coloring-mode context-coloring-mode-enable)
-
(provide 'context-coloring)
;;; context-coloring.el ends here