emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 32fa415 226/271: Use `font-lock' for comments and strings.


From: Jackson Ray Hamilton
Subject: [elpa] master 32fa415 226/271: Use `font-lock' for comments and strings.
Date: Thu, 05 Feb 2015 18:31:28 +0000

branch: master
commit 32fa415677609f332812763baf5f21ff7adeb1bc
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>

    Use `font-lock' for comments and strings.
---
 context-coloring.el               |   22 ++++++++++++----------
 languages/javascript/scopifier.js |   12 ------------
 test/context-coloring-test.el     |    6 ++++++
 3 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/context-coloring.el b/context-coloring.el
index 88660e0..cc9f909 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -51,6 +51,10 @@ Increase this if your machine is high-performing. Decrease 
it if it ain't.
 Supported modes: `js-mode', `js3-mode'"
   :group 'context-coloring)
 
+(defcustom context-coloring-comments-and-strings t
+  "If non-nil, also color comments and strings using `font-lock'."
+  :group 'context-coloring)
+
 (defcustom context-coloring-js-block-scopes nil
   "If non-nil, also color block scopes in the scope hierarchy in JavaScript.
 
@@ -97,7 +101,6 @@ used.")
        ,doc
        :group 'context-coloring)))
 
-(context-coloring-defface -1 "white"   "#7f7f7f" "#7f7f7f")
 (context-coloring-defface 0  "white"   "#000000" "#ffffff")
 (context-coloring-defface 1  "yellow"  "#007f80" "#ffff80")
 (context-coloring-defface 2  "green"   "#001580" "#cdfacd")
@@ -139,9 +142,6 @@ Determines level at which to cycle through faces again."
   (dolist (pair pairs)
     (let ((level (car pair))
           (color (cdr pair)))
-      (cond
-       ((eq level 'comment)
-        (setq level -1)))
       (set-face-foreground (context-coloring-face-symbol level) color))))
 
 (defsubst context-coloring-level-face (level)
@@ -159,6 +159,10 @@ END (exclusive) with the face corresponding to LEVEL."
    end
    `(face ,(context-coloring-level-face level))))
 
+(defsubst context-coloring-maybe-colorize-comments-and-strings ()
+  (when context-coloring-comments-and-strings
+    (font-lock-fontify-syntactically-region (point-min) (point-max))))
+
 
 ;;; js2-mode colorization
 
@@ -216,10 +220,6 @@ generated by js2-mode."
      (lambda (node end-p)
        (when (null end-p)
          (cond
-          ((js2-comment-node-p node)
-           (context-coloring-js2-colorize-node
-            node
-            -1))
           ((js2-scope-p node)
            (context-coloring-js2-colorize-node
             node
@@ -238,7 +238,8 @@ generated by js2-mode."
                 node
                 (context-coloring-js2-scope-level defining-scope))))))
          ;; The `t' indicates to search children.
-         t)))))
+         t)))
+    (context-coloring-maybe-colorize-comments-and-strings)))
 
 
 ;;; Shell command scopification / colorization
@@ -256,7 +257,8 @@ level. The vector is flat, with a new token occurring after 
every
          (elt tokens i)
          (elt tokens (+ i 1))
          (elt tokens (+ i 2)))
-        (setq i (+ i 3))))))
+        (setq i (+ i 3))))
+    (context-coloring-maybe-colorize-comments-and-strings)))
 
 (defun context-coloring-parse-array (input)
   "Specialized JSON parser for a flat array of numbers."
diff --git a/languages/javascript/scopifier.js 
b/languages/javascript/scopifier.js
index 6b46392..0171ab2 100644
--- a/languages/javascript/scopifier.js
+++ b/languages/javascript/scopifier.js
@@ -11,7 +11,6 @@ function scopifier(code) {
 
     var analyzedScopes,
         ast,
-        comment,
         definition,
         definitionsCount,
         definitionsIndex,
@@ -30,7 +29,6 @@ function scopifier(code) {
     // Gracefully handle parse errors by doing nothing.
     try {
         ast = esprima.parse(code, {
-            comment: true,
             range: true
         });
         analyzedScopes = escope.analyze(ast).scopes;
@@ -109,16 +107,6 @@ function scopifier(code) {
         }
     }
 
-    for (i = 0; i < ast.comments.length; i += 1) {
-        comment = ast.comments[i];
-        range = comment.range;
-        tokens.push(
-            range[0] + 1,
-            range[1] + 1,
-            -1
-        );
-    }
-
     return scopes.concat(tokens);
 }
 
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
index 52a93fb..4f72ff2 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -14,7 +14,11 @@
 (defun context-coloring-test-read-file (path)
   (get-string-from-file (context-coloring-test-resolve-path path)))
 
+(defun context-coloring-test-setup ()
+  (setq context-coloring-comments-and-strings nil))
+
 (defun context-coloring-test-cleanup ()
+  (setq context-coloring-comments-and-strings t)
   (setq context-coloring-after-colorize-hook nil)
   (setq context-coloring-js-block-scopes nil))
 
@@ -24,6 +28,7 @@ FIXTURE."
   `(with-temp-buffer
      (unwind-protect
          (progn
+           (context-coloring-test-setup)
            (insert (context-coloring-test-read-file ,fixture))
            ,@body)
        (context-coloring-test-cleanup))))
@@ -49,6 +54,7 @@ FIXTURE. A teardown callback is passed to CALLBACK for it to
 invoke when it is done."
   (context-coloring-test-with-temp-buffer-async
    (lambda (done-with-temp-buffer)
+     (context-coloring-test-setup)
      (insert (context-coloring-test-read-file fixture))
      (funcall
       callback



reply via email to

[Prev in Thread] Current Thread [Next in Thread]