[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 5826178 239/271: Update the dispatch API.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 5826178 239/271: Update the dispatch API. |
Date: |
Thu, 05 Feb 2015 18:31:35 +0000 |
branch: master
commit 5826178f9b9f3ebca17c5133e43cde100e7af43e
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Update the dispatch API.
---
context-coloring.el | 127 ++++++++++++++++++++++++++++++++++-----------------
1 files changed, 85 insertions(+), 42 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index 2cda3fb..759e303 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -318,26 +318,75 @@ Invokes CALLBACK when complete."
;;; Dispatch
-(defvar context-coloring-javascript-scopifier
- `(:type shell-command
- :executable "node"
- :command ,(expand-file-name
- "./languages/javascript/binaries/scopifier"
- context-coloring-path))
- "JavaScript scopifier via Node.js.")
-
-(defvar context-coloring-js2-colorizer
- `(:type elisp
- :colorizer context-coloring-js2-colorize)
- "JavaScript colorizer via `js2-mode'.")
-
-(defcustom context-coloring-dispatch-plist
- `(js-mode ,context-coloring-javascript-scopifier
- js2-mode ,context-coloring-js2-colorizer
- js3-mode ,context-coloring-javascript-scopifier)
- "Property list mapping major modes to scopification and
-colorization programs."
- :group 'context-coloring)
+(defvar context-coloring-dispatch-hash-table (make-hash-table :test 'eq)
+ "Mapping of dispatch strategy names to their corresponding
+ property lists, which contain details about the strategies.")
+
+(defvar context-coloring-mode-hash-table (make-hash-table :test 'eq)
+ "Mapping of major mode names to dispatch property lists.")
+
+(defun context-coloring-select-dispatch (mode dispatch)
+ "Use DISPATCH for MODE."
+ (puthash
+ mode
+ (gethash
+ dispatch
+ context-coloring-dispatch-hash-table)
+ context-coloring-mode-hash-table))
+
+(defun context-coloring-define-dispatch (symbol &rest properties)
+ "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.
+
+PROPERTIES must include `:modes' and one of `:colorizer',
+`:scopifier' or `:command'.
+
+`:modes' - List of major modes this dispatch is valid for.
+
+`: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'.
+
+`:command' - Shell command to execute with the current buffer
+sent via stdin, and with a flat JSON array of start, end and
+level data returned via stdout."
+ (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"))
+ (puthash symbol properties context-coloring-dispatch-hash-table)
+ (dolist (mode modes)
+ (when (null (gethash mode context-coloring-mode-hash-table))
+ (puthash mode properties context-coloring-mode-hash-table)))))
+
+(context-coloring-define-dispatch 'javascript-node
+ :modes '(js-mode js3-mode)
+ :executable "node"
+ :command (expand-file-name
+ "./languages/javascript/binaries/scopifier"
+ context-coloring-path))
+
+(context-coloring-define-dispatch 'javascript-js2
+ :modes '(js2-mode)
+ :colorizer 'context-coloring-js2-colorize)
(defun context-coloring-dispatch (&optional callback)
"Determines the optimal track for scopification / colorization
@@ -345,31 +394,25 @@ of the current buffer, then executes it.
Invokes CALLBACK when complete. It is invoked synchronously for
elisp tracks, and asynchronously for shell command tracks."
- (let ((dispatch (plist-get context-coloring-dispatch-plist major-mode)))
+ (let ((dispatch (gethash major-mode context-coloring-mode-hash-table)))
(if (null dispatch)
(message "%s" "Context coloring is not available for this major mode"))
- (let ((type (plist-get dispatch :type)))
+ (let (colorizer
+ scopifier
+ command
+ executable)
(cond
- ((eq type 'elisp)
- (let ((colorizer (plist-get dispatch :colorizer))
- (scopifier (plist-get dispatch :scopifier)))
- (cond
- (colorizer
- (funcall colorizer)
- (if callback (funcall callback)))
- (scopifier
- (context-coloring-apply-tokens (funcall scopifier))
- (if callback (funcall callback)))
- (t
- (error "No `:colorizer' nor `:scopifier' specified for dispatch of
`:type' elisp")))))
- ((eq type 'shell-command)
- (let ((executable (plist-get dispatch :executable))
- (command (plist-get dispatch :command)))
- (if (null command)
- (error "No `:command' specified for dispatch of `:type'
shell-command"))
- (if (and (not (null executable))
- (null (executable-find executable)))
- (message "Executable \"%s\" not found" executable))
+ ((setq colorizer (plist-get dispatch :colorizer))
+ (funcall colorizer)
+ (if callback (funcall callback)))
+ ((setq scopifier (plist-get dispatch :scopifier))
+ (context-coloring-apply-tokens (funcall scopifier))
+ (if callback (funcall callback)))
+ ((setq command (plist-get dispatch :command))
+ (setq executable (plist-get dispatch :executable))
+ (if (and (not (null executable))
+ (null (executable-find executable)))
+ (message "Executable \"%s\" not found" executable)
(context-coloring-scopify-shell-command command callback)))))))
- [elpa] master d44b426 208/271: Merge branch 'master' into develop, (continued)
- [elpa] master d44b426 208/271: Merge branch 'master' into develop, Jackson Ray Hamilton, 2015/02/05
- [elpa] master 3cff176 210/271: Add failing key-value pair test., Jackson Ray Hamilton, 2015/02/05
- [elpa] master e09d9ad 227/271: Add tests for comments and strings., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 21cc6c6 200/271: Save benchmark logs to an untracked directory., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 30a24f9 265/271: Add 'packages/context-coloring/' from commit 'f2b5d796d4dffc71b10503a8ae119bfa3274978e', Jackson Ray Hamilton, 2015/02/05
- [elpa] master 03d111c 235/271: Cleanup., Jackson Ray Hamilton, 2015/02/05
- [elpa] master eba74ae 192/271: Improve assertion functions., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 127b312 225/271: Remove rear-nonsticky., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 441dde0 178/271: Cleanup, comments., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 9fb06d8 254/271: Merge branch 'master' into develop, Jackson Ray Hamilton, 2015/02/05
- [elpa] master 5826178 239/271: Update the dispatch API.,
Jackson Ray Hamilton <=
- [elpa] master 3c8f842 195/271: Write failing property lookup test., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 4ac1eaa 242/271: Version 3.0.0., Jackson Ray Hamilton, 2015/02/05
- [elpa] master b485897 186/271: Update benchmarks., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 9e177bf 268/271: Update headers and documentation for download-dependencies.el., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 48ff468 220/271: Update linter., Jackson Ray Hamilton, 2015/02/05
- [elpa] master a0fefc4 245/271: Add themes. Prepare for ELPA. Version 3.1.0., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 574b955 248/271: Update sentence spacing., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 1f04586 172/271: Merge branch 'feature/js2-mode' into develop, Jackson Ray Hamilton, 2015/02/05
- [elpa] master 87725bc 190/271: Positions., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 7b2a4c8 214/271: Merge branch 'develop', Jackson Ray Hamilton, 2015/02/05