[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 6d79b91 024/271: Idly colorizing after changes working. Ca
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 6d79b91 024/271: Idly colorizing after changes working. Cancelling seemingly not working. |
Date: |
Thu, 05 Feb 2015 18:29:30 +0000 |
branch: master
commit 6d79b91656c359e288a1059872211858222198a3
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Idly colorizing after changes working. Cancelling seemingly not working.
---
context-coloring.el | 49 +++++++++++++++++++++++++++++++++++++++----------
1 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index 16ef241..2a0acb7 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -115,7 +115,8 @@ calling FUNCTION with the parsed list of tokens."
(start-process-shell-command "tokenizer" nil
context-coloring-tokenizer-path))
(let ((output "")
- (buffer context-coloring-buffer))
+ (buffer context-coloring-buffer)
+ (start-time context-coloring-colorize-start-time))
;;The process may produce output in multiple chunks. This filter
accumulates
;;the chunks into a message.
@@ -132,7 +133,8 @@ calling FUNCTION with the parsed list of tokens."
(json-read-from-string output))))
(with-current-buffer buffer
(context-coloring-apply-tokens tokens))
- (message "%s (%f)" "Colorization complete."
(float-time)))))))
+ (message "Colorized (after %f seconds)."
+ (- (float-time) start-time)))))))
;; Give the process its input.
(process-send-region context-coloring-tokenizer-process (point-min)
(point-max))
@@ -141,13 +143,24 @@ calling FUNCTION with the parsed list of tokens."
;;; Colorization functions
-(defun context-coloring-colorize-buffer ()
+(defun context-coloring-colorize ()
(interactive)
+ (setq context-coloring-colorize-start-time (float-time))
+ (message "%s" "Colorizing.")
(context-coloring-tokenize))
+(defun context-coloring-change-function (start end length)
+ (setq context-coloring-changed t))
+
(defun context-coloring-maybe-colorize ()
- (when (eq context-coloring-buffer (window-buffer (selected-window)))
- (context-coloring-colorize-buffer)))
+ "Colorize under certain conditions. This will run as an idle
+timer, so firstly the buffer must not be some other
+buffer. Additionally, the buffer must have changed, otherwise
+colorizing would be redundant."
+ (when (and (eq context-coloring-buffer (window-buffer (selected-window)))
+ context-coloring-changed)
+ (setq context-coloring-changed nil)
+ (context-coloring-colorize)))
;;; Local variables
@@ -161,6 +174,19 @@ calling FUNCTION with the parsed list of tokens."
is a reference to that one process.")
(make-variable-buffer-local 'context-coloring-tokenizer-process)
+(defvar context-coloring-colorize-idle-timer nil
+ "Reference to currently-running idle timer.")
+(make-variable-buffer-local 'context-coloring-colorize-idle-timer)
+
+(defvar context-coloring-changed nil
+ "Indication that the buffer has changed recently, which would
+imply that it should be colorized again.")
+(make-variable-buffer-local 'context-coloring-changed)
+
+(defvar context-coloring-colorize-start-time nil
+ "Used for dirty benchmarking of async colorization time.")
+(make-variable-buffer-local 'context-coloring-colorize-start-time)
+
;;; Minor mode
@@ -170,18 +196,21 @@ is a reference to that one process.")
nil " Context" nil
(if (not context-coloring-mode)
(progn
- (when (boundp 'context-coloring-colorize-idle-timer)
+ (when (not (null 'context-coloring-colorize-idle-timer))
(cancel-timer context-coloring-colorize-idle-timer)))
(setq context-coloring-buffer (current-buffer))
;; Colorize once initially.
- (context-coloring-colorize-buffer)
+ (context-coloring-colorize)
+
+ ;; Only recolor on change. So watch for changes.
+ (set (make-local-variable 'after-change-functions)
+ '(context-coloring-change-function))
;; Only recolor idly.
- ;; (set (make-local-variable 'context-coloring-colorize-idle-timer)
- ;; (run-with-idle-timer 1 t 'context-coloring-maybe-colorize))
- ))
+ (setq context-coloring-colorize-idle-timer
+ (run-with-idle-timer 1 t 'context-coloring-maybe-colorize))))
;;;###autoload
(defun context-coloring-mode-enable ()
- [elpa] master updated (c8087b9 -> dc9644e), Jackson Ray Hamilton, 2015/02/05
- [elpa] master e3fc05a 011/271: Create bin and scripts directories., Jackson Ray Hamilton, 2015/02/05
- [elpa] master aaf199e 006/271: Fix global wraparound., Jackson Ray Hamilton, 2015/02/05
- [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 <=
- [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, 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