]> code.delx.au - gnu-emacs-elpa/commitdiff
Add cond support.
authorJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Sat, 6 Jun 2015 20:01:26 +0000 (13:01 -0700)
committerJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Sat, 6 Jun 2015 20:01:26 +0000 (13:01 -0700)
context-coloring.el
test/context-coloring-test.el
test/fixtures/cond.el [new file with mode: 0644]

index f53066e52cc46b67cb055fe32b9d92bffad025a2..104964c66acb07d468ba527a1b425cb2a0c1ff05 100644 (file)
@@ -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.
index 75358177bb2a7edc2d3c4699964f26065010bc4d..c97228edb3927b77629720fa54b02f8266fe4dff 100644 (file)
@@ -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 (file)
index 0000000..e05d255
--- /dev/null
@@ -0,0 +1,6 @@
+(let (a)
+  (cond
+   (a t)
+   (free t)
+   ((eq a free) t)
+   (t (list a free))))