[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master d0f5470 022/271: Successfully lexically bind buffer.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master d0f5470 022/271: Successfully lexically bind buffer. |
Date: |
Thu, 05 Feb 2015 18:29:29 +0000 |
branch: master
commit d0f5470eb473df68147aeeed99abfc9ad34ced74
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Successfully lexically bind buffer.
---
context-coloring.el | 61 +++++++++++++++++++++++---------------------------
1 files changed, 28 insertions(+), 33 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index c106a7f..2b7e33c 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -80,12 +80,10 @@ For example: \"context-coloring-depth-1-face\"."
;;; Path constants
-(defconst context-coloring-path
- (file-name-directory (or load-file-name buffer-file-name))
+(defconst context-coloring-path (file-name-directory (or load-file-name
buffer-file-name))
"This file's directory.")
-(defconst context-coloring-tokenizer-path
- (expand-file-name "./bin/tokenizer" context-coloring-path)
+(defconst context-coloring-tokenizer-path (expand-file-name "./bin/tokenizer"
context-coloring-path)
"Path to the external tokenizer executable.")
@@ -100,21 +98,6 @@ 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-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
@@ -128,11 +111,25 @@ calling FUNCTION with the parsed list of tokens."
;; 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)
+ (let ((output "")
+ (buffer context-coloring-buffer))
+
+ ;;The process may produce output in multiple chunks. This filter
accumulates
+ ;;the chunks into a message.
+ (set-process-filter context-coloring-tokenizer-process
+ (lambda (process chunk)
+ (setq output (concat output chunk))))
+
+ ;; When the process's message is complete, this sentinel parses it as JSON
+ ;; and applies the tokens to the buffer.
+ (set-process-sentinel context-coloring-tokenizer-process
+ (lambda (process event)
+ (when (equal "finished\n" event)
+ (let ((tokens (let ((json-array-type 'list))
+ (json-read-from-string output))))
+ (context-coloring-apply-tokens tokens)
+ (message "%s (%f)" "Colorization complete."
(float-time)))))))
;; Give the process its input.
(process-send-region context-coloring-tokenizer-process (point-min)
(point-max))
@@ -149,14 +146,18 @@ calling FUNCTION with the parsed list of tokens."
(when (eq context-coloring-buffer (window-buffer (selected-window)))
(context-coloring-colorize-buffer)))
-(defvar context-coloring-buffer)
+
+;;; Local variables
+
+(defvar context-coloring-buffer nil
+ "Reference to this buffer for timers.")
(make-variable-buffer-local 'context-coloring-buffer)
-(defvar context-coloring-tokenizer-process nil)
+(defvar context-coloring-tokenizer-process nil
+ "Only allow a single tokenizer process to run at a time. This
+is a reference to that one process.")
(make-variable-buffer-local 'context-coloring-tokenizer-process)
-(defvar context-coloring-tokenizer-output nil)
-(make-variable-buffer-local 'context-coloring-tokenizer-output)
;;; Minor mode
@@ -169,14 +170,8 @@ calling FUNCTION with the parsed list of tokens."
(when (boundp 'context-coloring-colorize-idle-timer)
(cancel-timer context-coloring-colorize-idle-timer)))
- ;; Preserve a reference to this 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)
- [elpa] master 98df7db 010/271: Optimize cli a little bit., (continued)
- [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, 2015/02/05
- [elpa] master d0f5470 022/271: Successfully lexically bind buffer.,
Jackson Ray Hamilton <=
- [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, 2015/02/05