[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 9f87a03 148/271: Actually colorize complex files.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 9f87a03 148/271: Actually colorize complex files. |
Date: |
Thu, 05 Feb 2015 18:30:39 +0000 |
branch: master
commit 9f87a038747ebe73b12ef7285ff240b8ce80dc51
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Actually colorize complex files.
---
context-coloring.el | 64 +++++++++++++++++++++++++---------------
test/context-coloring-test.el | 31 ++++++++++++++++++--
test/fixtures/global.js | 1 +
3 files changed, 69 insertions(+), 27 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index 2549562..8891c21 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -197,34 +197,48 @@ For example: \"context-coloring-level-1-face\"."
(defsubst context-coloring-js2-scope-level (scope)
"Gets the level of SCOPE."
(let ((level 0))
- (while (and (not (null (js2-node-parent scope)))
+ (while (and (not (null scope))
+ (not (null (js2-node-parent scope)))
(not (null (setq scope (js2-node-get-enclosing-scope scope)))))
(setq level (+ level 1)))
level))
+;; Obtained from js2-refactor.el/js2r-vars.el
+(defun context-coloring-js2-local-name-node-p (node)
+ (and (js2-name-node-p node)
+ (not (save-excursion ; not key in object literal { key: value }
+ (goto-char (+ (js2-node-abs-pos node) (js2-node-len node)))
+ (looking-at "[\n\t ]*:")))
+ (not (save-excursion ; not property lookup on object
+ (goto-char (js2-node-abs-pos node))
+ (looking-back "\\.[\n\t ]*")))))
+
(defun context-coloring-js2-colorize ()
- (js2-visit-ast
- js2-mode-ast
- (lambda (node end-p)
- (when (null end-p)
- (when (js2-scope-p node)
- (let ((start (js2-node-abs-pos node)))
- (context-coloring-colorize-region
- start
- (+ start (js2-scope-len node)) ; End
- (context-coloring-js2-scope-level node) ; Level
- )))
- (when (js2-name-node-p node)
- (let ((start (js2-node-abs-pos node)))
- (context-coloring-colorize-region
- start
- (+ start (js2-name-node-len node)) ; End
- (context-coloring-js2-scope-level ; Level
- (js2-get-defining-scope
- (js2-node-get-enclosing-scope node)
- (js2-name-node-name node))))))
- ;; The `t' indicates to search children.
- t))))
+ (with-silent-modifications
+ (context-coloring-uncolorize-buffer)
+ (js2-visit-ast
+ js2-mode-ast
+ (lambda (node end-p)
+ (when (null end-p)
+ (cond
+ ((js2-scope-p node)
+ (let ((start (js2-node-abs-pos node)))
+ (context-coloring-colorize-region
+ start
+ (+ start (js2-scope-len node)) ; End
+ (context-coloring-js2-scope-level node) ; Level
+ )))
+ ((context-coloring-js2-local-name-node-p node)
+ (let ((start (js2-node-abs-pos node)))
+ (context-coloring-colorize-region
+ start
+ (+ start (js2-name-node-len node)) ; End
+ (context-coloring-js2-scope-level ; Level
+ (js2-get-defining-scope
+ (js2-node-get-enclosing-scope node)
+ (js2-name-node-name node)))))))
+ ;; The `t' indicates to search children.
+ t)))))
;;; Shell command copification / colorization
@@ -398,7 +412,9 @@ colorizing would be redundant."
(jit-lock-mode nil)
;; Colorize once initially.
- (context-coloring-colorize)
+ ;; (let ((start-time (float-time)))
+ (context-coloring-colorize)
+ ;; (message "Elapsed time: %f" (- (float-time) start-time)))
;; Only recolor on change.
(add-hook 'after-change-functions 'context-coloring-change-function nil t)
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
index 7c8709f..814fd6d 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -19,6 +19,17 @@ FIXTURE."
(insert (context-coloring-test-read-file ,fixture))
,@body))
+(defmacro context-coloring-test-js2-with-fixture (fixture &rest body)
+ "Evaluate BODY in a temporary buffer with the relative
+FIXTURE."
+ `(context-coloring-test-with-fixture
+ ,fixture
+ (add-to-list 'load-path (context-coloring-test-resolve-path
"./fixtures/js2-mode"))
+ (require 'js2-mode)
+ (setq js2-mode-show-parse-errors nil)
+ (setq js2-mode-show-strict-warnings nil)
+ ,@body))
+
(defun context-coloring-test-region-level-p (start end level)
(let ((i 0)
(length (- end start)))
@@ -66,12 +77,26 @@ FIXTURE."
(context-coloring-test-function-scopes)))
(ert-deftest context-coloring-test-js2-mode-function-scopes ()
- (context-coloring-test-with-fixture
+ (context-coloring-test-js2-with-fixture
"./fixtures/function-scopes.js"
- (add-to-list 'load-path (context-coloring-test-resolve-path
"./fixtures/js2-mode"))
- (require 'js2-mode)
(js2-mode)
(context-coloring-mode)
(context-coloring-test-function-scopes)))
+(ert-deftest context-coloring-test-js2-mode-global ()
+ (context-coloring-test-js2-with-fixture
+ "./fixtures/global.js"
+ (js2-mode)
+ (context-coloring-mode)
+ ;; Don't error.
+ ))
+
+(ert-deftest context-coloring-test-js2-mode-complexity ()
+ (context-coloring-test-js2-with-fixture
+ "../benchmark/fixtures/mkdirp-0.5.0.js"
+ (js2-mode)
+ (context-coloring-mode)
+ ;; Don't error.
+ ))
+
(provide 'context-coloring-test)
diff --git a/test/fixtures/global.js b/test/fixtures/global.js
new file mode 100644
index 0000000..119773e
--- /dev/null
+++ b/test/fixtures/global.js
@@ -0,0 +1 @@
+var a = require('a');
- [elpa] master 4b2e1db 140/271: Documentation., (continued)
- [elpa] master 4b2e1db 140/271: Documentation., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 3f1bae9 142/271: Make js2-mode read-only., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 1ceb460 139/271: Documentation., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 1b7e0a5 122/271: Make context-coloring-face-count customizable. Add some dummy faces., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 459987e 131/271: Generalize for different major modes. Remove dirty benchmarking., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 2341708 132/271: Reorganize JavaScript files., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 4be9ec8 147/271: Documentation., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 16cee40 150/271: Pass test for block scopes., Jackson Ray Hamilton, 2015/02/05
- [elpa] master f7b5d33 143/271: Add skeletal support for js2-mode scopification., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 549e523 149/271: Add failing test for block scopes., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 9f87a03 148/271: Actually colorize complex files.,
Jackson Ray Hamilton <=
- [elpa] master 76122df 144/271: Write js2 scopifier., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 5fcd757 146/271: Refactor to use more resilient dispatch strategy., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 8982c75 127/271: Merge branch 'feature/tests' into develop, Jackson Ray Hamilton, 2015/02/05
- [elpa] master e06fbe9 158/271: Add comment support for js2-mode., Jackson Ray Hamilton, 2015/02/05
- [elpa] master a2b6a5a 112/271: Use defvar-local., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 6c8175e 153/271: Update compilation., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 4f57f0c 163/271: Improve global test., Jackson Ray Hamilton, 2015/02/05
- [elpa] master dc8e99c 130/271: Function name., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 2bb4d12 124/271: More cleanup., Jackson Ray Hamilton, 2015/02/05
- [elpa] master d301048 154/271: Update compilation again., Jackson Ray Hamilton, 2015/02/05