[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 806398e 016/271: Use asynchronous command execution strate
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 806398e 016/271: Use asynchronous command execution strategy. |
Date: |
Thu, 05 Feb 2015 18:29:26 +0000 |
branch: master
commit 806398e345534643f1b1d59415fbeb912609ea2c
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Use asynchronous command execution strategy.
---
context-coloring.el | 86 ++++++++++++++++++++++++++-------------------------
1 files changed, 44 insertions(+), 42 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index b2daac6..8281676 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -57,7 +57,7 @@ Determines depth at which to cycle through faces again.")
;;; Face utility functions
-(defsubst context-coloring-level-face (depth)
+(defun context-coloring-level-face (depth)
"Return face-name for DEPTH as a string 'context-coloring-depth-DEPTH-face'.
For example: 'context-coloring-depth-1-face'."
(intern-soft
@@ -74,60 +74,62 @@ For example: 'context-coloring-depth-1-face'."
(- context-coloring-face-count 1)))))
"-face")))
-(defun context-coloring-save-buffer-to-temp ()
- "Save buffer to temp file.
-Return the name of the temporary file."
- (let ((file-name (make-temp-file "context-coloring")))
- ;; Do not flush short-lived temporary files onto disk.
- (let ((write-region-inhibit-fsync t))
- (write-region nil nil file-name nil 0))
- file-name))
-;;; The coloring.
+;;; The coloring
(defconst context-coloring-path
(file-name-directory (or load-file-name buffer-file-name)))
-(defun context-coloring-fontify-region (start end)
+(defconst context-coloring-tokenizer-path
+ (expand-file-name "./bin/tokenizer" context-coloring-path))
+
+(defun context-coloring-apply-tokens (tokens)
+ (with-silent-modifications
+ (dolist (token tokens)
+ (let ((start (cdr (assoc 's token)))
+ (end (cdr (assoc 'e token)))
+ (face (context-coloring-level-face (cdr (assoc 'l token)))))
+ (add-text-properties start end `(font-lock-face ,face rear-nonsticky
t))))))
+
+(defun context-coloring-tokenizer-filter (process chunk)
+ (setq context-coloring-tokenizer-output
+ (concat context-coloring-tokenizer-output chunk)))
+
+(defun context-coloring-tokenizer-sentinel (process event)
+ (when (equal "finished\n" event)
+ (let ((tokens (let ((json-array-type 'list))
+ (json-read-from-string
context-coloring-tokenizer-output))))
+ (setq context-coloring-tokenizer-output nil)
+ (context-coloring-apply-tokens tokens))))
+
+(defun context-coloring-tokenize ()
+ ;; Only continue if there is no concurrent tokenization going on.
+ (when (eq context-coloring-tokenizer-output nil)
+ (let ((tokenizer-process (start-process-shell-command
+ "tokenizer"
+ nil
+ context-coloring-tokenizer-path)))
+ (setq context-coloring-tokenizer-output "")
+ (set-process-filter tokenizer-process 'context-coloring-tokenizer-filter)
+ (set-process-sentinel tokenizer-process
'context-coloring-tokenizer-sentinel)
+ (process-send-region tokenizer-process (point-min) (point-max))
+ (process-send-eof tokenizer-process))))
+
+(defun context-coloring-colorize-buffer ()
(interactive)
- (let* ((temp-file (context-coloring-save-buffer-to-temp))
- (json (shell-command-to-string
- (format "%s < %s"
- (expand-file-name "./bin/tokenizer"
context-coloring-path)
- temp-file)))
- (tokens (let ((json-array-type 'list))
- (json-read-from-string json))))
- (with-silent-modifications
- (dolist (token tokens)
- (let ((s (cdr (assoc 's token)))
- (e (cdr (assoc 'e token)))
- (face (context-coloring-level-face (cdr (assoc 'l token)))))
- (when (and (>= s start)
- (<= e end))
- (add-text-properties s e `(font-lock-face ,face rear-nonsticky
t))))))
- (delete-file temp-file)))
-
-;;; Minor mode:
+ (context-coloring-tokenize))
+
+
+;;; Minor mode
;;;###autoload
(define-minor-mode context-coloring-mode
"Context-based code coloring for JavaScript, inspired by Douglas Crockford."
nil " Context" nil
- (make-local-variable 'jit-lock-stealth-time)
- (make-local-variable 'jit-lock-chunk-size)
- (make-local-variable 'jit-lock-contextually)
(if (not context-coloring-mode)
(progn
- (setq jit-lock-stealth-time nil)
- (setq jit-lock-chunk-size 500)
- ;;(setq jit-lock-contextually `syntax-driven)
- (jit-lock-unregister 'context-coloring-fontify-region)
- (jit-lock-register 'font-lock-fontify-region))
- (setq jit-lock-stealth-time 1)
- (setq jit-lock-chunk-size 536870911)
- ;;(setq jit-lock-contextually nil)
- (jit-lock-unregister 'font-lock-fontify-region)
- (jit-lock-register 'context-coloring-fontify-region t)))
+ )
+ (set (make-local-variable 'context-coloring-tokenizer-output) nil)))
;;;###autoload
(defun context-coloring-mode-enable ()
- [elpa] master 809d48b 020/271: Minor tweaks., (continued)
- [elpa] master 809d48b 020/271: Minor tweaks., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 98df7db 010/271: Optimize cli a little bit., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 5fd312b 002/271: More planning and research., Jackson Ray Hamilton, 2015/02/05
- [elpa] master ebc0b99 013/271: Add rollover font lock optimization., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 615ce2c 004/271: Wow, actually works., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 6d79b91 024/271: Idly colorizing after changes working. Cancelling seemingly not working., Jackson Ray Hamilton, 2015/02/05
- [elpa] master fd4b629 007/271: Add mode., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 6e991c4 014/271: Fix off-by-one error., Jackson Ray Hamilton, 2015/02/05
- [elpa] master b35380b 019/271: Vastly improve idle timer strategy., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 7ac8db6 012/271: Fix a bug where strings were matched., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 806398e 016/271: Use asynchronous command execution strategy.,
Jackson Ray Hamilton <=
- [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