branch: master
commit 5857bc81ea0c7644db489aa714717f4024473a69
Author: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com>
Commit: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com>

    Refactor comments and strings coloring.
---
 context-coloring.el |   59 ++++++++++++++++++++++++++------------------------
 1 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/context-coloring.el b/context-coloring.el
index afc05e4..b14c63e 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -285,8 +285,7 @@ generated by `js2-mode'."
 them along the way."
   (let ((start (point)))
     (context-coloring-forward-sws)
-    (context-coloring-elisp-colorize-comments-and-strings-in-region
-     start (point))))
+    (context-coloring-maybe-colorize-comments-and-strings start (point))))
 
 (defsubst context-coloring-elisp-forward-sexp ()
   "Like `forward-sexp', but colorize comments and strings along
@@ -438,18 +437,18 @@ provide visually \"instant\" updates at 60 frames per 
second.")
       (cond
        ((= syntax-code context-coloring-OPEN-PARENTHESIS-CODE)
         (forward-char)
-        (context-coloring-forward-sws)
+        (context-coloring-elisp-forward-sws)
         (setq syntax-code (context-coloring-get-syntax-code))
         (when (or (= syntax-code context-coloring-WORD-CODE)
                   (= syntax-code context-coloring-SYMBOL-CODE))
           (context-coloring-elisp-parse-arg
            (lambda (var)
              (push var varlist)))
-          (context-coloring-forward-sws)
+          (context-coloring-elisp-forward-sws)
           (setq syntax-code (context-coloring-get-syntax-code))
           (when (/= syntax-code context-coloring-CLOSE-PARENTHESIS-CODE)
             (context-coloring-elisp-colorize-sexp)))
-        (context-coloring-forward-sws)
+        (context-coloring-elisp-forward-sws)
         ;; Skip past the closing parenthesis.
         (forward-char))
        ((or (= syntax-code context-coloring-WORD-CODE)
@@ -459,7 +458,7 @@ provide visually \"instant\" updates at 60 frames per 
second.")
            (push var varlist)))))
       (when (eq type 'let*)
         (context-coloring-elisp-add-variable (pop varlist)))
-      (context-coloring-forward-sws))
+      (context-coloring-elisp-forward-sws))
     (when (eq type 'let)
       (while varlist
         (context-coloring-elisp-add-variable (pop varlist))))
@@ -479,8 +478,8 @@ provide visually \"instant\" updates at 60 frames per 
second.")
          (lambda (arg)
            (context-coloring-elisp-add-variable arg))))
        (t
-        (forward-sexp)))
-      (context-coloring-forward-sws))
+        (context-coloring-elisp-forward-sexp)))
+      (context-coloring-elisp-forward-sws))
     ;; Exit.
     (forward-char)))
 
@@ -501,10 +500,12 @@ provide visually \"instant\" updates at 60 frames per 
second.")
      end
      (context-coloring-elisp-current-scope-level))
     (goto-char start)
+    ;; Enter.
+    (forward-char)
+    (context-coloring-elisp-forward-sws)
     ;; Skip past the "defun".
-    (skip-syntax-forward "^w_")
     (forward-sexp)
-    (context-coloring-forward-sws)
+    (context-coloring-elisp-forward-sws)
     (setq stop nil)
     (unless anonymous-p
       ;; Check for the defun's name.
@@ -517,14 +518,14 @@ provide visually \"instant\" updates at 60 frames per 
second.")
         (forward-sexp)
         (setq defun-name-end (point))
         (context-coloring-colorize-region defun-name-pos defun-name-end 0)
-        (context-coloring-forward-sws))
+        (context-coloring-elisp-forward-sws))
        (t
         (setq stop t))))
     (cond
      (stop
       ;; Skip it.
       (goto-char start)
-      (forward-sexp))
+      (context-coloring-elisp-forward-sexp))
      (t
       (setq syntax-code (context-coloring-get-syntax-code))
       (cond
@@ -541,9 +542,8 @@ provide visually \"instant\" updates at 60 frames per 
second.")
        (t
         ;; Skip it.
         (goto-char start)
-        (forward-sexp)))))
-    (context-coloring-elisp-pop-scope)
-    (context-coloring-elisp-colorize-comments-and-strings-in-region start 
end)))
+        (context-coloring-elisp-forward-sexp)))))
+    (context-coloring-elisp-pop-scope)))
 
 (defun context-coloring-elisp-colorize-defun ()
   (context-coloring-elisp-colorize-defun-like))
@@ -563,7 +563,7 @@ provide visually \"instant\" updates at 60 frames per 
second.")
     (forward-char)
     (context-coloring-elisp-forward-sws)
     ;; Skip past the "cond".
-    (skip-syntax-forward "^w_")
+    (forward-sexp)
     (context-coloring-elisp-forward-sws)
     (while (/= (setq syntax-code (context-coloring-get-syntax-code))
                context-coloring-CLOSE-PARENTHESIS-CODE)
@@ -577,7 +577,7 @@ provide visually \"instant\" updates at 60 frames per 
second.")
           ;; Exit.
           (forward-char)))
        (t
-        (forward-sexp)))
+        (context-coloring-elisp-forward-sexp)))
       (context-coloring-elisp-forward-sws))
     ;; Exit.
     (forward-char)))
@@ -653,6 +653,8 @@ provide visually \"instant\" updates at 60 frames per 
second.")
                      (point)))
          (syntax-code (progn (goto-char start)
                              (forward-char)
+                             ;; Coloring is unnecessary here, it'll happen
+                             ;; presently.
                              (context-coloring-forward-sws)
                              (context-coloring-get-syntax-code))))
     ;; Figure out if the sexp is a special form.
@@ -719,14 +721,16 @@ provide visually \"instant\" updates at 60 frames per 
second.")
 (defun context-coloring-elisp-colorize-expression-prefix ()
   (context-coloring-elisp-increment-sexp-count)
   (let ((char (char-after))
-        (start (point))
-        (end (progn (forward-sexp)
-                    (point))))
+        start
+        end)
     (cond
      ((or (= char context-coloring-APOSTROPHE-CHAR)
           (= char context-coloring-OCTOTHORPE-CHAR))
-      (context-coloring-elisp-colorize-comments-and-strings-in-region start 
end))
+      (context-coloring-elisp-forward-sexp))
      ((= char context-coloring-BACKTICK-CHAR)
+      (setq start (point))
+      (setq end (progn (forward-sexp)
+                       (point)))
       (goto-char start)
       (while (> end (progn (forward-char)
                            (point)))
@@ -736,17 +740,16 @@ provide visually \"instant\" updates at 60 frames per 
second.")
           (when (= (char-after) context-coloring-AT-CHAR)
             ;; If we don't do this "@" could be interpreted as a symbol.
             (forward-char))
-          (context-coloring-forward-sws)
+          (context-coloring-elisp-forward-sws)
           (context-coloring-elisp-colorize-sexp)))
-      (context-coloring-elisp-colorize-comments-and-strings-in-region start 
end)))))
+      ;; We could probably do this as part of the above loop but it'd be
+      ;; repetitive.
+      (context-coloring-elisp-colorize-comments-and-strings-in-region
+       start end)))))
 
 (defun context-coloring-elisp-colorize-comment ()
   (context-coloring-elisp-increment-sexp-count)
-  (let ((start (point)))
-    (context-coloring-forward-sws)
-    (context-coloring-maybe-colorize-comments-and-strings
-     start
-     (point))))
+  (context-coloring-elisp-forward-sws))
 
 (defun context-coloring-elisp-colorize-string ()
   (context-coloring-elisp-increment-sexp-count)

Reply via email to