[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 09ec36e 24/47: Add interruption mechanism.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 09ec36e 24/47: Add interruption mechanism. |
Date: |
Mon, 18 May 2015 09:51:54 +0000 |
branch: master
commit 09ec36ebac10776a5982dd220ad9b6d8fd678579
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Add interruption mechanism.
---
context-coloring.el | 57 ++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 45 insertions(+), 12 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index 2c5f44b..940b90d 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -407,6 +407,15 @@ generated by `js2-mode'."
(defconst context-coloring-COMMA-CHAR 44)
(defconst context-coloring-BACKTICK-CHAR 96)
+(defvar context-coloring-parse-interruptable-p t
+ "Set this to nil to force parse to continue until finished.")
+
+(defvar context-coloring-tokens-per-pause 25
+ "Pause after this many statements to check for user input.
+If user input is pending, stop the parse. This makes for a
+smoother user experience for large files. This appears to be
+more or less how Eclipse, IntelliJ and other editors work.")
+
(defun context-coloring-emacs-lisp-colorize ()
"Color the current buffer by parsing emacs lisp sexps."
(with-silent-modifications
@@ -414,6 +423,7 @@ generated by `js2-mode'."
;; TODO: Can probably make this lazy to the nearest defun.
(goto-char (point-min))
(let* ((inhibit-point-motion-hooks t)
+ (token-count 0)
(end (point-max))
(last-ppss-pos (point))
(ppss (syntax-ppss))
@@ -453,6 +463,11 @@ generated by `js2-mode'."
child-2-end)
(while (> end (progn (skip-syntax-forward "^()w_'" end)
(point)))
+ (and context-coloring-parse-interruptable-p
+ (zerop (% (setq token-count (1+ token-count))
+ context-coloring-tokens-per-pause))
+ (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)))
@@ -826,7 +841,11 @@ 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."
+`context-coloring-mode' is disabled.
+
+`:interrupt' - Arbitrary code to run if parsing or coloring is
+interrupted (for synchronous strategies like `:colorizer' and
+`:scopifier')."
(let ((modes (plist-get properties :modes))
(colorizer (plist-get properties :colorizer))
(scopifier (plist-get properties :scopifier))
@@ -1322,6 +1341,10 @@ 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))
@@ -1338,18 +1361,28 @@ the current buffer, then execute it.
Invoke CALLBACK when complete. It is invoked synchronously for
elisp tracks, and asynchronously for shell command tracks."
- (let ((dispatch (gethash major-mode context-coloring-mode-hash-table))
- colorizer
- scopifier
- command)
+ (let* ((dispatch (gethash major-mode context-coloring-mode-hash-table))
+ (colorizer (plist-get dispatch :colorizer))
+ (scopifier (plist-get dispatch :scopifier))
+ (command (plist-get dispatch :command))
+ (interrupt (plist-get dispatch :interrupt))
+ interrupted-p)
(cond
- ((setq colorizer (plist-get dispatch :colorizer))
- (funcall colorizer)
- (when callback (funcall callback)))
- ((setq scopifier (plist-get dispatch :scopifier))
- (context-coloring-apply-tokens (funcall scopifier))
- (when callback (funcall callback)))
- ((setq command (plist-get dispatch :command))
+ ((or colorizer scopifier)
+ (setq interrupted-p
+ (catch 'interrupted
+ (cond
+ (colorizer
+ (funcall colorizer))
+ (scopifier
+ (context-coloring-apply-tokens (funcall scopifier))))))
+ (cond
+ (interrupted-p
+ (when interrupt (funcall interrupt))
+ (setq context-coloring-changed t))
+ (t
+ (when callback (funcall callback)))))
+ (command
(context-coloring-scopify-and-colorize command callback)))))
- [elpa] master c830ae5 15/47: Fix let* test., (continued)
- [elpa] master c830ae5 15/47: Fix let* test., Jackson Ray Hamilton, 2015/05/18
- [elpa] master b4072c1 14/47: Trivial refactoring for clarity., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 926d74a 17/47: Include binding order in let* test., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 29328af 18/47: Add let test., Jackson Ray Hamilton, 2015/05/18
- [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 <=
- [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, 2015/05/18
- [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