[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 9b436c0 76/79: Fully recolor later after a fast recolor.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 9b436c0 76/79: Fully recolor later after a fast recolor. |
Date: |
Sun, 14 Jun 2015 00:05:49 +0000 |
branch: master
commit 9b436c087420fd0264568547b558197a173153eb
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Fully recolor later after a fast recolor.
---
context-coloring.el | 56 +++++++++++++++++++++++++++++++---------
test/context-coloring-test.el | 2 +-
2 files changed, 44 insertions(+), 14 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index 6b78a1a..d248edc 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -125,8 +125,8 @@ themes have been disabled.")
(defvar-local context-coloring-changed-p nil
"Indication that the buffer has changed recently, which implies
that it should be colored again by
-`context-coloring-colorize-idle-timer' if that timer is being
-used.")
+`context-coloring-maybe-colorize-idle-timer' if that timer is
+being used.")
(defvar-local context-coloring-changed-start nil
"Beginning of last text that changed.")
@@ -148,18 +148,20 @@ START, END and LENGTH are recorded for later use."
(setq context-coloring-changed-length length)
(setq context-coloring-changed-p t))
-(defun context-coloring-maybe-colorize (buffer)
- "Colorize the current buffer if it is BUFFER and has changed."
- (when (and (eq buffer (current-buffer))
- context-coloring-changed-p)
- (context-coloring-colorize)
+(defun context-coloring-maybe-colorize-with-buffer (buffer)
+ "Color BUFFER and if it has changed."
+ (when context-coloring-changed-p
+ (context-coloring-colorize-with-buffer buffer)
(setq context-coloring-changed-p nil)
(setq context-coloring-changed-start nil)
(setq context-coloring-changed-end nil)
(setq context-coloring-changed-length nil)))
+(defvar-local context-coloring-maybe-colorize-idle-timer nil
+ "The currently-running idle timer for conditional coloring.")
+
(defvar-local context-coloring-colorize-idle-timer nil
- "The currently-running idle timer.")
+ "The currently-running idle timer for unconditional coloring.")
(defcustom context-coloring-default-delay 0.25
"Default (sometimes overridden) delay between a buffer update
@@ -176,6 +178,21 @@ Supported modes: `js-mode', `js3-mode'"
'context-coloring-default-delay
"6.4.0")
+(defun context-coloring-cancel-timer (timer)
+ "Cancel TIMER."
+ (when timer
+ (cancel-timer timer)))
+
+(defun context-coloring-schedule-coloring (time)
+ "Schedule coloring to occur once after Emacs is idle for TIME."
+ (context-coloring-cancel-timer context-coloring-colorize-idle-timer)
+ (setq context-coloring-colorize-idle-timer
+ (run-with-idle-timer
+ time
+ nil
+ #'context-coloring-colorize-with-buffer
+ (current-buffer))))
+
(defun context-coloring-setup-idle-change-detection ()
"Setup idle change detection."
(let ((dispatch (context-coloring-get-dispatch-for-mode major-mode)))
@@ -183,18 +200,19 @@ Supported modes: `js-mode', `js3-mode'"
'after-change-functions #'context-coloring-change-function nil t)
(add-hook
'kill-buffer-hook #'context-coloring-teardown-idle-change-detection nil t)
- (setq context-coloring-colorize-idle-timer
+ (setq context-coloring-maybe-colorize-idle-timer
(run-with-idle-timer
(or (plist-get dispatch :delay) context-coloring-default-delay)
t
- #'context-coloring-maybe-colorize
+ #'context-coloring-maybe-colorize-with-buffer
(current-buffer)))))
(defun context-coloring-teardown-idle-change-detection ()
"Teardown idle change detection."
(context-coloring-cancel-scopification)
- (when context-coloring-colorize-idle-timer
- (cancel-timer context-coloring-colorize-idle-timer))
+ (dolist (timer (list context-coloring-colorize-idle-timer
+ context-coloring-maybe-colorize-idle-timer))
+ (context-coloring-cancel-timer timer))
(remove-hook
'kill-buffer-hook #'context-coloring-teardown-idle-change-detection t)
(remove-hook
@@ -1015,7 +1033,12 @@ scopes and variables."
(forward-line 1))
(end-of-defun)
(point))))
- (context-coloring-elisp-colorize-region-initially start end)))
+ (context-coloring-elisp-colorize-region-initially start end)
+ ;; Fast coloring is nice, but if the code is not well-formed
+ ;; (e.g. an unclosed string literal is parsed at any time) then
+ ;; there could be leftover incorrectly-colored code offscreen.
So
+ ;; do a clean sweep as soon as appropriate.
+ (context-coloring-schedule-coloring
context-coloring-default-delay)))
(t
(context-coloring-elisp-colorize-region-initially (point-min)
(point-max))))
;; Scan errors can happen virtually anywhere if parenthesis are
@@ -1279,6 +1302,13 @@ Invoke CALLBACK when complete; see
`context-coloring-dispatch'."
(when callback (funcall callback))
(run-hooks 'context-coloring-colorize-hook))))
+(defun context-coloring-colorize-with-buffer (buffer)
+ "Color BUFFER."
+ ;; Don't select deleted buffers.
+ (when (get-buffer buffer)
+ (with-current-buffer buffer
+ (context-coloring-colorize))))
+
;;; Versioning
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
index cce22a3..7020589 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -375,7 +375,7 @@ ARGS)."
(funcall done)))
(insert " ")
(set-window-buffer (selected-window) (current-buffer))
- (context-coloring-maybe-colorize (current-buffer))))
+ (context-coloring-maybe-colorize-with-buffer (current-buffer))))
(context-coloring-mode))
:after (lambda ()
(setq context-coloring-colorize-hook nil)))
- [elpa] master 9edc6c3 69/79: Checkdoc cleanup., (continued)
- [elpa] master 9edc6c3 69/79: Checkdoc cleanup., Jackson Ray Hamilton, 2015/06/13
- [elpa] master e2ceef9 57/79: Prepend function symbols with octothorpes., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 22403b7 61/79: Cover parsing edge cases., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 67576b5 72/79: Skip all insignificant expression prefixes., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 306335e 71/79: Add defadvice support., Jackson Ray Hamilton, 2015/06/13
- [elpa] master acf15ae 70/79: Remove if., Jackson Ray Hamilton, 2015/06/13
- [elpa] master ed870d8 68/79: Refactor minor mode definition., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 72a0998 73/79: Add quote and backquote function support., Jackson Ray Hamilton, 2015/06/13
- [elpa] master a4a136c 74/79: Refactor defun / defadvice name handling., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 69ea835 67/79: Refactor elisp parsers using helper functions., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 9b436c0 76/79: Fully recolor later after a fast recolor.,
Jackson Ray Hamilton <=
- [elpa] master 40f67bf 78/79: Version 6.4.0., Jackson Ray Hamilton, 2015/06/13
- [elpa] master c81eecb 58/79: Update function names and docstrings., Jackson Ray Hamilton, 2015/06/13
- [elpa] master f7c6dcb 75/79: Refactor callee dispatching., Jackson Ray Hamilton, 2015/06/13
- [elpa] master fff08de 36/79: Add elisp benchmarks., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 2d96f10 77/79: Merge branch 'elisp', Jackson Ray Hamilton, 2015/06/13
- [elpa] master e2f402c 79/79: Merge commit '40f67bf039c143758ac070f9693bb0af87b98aba' from context-coloring, Jackson Ray Hamilton, 2015/06/13