[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 76122df 144/271: Write js2 scopifier.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 76122df 144/271: Write js2 scopifier. |
Date: |
Thu, 05 Feb 2015 18:30:38 +0000 |
branch: master
commit 76122dfcb343a6160383756ebb7482bf3de1c4bb
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Write js2 scopifier.
---
context-coloring.el | 60 +++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 49 insertions(+), 11 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index aec467d..3f8b978 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -179,10 +179,48 @@ imply that it should be colorized again.")
;;; js2-mode Scopification
;; Potentially useful functions: js2-visit-ast js2-node-get-enclosing-scope
-;; js2-get-defining-scope js2-visit-ast-root
-
-(defun context-coloring-js2-mode-scopifier ()
- (vector))
+;; js2-get-defining-scope js2-visit-ast-root js2-node-root
+
+(defsubst context-coloring-js2-scope-level (scope)
+ (let ((level 0))
+ (while (and (not (null (js2-node-parent scope)))
+ (not (null (setq scope (js2-node-get-enclosing-scope scope)))))
+ (setq level (+ level 1)))
+ level))
+
+(defsubst context-coloring-js2-scope-to-token (scope)
+ (let ((level (context-coloring-js2-scope-level scope))
+ (start (js2-node-abs-pos scope)))
+ (let ((end (+ start (js2-scope-len scope))))
+ `(,start ,end ,level))))
+
+(defsubst context-coloring-js2-name-get-defining-scope (name)
+ (js2-get-defining-scope
+ (js2-node-get-enclosing-scope name)
+ (js2-name-node-name name)))
+
+(defsubst context-coloring-js2-name-to-token (name)
+ (let ((level (context-coloring-js2-scope-level
+ (context-coloring-js2-name-get-defining-scope name)))
+ (start (js2-node-abs-pos name)))
+ (let ((end (+ start (js2-name-node-len name))))
+ `(,start ,end ,level))))
+
+(defun context-coloring-js2-scopifier ()
+ (let ((tokens '()))
+ (js2-visit-ast
+ js2-mode-ast
+ (lambda (node end-p)
+ (when (null end-p)
+ (when (js2-scope-p node)
+ (setq tokens (nconc tokens (context-coloring-js2-scope-to-token
node))))
+ (when (js2-name-node-p node)
+ (let ((scope (js2-node-get-enclosing-scope node))
+ (name (js2-name-node-name node)))
+ (setq tokens (nconc tokens (context-coloring-js2-name-to-token
node)))))
+ t) ; Always search children.
+ ))
+ (vconcat tokens)))
;;; Scopification
@@ -192,19 +230,19 @@ imply that it should be colorized again.")
:command ,(expand-file-name
"./languages/javascript/bin/scopifier"
context-coloring-path)))
- (js2-mode-scopifier `(:type elisp
- :scopifier context-coloring-js2-mode-scopifier)))
+ (js2-scopifier `(:type elisp
+ :scopifier context-coloring-js2-scopifier)))
(defcustom context-coloring-scopifier-plist
`(js-mode ,javascript-scopifier
- js2-mode ,js2-mode-scopifier
+ js2-mode ,js2-scopifier
js3-mode ,javascript-scopifier)
"Property list mapping major modes to scopification programs."))
(defun context-coloring-apply-tokens (tokens)
- "Processes TOKENS to apply context-based coloring to the
-current buffer. Tokens are 3 integers: start, end, level. The
-array is flat, with a new token occurring after every 3rd
-number."
+ "Processes a vector of TOKENS to apply context-based coloring
+to the current buffer. Tokens are 3 integers: start, end,
+level. The vector is flat, with a new token occurring after every
+3rd element."
(with-silent-modifications
;; Reset in case there should be uncolored areas.
(remove-text-properties (point-min) (point-max) `(face nil rear-nonsticky
nil))
- [elpa] master 3f1bae9 142/271: Make js2-mode read-only., (continued)
- [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, 2015/02/05
- [elpa] master 76122df 144/271: Write js2 scopifier.,
Jackson Ray Hamilton <=
- [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
- [elpa] master 1d9cf42 164/271: Refactor tests., Jackson Ray Hamilton, 2015/02/05