From 79513b20a0e04f2ffb59ce7595cba10d4d285cfa Mon Sep 17 00:00:00 2001 From: Jackson Ray Hamilton Date: Thu, 27 Nov 2014 12:18:05 -0800 Subject: [PATCH] Remove styling from faces. --- README.md | 3 +-- bin/cli.js | 2 +- context-coloring.el | 59 ++++++--------------------------------------- scopifier.js | 23 ++++++------------ 4 files changed, 16 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index b476f4190..2c28844b7 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,7 @@ Highlights JavaScript code according to function context. scope is a different color, and code within such functions is another color, and so on. - Identifiers retain the color of the scope in which they were declared. -- Identifiers are bold when first declared. -- Comments are gray and italic. +- 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 diff --git a/bin/cli.js b/bin/cli.js index 3453b3379..1a059bc0e 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,6 +1,6 @@ // Reads a JavaScript file from stdin. -// Writes an array of `[start, end, level, style]' tokens to stdout. +// Writes an array of tokens to stdout. 'use strict'; diff --git a/context-coloring.el b/context-coloring.el index b32ab352f..9f21dfc21 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -92,46 +92,6 @@ "Context coloring face, depth 6." :group 'context-coloring-faces) -(defface context-coloring-depth--1-italic-face - '((default (:inherit context-coloring-depth--1-face :slant italic))) - "Context coloring face, depth -1; italic; comments." - :group 'context-coloring-faces) - -(defface context-coloring-depth-0-bold-face - '((default (:inherit context-coloring-depth-0-face :weight bold))) - "Context coloring face, depth 0; bold; global scope." - :group 'context-coloring-faces) - -(defface context-coloring-depth-1-bold-face - '((default (:inherit context-coloring-depth-1-face :weight bold))) - "Context coloring face, depth 1; bold." - :group 'context-coloring-faces) - -(defface context-coloring-depth-2-bold-face - '((default (:inherit context-coloring-depth-2-face :weight bold))) - "Context coloring face, depth 2; bold." - :group 'context-coloring-faces) - -(defface context-coloring-depth-3-bold-face - '((default (:inherit context-coloring-depth-3-face :weight bold))) - "Context coloring face, depth 3; bold." - :group 'context-coloring-faces) - -(defface context-coloring-depth-4-bold-face - '((default (:inherit context-coloring-depth-4-face :weight bold))) - "Context coloring face, depth 4; bold." - :group 'context-coloring-faces) - -(defface context-coloring-depth-5-bold-face - '((default (:inherit context-coloring-depth-5-face :weight bold))) - "Context coloring face, depth 5; bold." - :group 'context-coloring-faces) - -(defface context-coloring-depth-6-bold-face - '((default (:inherit context-coloring-depth-6-face :weight bold))) - "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.") @@ -139,8 +99,8 @@ Determines depth at which to cycle through faces again.") ;;; Face functions -(defsubst context-coloring-level-face (depth style) - "Return face-name for DEPTH and STYLE as a string \"context-coloring-depth-DEPTH-face\". +(defsubst context-coloring-level-face (depth) + "Return face-name for DEPTH as a string \"context-coloring-depth-DEPTH-face\". For example: \"context-coloring-depth-1-face\"." (intern-soft (concat "context-coloring-depth-" @@ -154,9 +114,6 @@ For example: \"context-coloring-depth-1-face\"." (+ 1 (mod (- depth 1) (- context-coloring-face-count 1))))) - (cond ((= 1 style) "-bold") - ((= 2 style) "-italic") - (t "")) "-face"))) @@ -210,9 +167,9 @@ imply that it should be colorized again.") (defun context-coloring-apply-tokens (tokens) "Processes TOKENS to apply context-based coloring to the -current buffer. Tokens are 4 integers: start, end, level, and -style. The array is flat, with a new token occurring after every -4th number." +current buffer. Tokens are 3 integers: start, end, level. The +array is flat, with a new token occurring after every 3rd +number." (with-silent-modifications ;; Reset in case there should be uncolored areas. (remove-text-properties (point-min) (point-max) `(face nil rear-nonsticky nil)) @@ -222,10 +179,8 @@ style. The array is flat, with a new token occurring after every (add-text-properties (elt tokens i) (elt tokens (+ i 1)) - `(face ,(context-coloring-level-face - (elt tokens (+ i 2)) - (elt tokens (+ i 3))) rear-nonsticky t)) - (setq i (+ i 4)))))) + `(face ,(context-coloring-level-face (elt tokens (+ i 2))) rear-nonsticky t)) + (setq i (+ i 3)))))) (defsubst context-coloring-kill-scopifier () "Kills the currently-running scopifier process for this diff --git a/scopifier.js b/scopifier.js index 814550106..9e7c8ef47 100644 --- a/scopifier.js +++ b/scopifier.js @@ -1,14 +1,9 @@ 'use strict'; var escope = require('./lib/escope'), - esprima = require('./lib/esprima'), + esprima = require('./lib/esprima'); - normal = 0, - bold = 1, - italic = 2; - -// Given code, returns an array of `[start, end, level, style]' tokens for -// context-coloring. +// Given code, returns an array of tokens for context-coloring. module.exports = function (code) { var analyzedScopes, ast, @@ -65,8 +60,7 @@ module.exports = function (code) { scopes.push( range[0] + 1, range[1] + 1, - scope.level, - normal + scope.level ); definitionsIndex = tokens.length; definitionsCount = 0; @@ -79,8 +73,7 @@ module.exports = function (code) { tokens.push( range[0] + 1, range[1] + 1, - scope.level, - bold + scope.level ); } } @@ -93,7 +86,7 @@ module.exports = function (code) { // declared and initialized simultaneously; this filters // them.) for (k = 0; k < definitionsCount; k += 1) { - pointer = definitionsIndex + (k * 4); + pointer = definitionsIndex + (k * 3); if (tokens[pointer] === range[0] + 1 && tokens[pointer + 1] === range[1] + 1) { isDefined = true; @@ -105,8 +98,7 @@ module.exports = function (code) { // Handle global references too. range[0] + 1, range[1] + 1, - reference.resolved ? reference.resolved.scope.level : 0, - reference.__maybeImplicitGlobal ? bold : normal + reference.resolved ? reference.resolved.scope.level : 0 ); } } @@ -120,8 +112,7 @@ module.exports = function (code) { tokens.push( range[0] + 1, range[1] + 1, - -1, - italic + -1 ); } -- 2.39.2