[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 32fa415 226/271: Use `font-lock' for comments and strings.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 32fa415 226/271: Use `font-lock' for comments and strings. |
Date: |
Thu, 05 Feb 2015 18:31:28 +0000 |
branch: master
commit 32fa415677609f332812763baf5f21ff7adeb1bc
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Use `font-lock' for comments and strings.
---
context-coloring.el | 22 ++++++++++++----------
languages/javascript/scopifier.js | 12 ------------
test/context-coloring-test.el | 6 ++++++
3 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index 88660e0..cc9f909 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -51,6 +51,10 @@ Increase this if your machine is high-performing. Decrease
it if it ain't.
Supported modes: `js-mode', `js3-mode'"
:group 'context-coloring)
+(defcustom context-coloring-comments-and-strings t
+ "If non-nil, also color comments and strings using `font-lock'."
+ :group 'context-coloring)
+
(defcustom context-coloring-js-block-scopes nil
"If non-nil, also color block scopes in the scope hierarchy in JavaScript.
@@ -97,7 +101,6 @@ used.")
,doc
:group 'context-coloring)))
-(context-coloring-defface -1 "white" "#7f7f7f" "#7f7f7f")
(context-coloring-defface 0 "white" "#000000" "#ffffff")
(context-coloring-defface 1 "yellow" "#007f80" "#ffff80")
(context-coloring-defface 2 "green" "#001580" "#cdfacd")
@@ -139,9 +142,6 @@ Determines level at which to cycle through faces again."
(dolist (pair pairs)
(let ((level (car pair))
(color (cdr pair)))
- (cond
- ((eq level 'comment)
- (setq level -1)))
(set-face-foreground (context-coloring-face-symbol level) color))))
(defsubst context-coloring-level-face (level)
@@ -159,6 +159,10 @@ END (exclusive) with the face corresponding to LEVEL."
end
`(face ,(context-coloring-level-face level))))
+(defsubst context-coloring-maybe-colorize-comments-and-strings ()
+ (when context-coloring-comments-and-strings
+ (font-lock-fontify-syntactically-region (point-min) (point-max))))
+
;;; js2-mode colorization
@@ -216,10 +220,6 @@ generated by js2-mode."
(lambda (node end-p)
(when (null end-p)
(cond
- ((js2-comment-node-p node)
- (context-coloring-js2-colorize-node
- node
- -1))
((js2-scope-p node)
(context-coloring-js2-colorize-node
node
@@ -238,7 +238,8 @@ generated by js2-mode."
node
(context-coloring-js2-scope-level defining-scope))))))
;; The `t' indicates to search children.
- t)))))
+ t)))
+ (context-coloring-maybe-colorize-comments-and-strings)))
;;; Shell command scopification / colorization
@@ -256,7 +257,8 @@ level. The vector is flat, with a new token occurring after
every
(elt tokens i)
(elt tokens (+ i 1))
(elt tokens (+ i 2)))
- (setq i (+ i 3))))))
+ (setq i (+ i 3))))
+ (context-coloring-maybe-colorize-comments-and-strings)))
(defun context-coloring-parse-array (input)
"Specialized JSON parser for a flat array of numbers."
diff --git a/languages/javascript/scopifier.js
b/languages/javascript/scopifier.js
index 6b46392..0171ab2 100644
--- a/languages/javascript/scopifier.js
+++ b/languages/javascript/scopifier.js
@@ -11,7 +11,6 @@ function scopifier(code) {
var analyzedScopes,
ast,
- comment,
definition,
definitionsCount,
definitionsIndex,
@@ -30,7 +29,6 @@ function scopifier(code) {
// Gracefully handle parse errors by doing nothing.
try {
ast = esprima.parse(code, {
- comment: true,
range: true
});
analyzedScopes = escope.analyze(ast).scopes;
@@ -109,16 +107,6 @@ function scopifier(code) {
}
}
- for (i = 0; i < ast.comments.length; i += 1) {
- comment = ast.comments[i];
- range = comment.range;
- tokens.push(
- range[0] + 1,
- range[1] + 1,
- -1
- );
- }
-
return scopes.concat(tokens);
}
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
index 52a93fb..4f72ff2 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -14,7 +14,11 @@
(defun context-coloring-test-read-file (path)
(get-string-from-file (context-coloring-test-resolve-path path)))
+(defun context-coloring-test-setup ()
+ (setq context-coloring-comments-and-strings nil))
+
(defun context-coloring-test-cleanup ()
+ (setq context-coloring-comments-and-strings t)
(setq context-coloring-after-colorize-hook nil)
(setq context-coloring-js-block-scopes nil))
@@ -24,6 +28,7 @@ FIXTURE."
`(with-temp-buffer
(unwind-protect
(progn
+ (context-coloring-test-setup)
(insert (context-coloring-test-read-file ,fixture))
,@body)
(context-coloring-test-cleanup))))
@@ -49,6 +54,7 @@ FIXTURE. A teardown callback is passed to CALLBACK for it to
invoke when it is done."
(context-coloring-test-with-temp-buffer-async
(lambda (done-with-temp-buffer)
+ (context-coloring-test-setup)
(insert (context-coloring-test-read-file fixture))
(funcall
callback
- [elpa] master 8300976 244/271: Merge branch 'master' into develop, (continued)
- [elpa] master 8300976 244/271: Merge branch 'master' into develop, Jackson Ray Hamilton, 2015/02/05
- [elpa] master 9a883e2 217/271: Version 2.1.0., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 34fb7e9 267/271: Fix readme link., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 9fdc037 243/271: Merge branch 'develop', Jackson Ray Hamilton, 2015/02/05
- [elpa] master 7001dce 201/271: Use js2-node-top-level-decl-p as a fast track., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 221b583 156/271: Update hooking strategy., Jackson Ray Hamilton, 2015/02/05
- [elpa] master e2ee311 183/271: Fix timer existence check., Jackson Ray Hamilton, 2015/02/05
- [elpa] master a2ba1ef 213/271: Version 2.0.1., Jackson Ray Hamilton, 2015/02/05
- [elpa] master bef41e1 205/271: Merge branch 'feature/optimize-js2-mode' into develop, Jackson Ray Hamilton, 2015/02/05
- [elpa] master a14be3c 270/271: Merge commit 'fedf88552990afa269366dfa4c3f5af6d1cdb7c2' from context-coloring, Jackson Ray Hamilton, 2015/02/05
- [elpa] master 32fa415 226/271: Use `font-lock' for comments and strings.,
Jackson Ray Hamilton <=
- [elpa] master 450aa85 236/271: Use macros to clean up tests., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 555820b 247/271: Merge branch 'master' into develop, Jackson Ray Hamilton, 2015/02/05
- [elpa] master 43bb3c1 261/271: Remove unnecessary file from .elpaignore., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 195fbe7 196/271: Improve assertion message., Jackson Ray Hamilton, 2015/02/05
- [elpa] master d82f357 199/271: Merge branch 'feature/name-nodes' into develop, Jackson Ray Hamilton, 2015/02/05
- [elpa] master 310aca4 228/271: Use `save-excursion' before fontifying., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 5cc5224 249/271: Update sentence spacing., Jackson Ray Hamilton, 2015/02/05
- [elpa] master de8eacd 204/271: Update benchmarks in readme., Jackson Ray Hamilton, 2015/02/05
- [elpa] master f15c193 189/271: Escape., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 31ee972 197/271: Improve property lookup test., Jackson Ray Hamilton, 2015/02/05