[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 59492ab 41/79: Refactor token application.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 59492ab 41/79: Refactor token application. |
Date: |
Sun, 14 Jun 2015 00:05:34 +0000 |
branch: master
commit 59492ab8eae5ec7cd3afe258c34025a5dc31c06c
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Refactor token application.
---
context-coloring.el | 84 +++++++++++++---------------------------
test/context-coloring-test.el | 14 +------
2 files changed, 28 insertions(+), 70 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index 753a7da..0f823d8 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -728,43 +728,25 @@ provide visually \"instant\" updates at 60 frames per
second.")
;;; Shell command scopification / colorization
(defun context-coloring-apply-tokens (tokens)
- "Process a list of TOKENS to apply context-based coloring to
-the current buffer. Tokens are 3 integers: start, end, level.
-The list is flat, with a new token occurring after every 3rd
-element."
- (with-silent-modifications
+ "Process a string of TOKENS to apply context-based coloring to
+the current buffer. Tokens are 3 integers: start, end, level. A
+new token occurrs after every 3rd element, and the elements are
+separated by commas."
+ (let* ((tokens (mapcar 'string-to-number (split-string tokens ","))))
(while tokens
(context-coloring-colorize-region
- (prog1 (car tokens) (setq tokens (cdr tokens)))
- (prog1 (car tokens) (setq tokens (cdr tokens)))
- (prog1 (car tokens) (setq tokens (cdr tokens)))))
- (context-coloring-maybe-colorize-comments-and-strings)))
+ (pop tokens)
+ (pop tokens)
+ (pop tokens))))
+ (context-coloring-maybe-colorize-comments-and-strings))
(defun context-coloring-parse-array (array)
- "Parse ARRAY as a flat JSON array of numbers."
- (let ((braceless (substring-no-properties (context-coloring-trim array) 1
-1)))
- (cond
- ((> (length braceless) 0)
- (let* (;; Use a leading comma to simplify the below loop's
- ;; delimiter-checking.
- (chars (vconcat (concat "," braceless)))
- (index (length chars))
- (number 0)
- (multiplier 1)
- numbers)
- (while (> index 0)
- (setq index (1- index))
- (cond
- ((= (elt chars index) context-coloring-COMMA-CHAR)
- (setq numbers (cons number numbers))
- (setq number 0)
- (setq multiplier 1))
- (t
- (setq number (+ number (* (- (elt chars index) 48) multiplier)))
- (setq multiplier (* multiplier 10)))))
- numbers))
- (t
- (list)))))
+ "Parse ARRAY as a flat JSON array of numbers and use the tokens
+to colorize the buffer."
+ (let* ((braceless (substring-no-properties (context-coloring-trim array) 1
-1)))
+ (when (> (length braceless) 0)
+ (with-silent-modifications
+ (context-coloring-apply-tokens braceless)))))
(defvar-local context-coloring-scopifier-process nil
"The single scopifier process that can be running.")
@@ -823,11 +805,10 @@ Invoke CALLBACK when complete."
(context-coloring-scopify-shell-command
command
(lambda (output)
- (let ((tokens (context-coloring-parse-array output)))
- (with-current-buffer buffer
- (context-coloring-apply-tokens tokens))
- (setq context-coloring-scopifier-process nil)
- (when callback (funcall callback))))))
+ (with-current-buffer buffer
+ (context-coloring-parse-array output))
+ (setq context-coloring-scopifier-process nil)
+ (when callback (funcall callback)))))
(context-coloring-send-buffer-to-scopifier))
@@ -853,12 +834,11 @@ Invoke CALLBACK when complete."
"Define a new dispatch named SYMBOL with PROPERTIES.
A \"dispatch\" is a property list describing a strategy for
-coloring a buffer. There are three possible strategies: Parse
-and color in a single function (`:colorizer'), parse in a
-function that returns scope data (`:scopifier'), or parse with a
-shell command that returns scope data (`:command'). In the
-latter two cases, the scope data will be used to automatically
-color the buffer.
+coloring a buffer. There are two possible strategies: Parse and
+color in a single function (`:colorizer') or parse with a shell
+command that returns scope data (`:command'). In the latter
+case, the scope data will be used to automatically color the
+buffer.
PROPERTIES must include `:modes' and one of `:colorizer',
`:scopifier' or `:command'.
@@ -868,9 +848,6 @@ PROPERTIES must include `:modes' and one of `:colorizer',
`:colorizer' - Symbol referring to a function that parses and
colors the buffer.
-`:scopifier' - Symbol referring to a function that parses the
-buffer a returns a flat vector of start, end and level data.
-
`:executable' - Optional name of an executable required by
`:command'.
@@ -890,14 +867,12 @@ should be numeric, e.g. \"2\", \"19700101\", \"1.2.3\",
`context-coloring-mode' is disabled."
(let ((modes (plist-get properties :modes))
(colorizer (plist-get properties :colorizer))
- (scopifier (plist-get properties :scopifier))
(command (plist-get properties :command)))
(when (null modes)
(error "No mode defined for dispatch"))
(when (not (or colorizer
- scopifier
command))
- (error "No colorizer, scopifier or command defined for dispatch"))
+ (error "No colorizer or command defined for dispatch"))
(puthash symbol properties context-coloring-dispatch-hash-table)
(dolist (mode modes)
(puthash mode properties context-coloring-mode-hash-table))))
@@ -1406,18 +1381,13 @@ Invoke CALLBACK when complete. It is invoked
synchronously for
elisp tracks, and asynchronously for shell command tracks."
(let* ((dispatch (context-coloring-get-dispatch-for-mode major-mode))
(colorizer (plist-get dispatch :colorizer))
- (scopifier (plist-get dispatch :scopifier))
(command (plist-get dispatch :command))
interrupted-p)
(cond
- ((or colorizer scopifier)
+ (colorizer
(setq interrupted-p
(catch 'interrupted
- (cond
- (colorizer
- (funcall colorizer))
- (scopifier
- (context-coloring-apply-tokens (funcall scopifier))))))
+ (funcall colorizer)))
(cond
(interrupted-p
(setq context-coloring-changed t))
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
index a74ae6c..7535817 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -414,19 +414,7 @@ override it."
(context-coloring-define-dispatch
'define-dispatch-no-strategy
:modes '(context-coloring-test-define-dispatch-error-mode)))
- "No colorizer, scopifier or command defined for dispatch")))
-
-(context-coloring-test-define-derived-mode define-dispatch-scopifier)
-
-(context-coloring-test-deftest define-dispatch-scopifier
- (lambda ()
- (context-coloring-define-dispatch
- 'define-dispatch-scopifier
- :modes '(context-coloring-test-define-dispatch-scopifier-mode)
- :scopifier (lambda () (list)))
- (context-coloring-test-define-dispatch-scopifier-mode)
- (context-coloring-mode)
- (context-coloring-colorize)))
+ "No colorizer or command defined for dispatch")))
(context-coloring-test-define-derived-mode missing-executable)
- [elpa] master 87893df 32/79: Support comma splicing., (continued)
- [elpa] master 87893df 32/79: Support comma splicing., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 7167e93 19/79: Pass let and let* tests with recursive colorizer., Jackson Ray Hamilton, 2015/06/13
- [elpa] master af4f773 33/79: Colorize comments and strings inside backquotes., Jackson Ray Hamilton, 2015/06/13
- [elpa] master acaaf39 38/79: Add file statistics to benchmarks., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 8836df9 37/79: Add colorization times to logs., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 5661ed0 44/79: Document `:host' and `:port' properties., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 16fa835 40/79: Optimize JSON parser., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 3dfd515 42/79: Messy server implementation., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 872bf5f 46/79: Bump required scopifier version., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 2258572 39/79: Optimize. Refactor., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 59492ab 41/79: Refactor token application.,
Jackson Ray Hamilton <=
- [elpa] master 233ea1a 47/79: Kill any scopifier server before running the tests., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 0079778 48/79: Set `:send-report' to nil., Jackson Ray Hamilton, 2015/06/13
- [elpa] master cacf5de 49/79: Add cond support., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 8d15938 43/79: Cleaner server implementation., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 89286b6 54/79: Cleanup., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 5f9bd49 50/79: Add comments and strings to the cond test., Jackson Ray Hamilton, 2015/06/13
- [elpa] master c2834f0 51/79: Add condition-case support., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 2ee41c1 52/79: Add comments and strings to condition-case test., Jackson Ray Hamilton, 2015/06/13
- [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