branch: master commit b19030972e53b3043d57b2a81ff644925745a9e1 Author: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com> Commit: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com>
Update documentation to be language-agnostic. --- README.md | 30 +++++++++++++++++------------- context-coloring.el | 28 +++++++++++++++++----------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 2c28844..cf1deff 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ <img alt="Screenshot of JavaScript code highlighted by context." src="screenshot.png" title="Screenshot"> </p> -Highlights JavaScript code according to function context. +Highlights code according to function context. - 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, @@ -12,19 +12,21 @@ Highlights JavaScript code according to function context. - Identifiers retain the color of the scope in which they were declared. - Comments are gray. -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 +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 name +shadowing or unexpected assignment. 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. +side-effect... or, the state of a closure could be undergoing change. -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]. +This coloring strategy is probably more useful than conventional *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][] could also spot those errors, and if +[integrated via flycheck][integration], an extra spot opens up in your editing +toolbelt. + +Give context coloring a try; you may find that it *changes the way you write +code*. ## Features @@ -37,7 +39,9 @@ with many others, and can be [seamlessly integrated via flycheck][integration]. ## Usage -Requires Emacs 24+ and [Node.js 0.10+][node]. +Requires Emacs 24+. + +JavaScript language support requires [Node.js 0.10+][node]. - Clone this repository. diff --git a/context-coloring.el b/context-coloring.el index b5ad9bc..b492288 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -1,9 +1,9 @@ -;;; context-coloring.el --- JavaScript syntax highlighting, except not for syntax. -*- lexical-binding: t; -*- +;;; context-coloring.el --- Syntax highlighting, except not for syntax. -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Jackson Ray Hamilton ;; Author: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com> -;; Keywords: context coloring highlighting js javascript +;; Keywords: context coloring syntax highlighting ;; Version: 1.0.0 ;; Package-Requires: ((emacs "24")) @@ -22,15 +22,19 @@ ;;; Commentary: -;; Highlights JavaScript code according to function context. -;; -;; Usage: -;; -;; Install Node.js 0.10+. -;; In your ~/.emacs: -;; +;; Colors code by scope, rather than by syntax. + +;; A range of characters encompassing a scope is colored according to its level; +;; the global scope is white, scopes within the global scope are yellow, scopes +;; within scopes within the global scope are green, etc. Variables defined in a +;; parent scope which are referenced from child scopes retain the same color as +;; the scope in which they are defined; a variable defined in the global scope +;; will be the same color when referenced from nested scopes. + +;; To use, add the following to your ~/.emacs: + ;; (require 'context-coloring) -;; (add-hook 'js-mode-hook 'context-coloring-mode) +;; (add-hook 'js-mode-hook 'context-coloring-mode) ; Requires Node.js 0.10+. ;;; Code: @@ -91,6 +95,8 @@ "Context coloring face, level 6." :group 'context-coloring-faces) +;;; Additional 6 faces as placeholders for potential (insane) levels of nesting. + (defface context-coloring-level-7-face '((t (:inherit context-coloring-level-1-face))) "Context coloring face, level 7." @@ -300,7 +306,7 @@ colorizing would be redundant." ;;;###autoload (define-minor-mode context-coloring-mode - "Context-based code coloring for JavaScript, inspired by Douglas Crockford." + "Context-based code coloring, inspired by Douglas Crockford." nil " Context" nil (if (not context-coloring-mode) (progn