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

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

[elpa] master 6090eb3 17/79: Pass quote test with recursive colorizer.


From: Jackson Ray Hamilton
Subject: [elpa] master 6090eb3 17/79: Pass quote test with recursive colorizer.
Date: Sun, 14 Jun 2015 00:05:20 +0000

branch: master
commit 6090eb3246079470ad7da359ecf9660fccd806c1
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>

    Pass quote test with recursive colorizer.
---
 context-coloring.el           |   87 ++++++++++++++++++++++++++++++++---------
 test/context-coloring-test.el |   14 +++---
 2 files changed, 75 insertions(+), 26 deletions(-)

diff --git a/context-coloring.el b/context-coloring.el
index 8972da9..5b5fb08 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -403,14 +403,16 @@ generated by `js2-mode'."
   "\\`[^&:]")
 
 (defconst context-coloring-ignored-word-regexp
-  (concat "\\`[-+]?[0-9]\\|" (context-coloring-exact-or-regexp
-                              '("t" "nil" "." "?"))))
+  (concat "\\`[&:-+]?[0-9]\\|" (context-coloring-exact-or-regexp
+                                '("t" "nil" "." "?"))))
 
 (defconst context-coloring-WORD-CODE 2)
 (defconst context-coloring-SYMBOL-CODE 3)
 (defconst context-coloring-OPEN-PARENTHESIS-CODE 4)
 (defconst context-coloring-CLOSE-PARENTHESIS-CODE 5)
+(defconst context-coloring-EXPRESSION-PREFIX-CODE 6)
 
+(defconst context-coloring-APOSTROPHE-CHAR (string-to-char "'"))
 (defconst context-coloring-OPEN-PARENTHESIS-CHAR (string-to-char "("))
 (defconst context-coloring-COMMA-CHAR (string-to-char ","))
 (defconst context-coloring-BACKTICK-CHAR (string-to-char "`"))
@@ -565,7 +567,7 @@ provide visually \"instant\" updates at 60 frames per 
second.")
 (defun context-coloring-elisp-colorize-lambda ()
   (context-coloring-elisp-colorize-defun t))
 
-(defun context-coloring-elisp-colorize-sexp ()
+(defun context-coloring-elisp-colorize-parenthesized-sexp ()
   (let ((start (point))
         end
         syntax
@@ -610,31 +612,78 @@ provide visually \"instant\" updates at 60 frames per 
second.")
       (goto-char start)
       (forward-sexp)))))
 
+(defun context-coloring-elisp-colorize-symbol ()
+  (let (symbol-pos
+        symbol-end
+        symbol-string)
+    (setq symbol-pos (point))
+    (forward-sexp)
+    (setq symbol-end (point))
+    (setq symbol-string (buffer-substring-no-properties
+                         symbol-pos
+                         symbol-end))
+    (cond
+     ((string-match-p context-coloring-ignored-word-regexp symbol-string))
+     (t
+      (context-coloring-colorize-region
+       symbol-pos
+       symbol-end
+       (context-coloring-elisp-get-variable-level
+        (buffer-substring-no-properties
+         symbol-pos
+         symbol-end)))))))
+
+(defun context-coloring-elisp-colorize-expression-prefix ()
+  (let (start
+        end
+        char)
+    (setq char (char-after))
+    (cond
+     ((= char context-coloring-APOSTROPHE-CHAR)
+      (forward-sexp))
+     ((= char context-coloring-BACKTICK-CHAR)
+      (setq start (point))
+      (forward-sexp)
+      (setq end (point))
+      (goto-char start)
+      (while (> end (progn (forward-char)
+                           (point)))
+        (setq char (char-after))
+        (when (= char context-coloring-COMMA-CHAR)
+          (forward-char)
+          (skip-syntax-forward " ")
+          (context-coloring-elisp-colorize-sexp)))))))
+
+(defun context-coloring-elisp-colorize-sexp ()
+  (let (syntax
+        syntax-code)
+    (setq syntax (syntax-after (point)))
+    (setq syntax-code (syntax-class syntax))
+    (cond
+     ((= syntax-code context-coloring-OPEN-PARENTHESIS-CODE)
+      (context-coloring-elisp-colorize-parenthesized-sexp))
+     ((or (= syntax-code context-coloring-WORD-CODE)
+          (= syntax-code context-coloring-SYMBOL-CODE))
+      (context-coloring-elisp-colorize-symbol))
+     ((= syntax-code context-coloring-EXPRESSION-PREFIX-CODE)
+      (context-coloring-elisp-colorize-expression-prefix))
+     (t
+      (forward-char)))))
+
 (defun context-coloring-elisp-colorize-region (start end)
   (let (syntax
-        syntax-code
-        word-n-pos
-        word-n-end)
+        syntax-code)
     (goto-char start)
     (while (> end (progn (skip-syntax-forward "^()w_'" end)
                          (point)))
       (setq syntax (syntax-after (point)))
       (setq syntax-code (syntax-class syntax))
       (cond
-       ((= syntax-code context-coloring-OPEN-PARENTHESIS-CODE)
+       ((or (= syntax-code context-coloring-OPEN-PARENTHESIS-CODE)
+            (= syntax-code context-coloring-WORD-CODE)
+            (= syntax-code context-coloring-SYMBOL-CODE)
+            (= syntax-code context-coloring-EXPRESSION-PREFIX-CODE))
         (context-coloring-elisp-colorize-sexp))
-       ((or (= syntax-code context-coloring-WORD-CODE)
-            (= syntax-code context-coloring-SYMBOL-CODE))
-        (setq word-n-pos (point))
-        (forward-sexp)
-        (setq word-n-end (point))
-        (context-coloring-colorize-region
-         word-n-pos
-         word-n-end
-         (context-coloring-elisp-get-variable-level
-          (buffer-substring-no-properties
-           word-n-pos
-           word-n-end))))
        (t
         (forward-char))))))
 
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
index 4b8a939..2d8cfc9 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -1093,13 +1093,13 @@ ssssssssssss0"))
            11111111 11 2222222 2222
                          222 22 12 2221 111 0 00")))
 
-;; (context-coloring-test-deftest-emacs-lisp quote
-;;   (lambda ()
-;;     (context-coloring-test-assert-coloring "
-;; (xxxxx x (x)
-;;   (xx (xx x 111
-;;       111111 1 111 111
-;;       111111 1 1111111111 11 111 1 111 1 00001 10000 11 00001 1 
100001111")))
+(context-coloring-test-deftest-emacs-lisp quote
+  (lambda ()
+    (context-coloring-test-assert-coloring "
+(xxxxx x (x)
+  (xx (xx x 111
+      111111 1 111 111
+      111111 1 1111111111 11 111 1 111 1 00001 10000 11 00001 1 100001111")))
 
 ;; (context-coloring-test-deftest-emacs-lisp comment
 ;;   (lambda ()



reply via email to

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