[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 45c0d1a 23/26: Add `:setup' and `:teardown' properties to
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 45c0d1a 23/26: Add `:setup' and `:teardown' properties to dispatches. |
Date: |
Sat, 14 Feb 2015 08:19:40 +0000 |
branch: master
commit 45c0d1af2342ad8f4adc580a48ff0d7d35f9c7a3
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Add `:setup' and `:teardown' properties to dispatches.
---
context-coloring.el | 60 ++++++++++++++++++++++++++++++++++-----------------
1 files changed, 40 insertions(+), 20 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index b9f5cc4..574f0bc 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -354,7 +354,13 @@ buffer a returns a flat vector of start, end and level
data.
`: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."
+level data returned via stdout.
+
+`:setup' - Arbitrary code to set up this dispatch when
+`context-coloring-mode' is enabled.
+
+`:teardown' - Arbitrary code to tear down this dispatch when
+`context-coloring-mode' is disabled."
(let ((modes (plist-get properties :modes))
(colorizer (plist-get properties :colorizer))
(scopifier (plist-get properties :scopifier))
@@ -379,7 +385,13 @@ level data returned via stdout."
(context-coloring-define-dispatch
'javascript-js2
:modes '(js2-mode)
- :colorizer 'context-coloring-js2-colorize)
+ :colorizer 'context-coloring-js2-colorize
+ :setup
+ (lambda ()
+ (add-hook 'js2-post-parse-callbacks 'context-coloring-colorize nil t))
+ :teardown
+ (lambda ()
+ (remove-hook 'js2-post-parse-callbacks 'context-coloring-colorize t)))
(defun context-coloring-dispatch (&optional callback)
"Determine the optimal track for scopification / coloring of
@@ -804,10 +816,15 @@ Supported modes: `js-mode', `js3-mode'"
(context-coloring-kill-scopifier)
(when context-coloring-colorize-idle-timer
(cancel-timer context-coloring-colorize-idle-timer))
- (remove-hook
- 'js2-post-parse-callbacks 'context-coloring-colorize t)
- (remove-hook
- 'after-change-functions 'context-coloring-change-function t)
+ (let ((dispatch (gethash major-mode context-coloring-mode-hash-table)))
+ (when dispatch
+ (let ((command (plist-get dispatch :command))
+ (teardown (plist-get dispatch :teardown)))
+ (when command
+ (remove-hook
+ 'after-change-functions 'context-coloring-change-function t))
+ (when teardown
+ (funcall teardown)))))
(font-lock-mode)
(jit-lock-mode t))
@@ -818,21 +835,24 @@ Supported modes: `js-mode', `js3-mode'"
(font-lock-mode 0)
(jit-lock-mode nil)
- ;; Colorize once initially.
- (context-coloring-colorize)
+ (let ((dispatch (gethash major-mode context-coloring-mode-hash-table)))
+ (when dispatch
+ (let ((command (plist-get dispatch :command))
+ (setup (plist-get dispatch :setup)))
+ (when command
+ ;; Shell commands recolor on change, idly.
+ (add-hook
+ 'after-change-functions 'context-coloring-change-function nil t)
+ (setq context-coloring-colorize-idle-timer
+ (run-with-idle-timer
+ context-coloring-delay
+ t
+ 'context-coloring-maybe-colorize)))
+ (when setup
+ (funcall setup)))))
- (cond
- ((equal major-mode 'js2-mode)
- ;; Only recolor on reparse.
- (add-hook 'js2-post-parse-callbacks 'context-coloring-colorize nil t))
- (t
- ;; Only recolor on change, idly.
- (add-hook 'after-change-functions 'context-coloring-change-function nil
t)
- (setq context-coloring-colorize-idle-timer
- (run-with-idle-timer
- context-coloring-delay
- t
- 'context-coloring-maybe-colorize))))))
+ ;; Colorize once initially.
+ (context-coloring-colorize)))
(provide 'context-coloring)
- [elpa] master a49b024 15/26: Whitespace., (continued)
- [elpa] master a49b024 15/26: Whitespace., Jackson Ray Hamilton, 2015/02/14
- [elpa] master 0681e94 13/26: Remove `set-colors' and `set-colors-default'., Jackson Ray Hamilton, 2015/02/14
- [elpa] master e5d512f 10/26: "Misfeature.", Jackson Ray Hamilton, 2015/02/14
- [elpa] master 25a8d13 16/26: Documentation., Jackson Ray Hamilton, 2015/02/14
- [elpa] master 4c3d1da 17/26: Rename `defface-default' to `defface-neutral'., Jackson Ray Hamilton, 2015/02/14
- [elpa] master 8367e19 18/26: Rename `level-face' functions., Jackson Ray Hamilton, 2015/02/14
- [elpa] master 3d91840 22/26: Remove `context-coloring-benchmark-colorization'., Jackson Ray Hamilton, 2015/02/14
- [elpa] master 3805110 14/26: Reorganize faces. Remove eval macroexpand., Jackson Ray Hamilton, 2015/02/14
- [elpa] master a7db850 20/26: Cleanup documentation., Jackson Ray Hamilton, 2015/02/14
- [elpa] master bae456d 19/26: Use imperative for documentation., Jackson Ray Hamilton, 2015/02/14
- [elpa] master 45c0d1a 23/26: Add `:setup' and `:teardown' properties to dispatches.,
Jackson Ray Hamilton <=
- [elpa] master f4e1cbc 25/26: Version 6.0.0., Jackson Ray Hamilton, 2015/02/14
- [elpa] master 8e5674f 21/26: Cleanup documentation., Jackson Ray Hamilton, 2015/02/14
- [elpa] master f52a5e5 26/26: Merge commit 'f4e1cbc5386fbf197ff8bcb6a9275f17c9cbe8e4' from context-coloring, Jackson Ray Hamilton, 2015/02/14
- [elpa] master e2d3320 24/26: Add `uncompile' Makefile task., Jackson Ray Hamilton, 2015/02/14