[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master fd4bc95 66/79: Add dolist support.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master fd4bc95 66/79: Add dolist support. |
Date: |
Sun, 14 Jun 2015 00:05:44 +0000 |
branch: master
commit fd4bc9582cf9cb686254ce2aebe3b359c7e54d59
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Add dolist support.
---
context-coloring.el | 66 +++++++++++++++++++++++++++++++++++++++++
test/context-coloring-test.el | 7 ++++
test/fixtures/dolist.el | 3 ++
3 files changed, 76 insertions(+), 0 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index d89f844..c6a00ff 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -402,6 +402,10 @@ the way."
'("condition-case"
"condition-case-unless-debug")))
+(defconst context-coloring-elisp-dolist-regexp
+ (context-coloring-exact-or-regexp
+ '("dolist" "dotimes")))
+
(defconst context-coloring-elisp-ignored-word-regexp
(context-coloring-join (list "\\`[-+]?[0-9]"
"\\`[&:].+"
@@ -761,6 +765,64 @@ LET-TYPE can be one of `let' or `let*'."
(forward-char)
(context-coloring-elisp-pop-scope)))
+(defun context-coloring-elisp-colorize-scope (callback)
+ "Color the whole scope at point with its one color. Handle a
+header in CALLBACK."
+ (let ((start (point))
+ (end (progn (forward-sexp)
+ (point))))
+ (context-coloring-elisp-push-scope)
+ ;; Splash the whole thing in one color.
+ (context-coloring-colorize-region
+ start
+ end
+ (context-coloring-elisp-get-current-scope-level))
+ ;; Even if the parse is interrupted, this region should still be colored
+ ;; syntactically.
+ (context-coloring-elisp-colorize-comments-and-strings-in-region
+ start
+ end)
+ (goto-char start)
+ ;; Enter.
+ (forward-char)
+ (context-coloring-elisp-forward-sws)
+ ;; Skip past the function name.
+ (forward-sexp)
+ (context-coloring-elisp-forward-sws)
+ (funcall callback)
+ (context-coloring-elisp-colorize-region (point) (1- end))
+ ;; Exit.
+ (forward-char)
+ (context-coloring-elisp-pop-scope)))
+
+(defun context-coloring-elisp-colorize-dolist ()
+ "Color the `dolist' at point."
+ (let (syntax-code
+ (index 0))
+ (context-coloring-elisp-colorize-scope
+ (lambda ()
+ (setq syntax-code (context-coloring-get-syntax-code))
+ (when (= syntax-code context-coloring-OPEN-PARENTHESIS-CODE)
+ (forward-char)
+ (context-coloring-elisp-forward-sws)
+ (while (/= (setq syntax-code (context-coloring-get-syntax-code))
+ context-coloring-CLOSE-PARENTHESIS-CODE)
+ (cond
+ ((and
+ (or (= index 0) (= index 2))
+ (context-coloring-elisp-identifier-p syntax-code))
+ ;; Add the first or third name to the scope.
+ (context-coloring-elisp-parse-bindable
+ (lambda (variable)
+ (context-coloring-elisp-add-variable variable))))
+ (t
+ ;; Color artifacts.
+ (context-coloring-elisp-colorize-sexp)))
+ (context-coloring-elisp-forward-sws)
+ (setq index (1+ index)))
+ ;; Exit.
+ (forward-char))))))
+
(defun context-coloring-elisp-colorize-parenthesized-sexp ()
"Color the sexp enclosed by parenthesis at point."
(context-coloring-elisp-increment-sexp-count)
@@ -805,6 +867,10 @@ LET-TYPE can be one of `let' or `let*'."
(goto-char start)
(context-coloring-elisp-colorize-condition-case)
t)
+ ((string-match-p context-coloring-elisp-dolist-regexp name-string)
+ (goto-char start)
+ (context-coloring-elisp-colorize-dolist)
+ 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 95a081d..4393c74 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -1190,6 +1190,13 @@ ssssssssssss0"))
(11111 (xxx () 222))
sss)")))
+(context-coloring-test-deftest-emacs-lisp dolist
+ (lambda ()
+ (context-coloring-test-assert-coloring "
+1111111 111111
+ 2222222 2222 1111 2222222
+ 3333333 33 33 222 1111 2222223321")))
+
(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/dolist.el b/test/fixtures/dolist.el
new file mode 100644
index 0000000..f103670
--- /dev/null
+++ b/test/fixtures/dolist.el
@@ -0,0 +1,3 @@
+(lambda (list)
+ (dolist (var list result)
+ (lambda () (+ var list result))))
- [elpa] master e387aaf 45/79: Merge branch 'server' into elisp, (continued)
- [elpa] master e387aaf 45/79: Merge branch 'server' into elisp, Jackson Ray Hamilton, 2015/06/13
- [elpa] master 77b075f 60/79: Space., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 5857bc8 53/79: Refactor comments and strings coloring., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 4bd7fc7 56/79: Make delays configurable at the dispatch level., Jackson Ray Hamilton, 2015/06/13
- [elpa] master f870598 59/79: Fix infinite loop when parsing let., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 3c7a00d 55/79: Add lazy coloring., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 08e2981 63/79: Swallow scan errors., Jackson Ray Hamilton, 2015/06/13
- [elpa] master ec9f04d 64/79: Update emacs lisp support in readme., Jackson Ray Hamilton, 2015/06/13
- [elpa] master d2e08e8 62/79: Improve and test lazy coloring., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 46a9193 65/79: Find the edges of the screen more efficiently., Jackson Ray Hamilton, 2015/06/13
- [elpa] master fd4bc95 66/79: Add dolist support.,
Jackson Ray Hamilton <=
- [elpa] master 9edc6c3 69/79: Checkdoc cleanup., Jackson Ray Hamilton, 2015/06/13
- [elpa] master e2ceef9 57/79: Prepend function symbols with octothorpes., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 22403b7 61/79: Cover parsing edge cases., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 67576b5 72/79: Skip all insignificant expression prefixes., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 306335e 71/79: Add defadvice support., Jackson Ray Hamilton, 2015/06/13
- [elpa] master acf15ae 70/79: Remove if., Jackson Ray Hamilton, 2015/06/13
- [elpa] master ed870d8 68/79: Refactor minor mode definition., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 72a0998 73/79: Add quote and backquote function support., Jackson Ray Hamilton, 2015/06/13
- [elpa] master a4a136c 74/79: Refactor defun / defadvice name handling., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 69ea835 67/79: Refactor elisp parsers using helper functions., Jackson Ray Hamilton, 2015/06/13