branch: master commit f1ed39f634a9c109e829ee79e9070026a6253050 Author: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com> Commit: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com>
Pass comment and string tests with recursive colorizer. --- context-coloring.el | 37 ++++++++++++++++++++++++++++++++++++- test/context-coloring-test.el | 30 +++++++++++++----------------- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 174edde..a3a1887 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -333,6 +333,10 @@ provide visually \"instant\" updates at 60 frames per second.") (defconst context-coloring-OPEN-PARENTHESIS-CODE 4) (defconst context-coloring-CLOSE-PARENTHESIS-CODE 5) (defconst context-coloring-EXPRESSION-PREFIX-CODE 6) +(defconst context-coloring-STRING-QUOTE-CODE 7) +(defconst context-coloring-ESCAPE-CODE 9) +(defconst context-coloring-COMMENT-START-CODE 11) +(defconst context-coloring-COMMENT-END-CODE 12) (defconst context-coloring-APOSTROPHE-CHAR (string-to-char "'")) (defconst context-coloring-OPEN-PARENTHESIS-CHAR (string-to-char "(")) @@ -632,10 +636,37 @@ provide visually \"instant\" updates at 60 frames per second.") (t (forward-char))))) +(defun context-coloring-elisp-colorize-comment () + (let ((start (point))) + (skip-syntax-forward "^>") + (context-coloring-maybe-colorize-comments-and-strings + start + (point)))) + +(defun context-coloring-elisp-colorize-string () + (let ((start (point)) + (syntax-code (context-coloring-get-syntax-code))) + ;; Move past the opening string delimiter. + (forward-char) + (while (progn + (skip-syntax-forward "^\\\"") + (cond + ((= syntax-code context-coloring-ESCAPE-CODE) + ;; If there was an escape char, keep going. + (forward-char 2) + t) + ((= syntax-code context-coloring-STRING-QUOTE-CODE) + ;; If the string ended, move outside it. + (forward-char) + nil)))) + (context-coloring-maybe-colorize-comments-and-strings + start + (point)))) + (defun context-coloring-elisp-colorize-region (start end) (let (syntax-code) (goto-char start) - (while (> end (progn (skip-syntax-forward "^()w_'" end) + (while (> end (progn (skip-syntax-forward "^()w_'<\"" end) (point))) (setq syntax-code (context-coloring-get-syntax-code)) (cond @@ -644,6 +675,10 @@ provide visually \"instant\" updates at 60 frames per second.") (= syntax-code context-coloring-SYMBOL-CODE) (= syntax-code context-coloring-EXPRESSION-PREFIX-CODE)) (context-coloring-elisp-colorize-sexp)) + ((= syntax-code context-coloring-COMMENT-START-CODE) + (context-coloring-elisp-colorize-comment)) + ((= syntax-code context-coloring-STRING-QUOTE-CODE) + (context-coloring-elisp-colorize-string)) (t (forward-char)))))) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index f1ed4d2..4d59054 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -1101,23 +1101,19 @@ ssssssssssss0")) 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 () -;; ;; Just check that the comment isn't parsed syntactically. -;; (context-coloring-test-assert-coloring " -;; (xxxxx x () -;; (xx (x xxxxx-xxxx xx) cccccccccc -;; 11 00000-0000 11))) cccccccccc")) -;; :before (lambda () -;; (setq context-coloring-syntactic-comments t))) +(context-coloring-test-deftest-emacs-lisp comment + (lambda () + ;; Just check that the comment isn't parsed syntactically. + (context-coloring-test-assert-coloring " +(xxxxx x () + (xx (x xxxxx-xxxx xx) cccccccccc + 11 00000-0000 11))) cccccccccc"))) -;; (context-coloring-test-deftest-emacs-lisp string -;; (lambda () -;; (context-coloring-test-assert-coloring " -;; (xxxxx x (x) -;; (xxxxxx x x sss 1 0 sssss 0 1 sssssss11")) -;; :before (lambda () -;; (setq context-coloring-syntactic-strings t))) +(context-coloring-test-deftest-emacs-lisp string + (lambda () + (context-coloring-test-assert-coloring " +(xxxxx x (x) + (xxxxxx x x sss 1 0 sssss 0 1 sssssss11"))) (context-coloring-test-deftest-emacs-lisp ignored (lambda ()