]> code.delx.au - gnu-emacs-elpa/commitdiff
Use more agnostic names.
authorJackson Hamilton <jackson@jacksonrayhamilton.com>
Sun, 18 Oct 2015 10:56:09 +0000 (03:56 -0700)
committerJackson Hamilton <jackson@jacksonrayhamilton.com>
Sun, 18 Oct 2015 10:56:09 +0000 (03:56 -0700)
context-coloring.el
test/context-coloring-test.el

index 1f617b93800e24dc92743dec19bef0e6ef1610c7..ef908fd4da67df57422f917451ac03dcd36e8f3f 100644 (file)
@@ -414,8 +414,10 @@ this for ES6 code; disable it elsewhere."
    "\\)")
   "Match a comment body hinting at a Node.js program.")
 
-(defun context-coloring-node-program-p ()
-  "Guess whether the current file is a Node.js program."
+;; TODO: Add ES6 module detection.
+(defun context-coloring-js2-top-level-local-p ()
+  "Guess whether top-level variables are local.
+For instance, the current file could be a Node.js program."
   (or
    ;; A shebang is a pretty obvious giveaway.
    (string-equal
@@ -472,17 +474,17 @@ this for ES6 code; disable it elsewhere."
        ;; Default to returning nil from the catch body.
        nil))))
 
-(defcustom context-coloring-detect-node t
-  "If non-nil, use file-level scope for variables in Node.js."
+(defcustom context-coloring-javascript-detect-top-level-scope t
+  "If non-nil, detect when to use file-level scope."
   :type 'boolean
   :group 'context-coloring)
 
 (defun context-coloring-js2-colorize ()
   "Color the buffer using the `js2-mode'."
   (cond
-   ;; Increase the initial level if we can detect Node.js.
-   ((and context-coloring-detect-node
-         (context-coloring-node-program-p))
+   ;; Increase the initial level if we should.
+   ((and context-coloring-javascript-detect-top-level-scope
+         (context-coloring-js2-top-level-local-p))
     (let ((context-coloring-initial-level 1))
       (context-coloring-js2-colorize-ast)))
    (t
index 6cf78e4300adbba6823596d2b716b00a3ce281b1..f643e914c508b5a9b917c235ac8345ef9f21d95d 100644 (file)
@@ -623,7 +623,7 @@ ssssssssssss0"))
   :after (lambda ()
            (setq context-coloring-initial-level 0)))
 
-(defun context-coloring-test-setup-detect-node (string)
+(defun context-coloring-test-setup-top-level-scope (string)
   "Make STRING the first line and colorize again."
   (goto-char (point-min))
   (kill-whole-line 0)
@@ -631,7 +631,7 @@ ssssssssssss0"))
   ;; Reparsing triggers recoloring.
   (js2-reparse))
 
-(context-coloring-test-deftest-javascript detect-node
+(context-coloring-test-deftest-javascript top-level-scope
   (lambda ()
     (let ((positive-indicators
            (list "#!/usr/bin/env node"
@@ -648,10 +648,10 @@ ssssssssssss0"))
                  "exports"
                  "var require; require('a')")))
       (dolist (indicator positive-indicators)
-        (context-coloring-test-setup-detect-node indicator)
+        (context-coloring-test-setup-top-level-scope indicator)
         (context-coloring-test-assert-javascript-elevated-level))
       (dolist (indicator negative-indicators)
-        (context-coloring-test-setup-detect-node indicator)
+        (context-coloring-test-setup-top-level-scope indicator)
         (context-coloring-test-assert-javascript-global-level))))
   :fixture "initial-level.js")