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

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

[elpa] master 2efebc8 10/28: Don't colorize if there are parse errors.


From: Jackson Ray Hamilton
Subject: [elpa] master 2efebc8 10/28: Don't colorize if there are parse errors.
Date: Tue, 05 May 2015 11:10:18 +0000

branch: master
commit 2efebc8963a71e0455fffacb0c0f3beba3909689
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>

    Don't colorize if there are parse errors.
---
 context-coloring.el |   58 ++++++++++++++++++++++++++------------------------
 1 files changed, 30 insertions(+), 28 deletions(-)

diff --git a/context-coloring.el b/context-coloring.el
index 853a8e8..c7caa86 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -248,34 +248,36 @@ variable."
 (defun context-coloring-js2-colorize ()
   "Color the current buffer using the abstract syntax tree
 generated by `js2-mode'."
-  ;; Reset the hash table; the old one could be obsolete.
-  (setq context-coloring-js2-scope-level-hash-table (make-hash-table :test 
'eq))
-  (with-silent-modifications
-    (js2-visit-ast
-     js2-mode-ast
-     (lambda (node end-p)
-       (when (null end-p)
-         (cond
-          ((js2-scope-p node)
-           (context-coloring-js2-colorize-node
-            node
-            (context-coloring-js2-scope-level node)))
-          ((context-coloring-js2-local-name-node-p node)
-           (let* ((enclosing-scope (js2-node-get-enclosing-scope node))
-                  (defining-scope (js2-get-defining-scope
-                                   enclosing-scope
-                                   (js2-name-node-name node))))
-             ;; The tree seems to be walked lexically, so an entire scope will
-             ;; be colored, including its name nodes, before they are reached.
-             ;; Coloring the nodes defined in that scope would be redundant, so
-             ;; don't do it.
-             (when (not (eq defining-scope enclosing-scope))
-               (context-coloring-js2-colorize-node
-                node
-                (context-coloring-js2-scope-level defining-scope))))))
-         ;; The `t' indicates to search children.
-         t)))
-    (context-coloring-maybe-colorize-comments-and-strings)))
+  ;; Don't bother trying to color a mangled tree.
+  (when (= 0 (length js2-parsed-errors))
+    ;; Reset the hash table; the old one could be obsolete.
+    (setq context-coloring-js2-scope-level-hash-table (make-hash-table :test 
'eq))
+    (with-silent-modifications
+      (js2-visit-ast
+       js2-mode-ast
+       (lambda (node end-p)
+         (when (null end-p)
+           (cond
+            ((js2-scope-p node)
+             (context-coloring-js2-colorize-node
+              node
+              (context-coloring-js2-scope-level node)))
+            ((context-coloring-js2-local-name-node-p node)
+             (let* ((enclosing-scope (js2-node-get-enclosing-scope node))
+                    (defining-scope (js2-get-defining-scope
+                                     enclosing-scope
+                                     (js2-name-node-name node))))
+               ;; The tree seems to be walked lexically, so an entire scope 
will
+               ;; be colored, including its name nodes, before they are 
reached.
+               ;; Coloring the nodes defined in that scope would be redundant, 
so
+               ;; don't do it.
+               (when (not (eq defining-scope enclosing-scope))
+                 (context-coloring-js2-colorize-node
+                  node
+                  (context-coloring-js2-scope-level defining-scope))))))
+           ;; The `t' indicates to search children.
+           t)))
+      (context-coloring-maybe-colorize-comments-and-strings))))
 
 
 ;;; Shell command scopification / colorization



reply via email to

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