[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 89f20e4 28/47: Improve interruptability of syntactic color
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 89f20e4 28/47: Improve interruptability of syntactic coloring. |
Date: |
Mon, 18 May 2015 09:51:56 +0000 |
branch: master
commit 89f20e43358e92caa0a6232f9699aea89a362f1c
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Improve interruptability of syntactic coloring.
---
context-coloring.el | 52 +++++++++++++++++++++++++++++++-------------------
1 files changed, 32 insertions(+), 20 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index d1c2d52..f21b323 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -172,6 +172,8 @@ the END point (exclusive) with the face corresponding to
LEVEL."
"Tell `font-lock' to color a string but not a comment."
(if (nth 3 state) font-lock-string-face nil))
+;; TODO: Add specialized emacs-lisp version based on
+;; `lisp-font-lock-syntactic-face-function'.
(defsubst context-coloring-maybe-colorize-comments-and-strings (&optional min
max)
"Color the current buffer's comments and strings if
`context-coloring-comments-and-strings' is non-nil."
@@ -415,7 +417,7 @@ As of this writing, emacs lisp colorization seems to run at
about
60,000 iterations per second. A default value of 1000 should
provide visually \"instant\" updates at ~60 frames per second.")
-(defvar context-coloring-verbose-parse t
+(defvar context-coloring-verbose-parse nil
"Log useful information pertaining to a parse.")
(defun context-coloring-emacs-lisp-colorize ()
@@ -427,6 +429,8 @@ provide visually \"instant\" updates at ~60 frames per
second.")
(let* ((start-time (float-time))
(inhibit-point-motion-hooks t)
(iteration-count 0)
+ (last-fontified-position (point))
+ end-of-current-defun
(end (point-max))
(last-ppss-pos (point))
(ppss (syntax-ppss))
@@ -466,11 +470,25 @@ provide visually \"instant\" updates at ~60 frames per
second.")
child-2-end)
(while (> end (progn (skip-syntax-forward "^()w_'" end)
(point)))
- (and context-coloring-parse-interruptable-p
- (zerop (% (setq iteration-count (1+ iteration-count))
- context-coloring-emacs-lisp-iterations-per-pause))
- (input-pending-p)
- (throw 'interrupted t))
+ ;; Sparingly-executed tasks.
+ (setq iteration-count (1+ iteration-count))
+ (when (zerop (% iteration-count
+ context-coloring-emacs-lisp-iterations-per-pause))
+ ;; Fontify until the end of the current defun because doing it in
+ ;; chunks based soley on point could result in partial
+ ;; re-fontifications over the contents of scopes.
+ (setq end-of-current-defun (save-excursion
+ (end-of-defun)
+ (point)))
+ ;; Fontify in chunks.
+ (context-coloring-maybe-colorize-comments-and-strings
+ last-fontified-position
+ end-of-current-defun)
+ (setq last-fontified-position end-of-current-defun)
+ (when (and context-coloring-parse-interruptable-p
+ (input-pending-p))
+ (throw 'interrupted t)))
+
(setq token-pos (point))
(setq token-syntax (syntax-after token-pos))
(setq token-syntax-code (logand #xFFFF (car token-syntax)))
@@ -701,10 +719,13 @@ provide visually \"instant\" updates at ~60 frames per
second.")
(setq popped-vars (cdr popped-vars))))
))
+ ;; Fontify the last stretch.
+ (context-coloring-maybe-colorize-comments-and-strings
+ last-fontified-position
+ (point))
(when context-coloring-verbose-parse
(message "Elapsed: %s; iterations: %s"
- (- (float-time) start-time) iteration-count))))
- (context-coloring-maybe-colorize-comments-and-strings)))
+ (- (float-time) start-time) iteration-count))))))
;;; Shell command scopification / colorization
@@ -847,11 +868,7 @@ should be numeric, e.g. \"2\", \"19700101\", \"1.2.3\",
`context-coloring-mode' is enabled.
`:teardown' - Arbitrary code to tear down this dispatch when
-`context-coloring-mode' is disabled.
-
-`:interrupt' - Arbitrary code to run if parsing or coloring is
-interrupted (for synchronous strategies like `:colorizer' and
-`:scopifier')."
+`context-coloring-mode' is disabled."
(let ((modes (plist-get properties :modes))
(colorizer (plist-get properties :colorizer))
(scopifier (plist-get properties :scopifier))
@@ -1346,10 +1363,6 @@ Supported modes: `js-mode', `js3-mode'"
'emacs-lisp
:modes '(emacs-lisp-mode)
:colorizer 'context-coloring-emacs-lisp-colorize
- ;; Comments and strings aren't colored till the end so it can be pretty ugly
if
- ;; you interrupt too far down the buffer. TODO: Still not very satisfying,
- ;; seeing flashes of uncolored code occassionally.
- :interrupt 'context-coloring-maybe-colorize-comments-and-strings
:setup
(lambda ()
(context-coloring-setup-idle-change-detection))
@@ -1370,7 +1383,6 @@ elisp tracks, and asynchronously for shell command
tracks."
(colorizer (plist-get dispatch :colorizer))
(scopifier (plist-get dispatch :scopifier))
(command (plist-get dispatch :command))
- (interrupt (plist-get dispatch :interrupt))
interrupted-p)
(cond
((or colorizer scopifier)
@@ -1383,7 +1395,6 @@ elisp tracks, and asynchronously for shell command
tracks."
(context-coloring-apply-tokens (funcall scopifier))))))
(cond
(interrupted-p
- (when interrupt (funcall interrupt))
(setq context-coloring-changed t))
(t
(when callback (funcall callback)))))
@@ -1455,7 +1466,8 @@ elisp tracks, and asynchronously for shell command
tracks."
(funcall setup))
;; Colorize once initially.
(when colorize-initially-p
- (context-coloring-colorize))))
+ (let ((context-coloring-parse-interruptable-p nil))
+ (context-coloring-colorize)))))
(when (null dispatch)
(message "Context coloring is not available for this major
mode"))))))
- [elpa] master ea3ff31 16/47: Pass let* test., (continued)
- [elpa] master ea3ff31 16/47: Pass let* test., Jackson Ray Hamilton, 2015/05/18
- [elpa] master b28e896 19/47: Add complex nesting to let test., Jackson Ray Hamilton, 2015/05/18
- [elpa] master bd9c147 20/47: Ignore the dot., Jackson Ray Hamilton, 2015/05/18
- [elpa] master d7b2c92 21/47: Remove unused functions., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 0836b9f 22/47: Add change hooks for elisp., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 08bf3e4 23/47: Ignore question marks., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 09ec36e 24/47: Add interruption mechanism., Jackson Ray Hamilton, 2015/05/18
- [elpa] master dc2f9a6 25/47: Refactor maybe-colorize-comments-and-strings., Jackson Ray Hamilton, 2015/05/18
- [elpa] master a556195 26/47: Tweak iteration values, add logging., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 3fc5b20 27/47: Make dispatches fully redefinable., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 89f20e4 28/47: Improve interruptability of syntactic coloring.,
Jackson Ray Hamilton <=
- [elpa] master d24de46 31/47: Add TODO., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 07c5852 30/47: Add idle change teardown function., Jackson Ray Hamilton, 2015/05/18
- [elpa] master ef544ef 29/47: Fontify keywords., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 5c5b429 32/47: Fix font-lock error., Jackson Ray Hamilton, 2015/05/18
- [elpa] master c0a6689 33/47: Only set defaults when the mode is enabled., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 59a6c8e 34/47: Fix timer disposal and timer buffer detection., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 88a921f 35/47: Improve defun regexp., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 438cb33 36/47: Fix incorrect last fontified position., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 1d7761c 37/47: Add constant comment test., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 4ff6e82 39/47: Remove verbose parsing., Jackson Ray Hamilton, 2015/05/18