branch: master commit cacf5de396962d767d59ca203afc2cc3d0bb6d85 Author: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com> Commit: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com>
Add cond support. --- context-coloring.el | 37 +++++++++++++++++++++++++++++++++++++ test/context-coloring-test.el | 10 ++++++++++ test/fixtures/cond.el | 6 ++++++ 3 files changed, 53 insertions(+), 0 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index f53066e..104964c 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -280,6 +280,14 @@ generated by `js2-mode'." "Move forward through whitespace and comments." (while (forward-comment 1))) +(defsubst context-coloring-elisp-forward-sws () + "Move forward through whitespace and comments, colorizing +them along the way." + (let ((start (point))) + (context-coloring-forward-sws) + (context-coloring-elisp-colorize-comments-and-strings-in-region + start (point)))) + (defsubst context-coloring-get-syntax-code () (syntax-class ;; Faster version of `syntax-after': @@ -539,6 +547,31 @@ provide visually \"instant\" updates at 60 frames per second.") (defun context-coloring-elisp-colorize-let* () (context-coloring-elisp-colorize-defun-like t 'let*)) +(defun context-coloring-elisp-colorize-cond () + (let (syntax-code) + ;; Enter. + (forward-char) + (context-coloring-elisp-forward-sws) + ;; Skip past the "cond". + (skip-syntax-forward "^w_") + (context-coloring-elisp-forward-sws) + (while (/= (setq syntax-code (context-coloring-get-syntax-code)) + context-coloring-CLOSE-PARENTHESIS-CODE) + (cond + ((= syntax-code context-coloring-OPEN-PARENTHESIS-CODE) + ;; Colorize inside the parens. + (let ((start (point))) + (forward-sexp) + (context-coloring-elisp-colorize-region + (1+ start) (1- (point))) + ;; Exit. + (forward-char))) + (t + (forward-sexp))) + (context-coloring-elisp-forward-sws)) + ;; Exit. + (forward-char))) + (defun context-coloring-elisp-colorize-parenthesized-sexp () (context-coloring-elisp-increment-sexp-count) (let* ((start (point)) @@ -573,6 +606,10 @@ provide visually \"instant\" updates at 60 frames per second.") (goto-char start) (context-coloring-elisp-colorize-lambda) t) + ((string-equal "cond" name-string) + (goto-char start) + (context-coloring-elisp-colorize-cond) + t) (t nil))))) ;; Not a special form; just colorize the remaining region. diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 7535817..c97228e 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -1152,6 +1152,16 @@ ssssssssssss0")) 2222 1 1 2 2 2 000022 1111 1 1 1 0 0 000011"))) +(context-coloring-test-deftest-emacs-lisp cond + (lambda () + (context-coloring-test-assert-coloring " +(xxx (x) + 11111 + 11 11 + 10000 11 + 1111 1 00001 11 + 11 11111 1 0000111)"))) + (defun context-coloring-test-insert-unread-space () "Simulate the insertion of a space as if by a user." (setq unread-command-events (cons '(t . 32) diff --git a/test/fixtures/cond.el b/test/fixtures/cond.el new file mode 100644 index 0000000..e05d255 --- /dev/null +++ b/test/fixtures/cond.el @@ -0,0 +1,6 @@ +(let (a) + (cond + (a t) + (free t) + ((eq a free) t) + (t (list a free))))