[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 7c16f46 05/16: Add initial level setting.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 7c16f46 05/16: Add initial level setting. |
Date: |
Sun, 18 Oct 2015 11:21:39 +0000 |
branch: master
commit 7c16f46c107512e194f5aea6b7170562405887dc
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Add initial level setting.
---
context-coloring.el | 24 +++++++++++++++++++-----
test/context-coloring-test.el | 10 ++++++++++
test/fixtures/initial-level.js | 1 +
3 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index b7d5762..a29c7eb 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -285,6 +285,17 @@ MIN defaults to beginning of buffer. MAX defaults to end."
(when (eq major-mode 'emacs-lisp-mode)
(font-lock-fontify-keywords-region min max))))))
+(defcustom context-coloring-initial-level 0
+ "Scope level at which to start coloring.
+
+If top-level variables and functions do not become global, but
+are scoped to a file (as in Node.js), set this to `1'."
+ :type 'integer
+ :safe #'integerp
+ :group 'context-coloring)
+
+(make-variable-buffer-local 'context-coloring-initial-level)
+
;;; js2-mode colorization
@@ -304,11 +315,11 @@ this for ES6 code; disable it elsewhere."
'context-coloring-javascript-block-scopes
"7.0.0")
-(defsubst context-coloring-js2-scope-level (scope)
- "Return the level of SCOPE."
+(defsubst context-coloring-js2-scope-level (scope initial)
+ "Return the level of SCOPE, starting from INITIAL."
(cond ((gethash scope context-coloring-js2-scope-level-hash-table))
(t
- (let ((level 0)
+ (let ((level initial)
(current-scope scope)
enclosing-scope)
(while (and current-scope
@@ -365,7 +376,7 @@ this for ES6 code; disable it elsewhere."
((js2-scope-p node)
(context-coloring-js2-colorize-node
node
- (context-coloring-js2-scope-level node)))
+ (context-coloring-js2-scope-level node
context-coloring-initial-level)))
((context-coloring-js2-local-name-node-p node)
(let* ((enclosing-scope (js2-node-get-enclosing-scope node))
(defining-scope (js2-get-defining-scope
@@ -378,7 +389,10 @@ this for ES6 code; disable it elsewhere."
(when (not (eq defining-scope enclosing-scope))
(context-coloring-js2-colorize-node
node
- (context-coloring-js2-scope-level defining-scope))))))
+ ;; Use `0' as an initial level so global variables are always
at
+ ;; the highest level (even if `context-coloring-initial-level'
+ ;; specifies an initial level for the rest of the code).
+ (context-coloring-js2-scope-level defining-scope 0))))))
;; The `t' indicates to search children.
t)))
(context-coloring-colorize-comments-and-strings)))
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
index 32e4d80..e267941 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -602,6 +602,16 @@ ssssssssssss0"))
;; As long as `add-text-properties' doesn't signal an error, this test
passes.
(lambda ()))
+(context-coloring-test-deftest-javascript initial-level
+ (lambda ()
+ (context-coloring-test-assert-coloring "
+111 1 1 00000001xxx11"))
+ :fixture "initial-level.js"
+ :before (lambda ()
+ (setq context-coloring-initial-level 1))
+ :after (lambda ()
+ (setq context-coloring-initial-level 0)))
+
(context-coloring-test-deftest-emacs-lisp defun
(lambda ()
(context-coloring-test-assert-coloring "
diff --git a/test/fixtures/initial-level.js b/test/fixtures/initial-level.js
new file mode 100644
index 0000000..119773e
--- /dev/null
+++ b/test/fixtures/initial-level.js
@@ -0,0 +1 @@
+var a = require('a');
- [elpa] master updated (9319a95 -> 6934762), Jackson Ray Hamilton, 2015/10/18
- [elpa] master 53279b1 01/16: Fix tests on Windows., Jackson Ray Hamilton, 2015/10/18
- [elpa] master 85397da 02/16: Add more sophisticated block scope test., Jackson Ray Hamilton, 2015/10/18
- [elpa] master 683a522 04/16: Suggest eval-expression-minibuffer-setup-hook., Jackson Ray Hamilton, 2015/10/18
- [elpa] master df914b8 03/16: Bump minimum js2-mode version., Jackson Ray Hamilton, 2015/10/18
- [elpa] master 7c16f46 05/16: Add initial level setting.,
Jackson Ray Hamilton <=
- [elpa] master fa99117 06/16: Add defcustom types., Jackson Ray Hamilton, 2015/10/18
- [elpa] master 614de4c 07/16: Don't make the initial level buffer-local., Jackson Ray Hamilton, 2015/10/18
- [elpa] master a193f4e 08/16: Refactor position level assertion., Jackson Ray Hamilton, 2015/10/18
- [elpa] master 6fe9e58 09/16: Add Node.js detection., Jackson Ray Hamilton, 2015/10/18
- [elpa] master 6531b86 11/16: Use more agnostic names., Jackson Ray Hamilton, 2015/10/18
- [elpa] master 2c62db1 10/16: Ensure Node.js variable is global., Jackson Ray Hamilton, 2015/10/18
- [elpa] master 6ac3b43 12/16: Merge branch 'detect-node', Jackson Ray Hamilton, 2015/10/18
- [elpa] master ff9643c 14/16: Update Zenburn paragraph., Jackson Ray Hamilton, 2015/10/18
- [elpa] master 765d4c4 13/16: Document new scope detection., Jackson Ray Hamilton, 2015/10/18
- [elpa] master 0c3a48f 15/16: Version 7.1.0., Jackson Ray Hamilton, 2015/10/18