[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 09166f9 021/271: Some progress, probably have to switch ba
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 09166f9 021/271: Some progress, probably have to switch back to lexical. |
Date: |
Thu, 05 Feb 2015 18:29:29 +0000 |
branch: master
commit 09166f9fd225f2b280ab8af0b770ed661a9fcabf
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Some progress, probably have to switch back to lexical.
---
context-coloring.el | 90 ++++++++++++++++++++++++++++++-----------------
package.json | 25 +++++++++++++
test/fixtures/monad.js | 3 ++
3 files changed, 85 insertions(+), 33 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index 03b43b6..c106a7f 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -1,4 +1,4 @@
-;; -*- lexical-binding: t -*-
+;; -*- lexical-binding: t; -*-
(require 'json)
@@ -100,45 +100,63 @@ For example: \"context-coloring-depth-1-face\"."
(face (context-coloring-level-face (cdr (assoc 'l token)))))
(add-text-properties start end `(font-lock-face ,face rear-nonsticky
t))))))
-(defun context-coloring-tokenize (function)
+(defun context-coloring-tokenizer-filter (process chunk)
+ "The process may produce output in multiple chunks. This filter
+accumulates the chunks into a message."
+ (setq context-coloring-tokenizer-output
+ (concat context-coloring-tokenizer-output chunk)))
+
+(defun context-coloring-tokenizer-sentinel (process event)
+ "When the process's message is complete, this sentinel parses
+it as JSON and applies the tokens to the buffer."
+ (when (equal "finished\n" event)
+ (let ((tokens (let ((json-array-type 'list))
+ (json-read-from-string
context-coloring-tokenizer-output))))
+ (context-coloring-apply-tokens tokens)
+ (message "%s (%f)" "Colorization complete." (float-time)))))
+
+(defun context-coloring-tokenize ()
"Invokes the external tokenizer with the current buffer's
contents, reading the tokenizer's response asynchronously and
calling FUNCTION with the parsed list of tokens."
- (let ((tokenizer-process (start-process-shell-command
- "tokenizer"
- nil
- context-coloring-tokenizer-path))
- (output ""))
-
- ;; The process may produce output in multiple chunks. The chunks
- ;; collectively form a message.
- (set-process-filter tokenizer-process
- (lambda (process chunk)
- (setq output (concat output chunk))))
-
- ;; When the message is complete, parse it as JSON and apply the tokens.
- (set-process-sentinel tokenizer-process
- (lambda (process event)
- (when (equal "finished\n" event)
- (let ((tokens (let ((json-array-type 'list))
- (json-read-from-string output))))
- (funcall function tokens)))))
-
- ;; Give the process its input.
- (process-send-region tokenizer-process (point-min) (point-max))
- (process-send-eof tokenizer-process)))
+
+ ;; Cancel a running process because it is implicitly obsolete if we are
+ ;; calling this function.
+ (when (not (null context-coloring-tokenizer-process))
+ (delete-process context-coloring-tokenizer-process))
+
+ ;; Start the process.
+ (setq context-coloring-tokenizer-process
+ (start-process-shell-command "tokenizer" nil
context-coloring-tokenizer-path))
+ (setq context-coloring-tokenizer-output "")
+
+ ;; Listen to the process.
+ (set-process-filter context-coloring-tokenizer-process
'context-coloring-tokenizer-filter)
+ (set-process-sentinel context-coloring-tokenizer-process
'context-coloring-tokenizer-sentinel)
+
+ ;; Give the process its input.
+ (process-send-region context-coloring-tokenizer-process (point-min)
(point-max))
+ (process-send-eof context-coloring-tokenizer-process))
;;; Colorization functions
(defun context-coloring-colorize-buffer ()
(interactive)
- (context-coloring-tokenize 'context-coloring-apply-tokens))
+ (context-coloring-tokenize))
-(defun context-coloring-colorize-if-current ()
+(defun context-coloring-maybe-colorize ()
(when (eq context-coloring-buffer (window-buffer (selected-window)))
(context-coloring-colorize-buffer)))
+(defvar context-coloring-buffer)
+(make-variable-buffer-local 'context-coloring-buffer)
+
+(defvar context-coloring-tokenizer-process nil)
+(make-variable-buffer-local 'context-coloring-tokenizer-process)
+
+(defvar context-coloring-tokenizer-output nil)
+(make-variable-buffer-local 'context-coloring-tokenizer-output)
;;; Minor mode
@@ -151,15 +169,21 @@ calling FUNCTION with the parsed list of tokens."
(when (boundp 'context-coloring-colorize-idle-timer)
(cancel-timer context-coloring-colorize-idle-timer)))
- ;; Colorize once initially. Why this doesn't work, I cannot say.
- ;; (context-coloring-colorize-buffer)
-
;; Preserve a reference to this buffer.
- (set (make-local-variable 'context-coloring-buffer) (current-buffer))
+ (setq context-coloring-buffer (current-buffer))
+
+ ;; Only allow a single tokenizer process to run at a time. Keep track of it
+ ;; with this reference.
+ ;; (set (make-local-variable 'context-coloring-tokenizer-process) nil)
+ ;; (set (make-local-variable 'context-coloring-tokenizer-output) nil)
+
+ ;; Colorize once initially.
+ (context-coloring-colorize-buffer)
;; Only recolor idly.
- (set (make-local-variable 'context-coloring-colorize-idle-timer)
- (run-with-idle-timer 1 t 'context-coloring-colorize-if-current))))
+ ;; (set (make-local-variable 'context-coloring-colorize-idle-timer)
+ ;; (run-with-idle-timer 1 t 'context-coloring-maybe-colorize))
+ ))
;;;###autoload
(defun context-coloring-mode-enable ()
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..8229496
--- /dev/null
+++ b/package.json
@@ -0,0 +1,25 @@
+{
+ "name": "context-coloring",
+ "version": "0.0.0",
+ "description": "JavaScript syntax highlighting for grown-ups.",
+ "main": "index.js",
+ "directories": {
+ "test": "test"
+ },
+ "scripts": {
+ "test": "make test"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/jacksonrayhamilton/context-coloring.git"
+ },
+ "author": "Jackson Ray Hamilton",
+ "license": "GPL-3.0+",
+ "bugs": {
+ "url": "https://github.com/jacksonrayhamilton/context-coloring/issues"
+ },
+ "homepage": "https://github.com/jacksonrayhamilton/context-coloring",
+ "devDependencies": {
+ "matcha": "^0.6.0"
+ }
+}
diff --git a/test/fixtures/monad.js b/test/fixtures/monad.js
index 7646f0d..f49ca8a 100644
--- a/test/fixtures/monad.js
+++ b/test/fixtures/monad.js
@@ -10,6 +10,9 @@
monad.bind = function (func) {
return func(value);
};
+ monad.go = function () {
+
+ };
return monad;
};
}
- [elpa] master d0f5470 022/271: Successfully lexically bind buffer., (continued)
- [elpa] master d0f5470 022/271: Successfully lexically bind buffer., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 397ef04 005/271: Detect globals., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 409a05b 017/271: Enable font lock again., Jackson Ray Hamilton, 2015/02/05
- [elpa] master a72314c 008/271: Write temp files., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 6a2a7df 018/271: Use idle timers instead of font lock., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 0a4248b 009/271: Update chunk size., Jackson Ray Hamilton, 2015/02/05
- [elpa] master ffd69f5 026/271: Minutia., Jackson Ray Hamilton, 2015/02/05
- [elpa] master f349ecb 027/271: Minutia., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 35453e0 015/271: Only color changed regions., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 222276b 001/271: Init., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 09166f9 021/271: Some progress, probably have to switch back to lexical.,
Jackson Ray Hamilton <=
- [elpa] master e448e2f 025/271: Cancelling working., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 97194c7 023/271: Apply tokens with lexically-bound buffer as current., Jackson Ray Hamilton, 2015/02/05
- [elpa] master b4b86ac 033/271: Fix after-change-functions with add-hook. Fix nulls., Jackson Ray Hamilton, 2015/02/05
- [elpa] master cce215d 030/271: Add readme., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 169b1f4 028/271: Set JSLint options to not care., Jackson Ray Hamilton, 2015/02/05
- [elpa] master df36161 031/271: Fix screenshot link., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 16e984c 039/271: Update installation instructions., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 3e6f2cf 037/271: Cleanup., Jackson Ray Hamilton, 2015/02/05
- [elpa] master bd8fc87 034/271: Restore test files. Start on uglify tokenizer., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 099e8c1 003/271: Write basic tokenizer cli., Jackson Ray Hamilton, 2015/02/05