From: Jackson Hamilton Date: Sun, 18 Oct 2015 10:56:09 +0000 (-0700) Subject: Use more agnostic names. X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/6531b86bd03b34b1944e1fe8714dd26698277e02 Use more agnostic names. --- diff --git a/context-coloring.el b/context-coloring.el index 1f617b938..ef908fd4d 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -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 diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 6cf78e430..f643e914c 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -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")