branch: master commit 4bbce5681327381e34a745a364c45650c0b43e27 Author: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com> Commit: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com>
Add test for interruption. --- context-coloring.el | 18 ++++++++++++++---- test/context-coloring-test.el | 26 ++++++++++++++++++++++++-- test/fixtures/{depth.el => iteration.el} | 0 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 585f325..b8407a5 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -438,6 +438,7 @@ provide visually \"instant\" updates at ~60 frames per second.") (inhibit-point-motion-hooks t) (iteration-count 0) (last-fontified-position (point)) + beginning-of-current-defun end-of-current-defun (end (point-max)) (last-ppss-pos (point)) @@ -485,13 +486,22 @@ provide visually \"instant\" updates at ~60 frames per second.") ;; 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))) + (save-excursion + (end-of-defun) + (setq end-of-current-defun (point)) + (beginning-of-defun) + (setq beginning-of-current-defun (point))) + ;; Fontify in chunks. (context-coloring-maybe-colorize-comments-and-strings last-fontified-position - end-of-current-defun) + (cond + ;; We weren't actually in a defun, so don't color the next one, as + ;; that could result in `font-lock' properties being added to it. + ((> beginning-of-current-defun (point)) + (point)) + (t + end-of-current-defun))) (setq last-fontified-position (point)) (when (and context-coloring-parse-interruptable-p (input-pending-p)) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 7466e23..19f844b 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -236,6 +236,9 @@ environment." (defun context-coloring-test-assert-position-string (position) (context-coloring-test-assert-position-face position 'font-lock-string-face)) +(defun context-coloring-test-assert-position-nil (position) + (context-coloring-test-assert-position-face position nil)) + (defun context-coloring-test-assert-coloring (map) "Assert that the current buffer's coloring matches MAP." ;; Omit the superfluous, formatting-related leading newline. Can't use @@ -268,6 +271,10 @@ environment." ((= char 99) (context-coloring-test-assert-position-constant-comment (point)) (forward-char)) + ;; 'n' = nil + ((= char 110) + (context-coloring-test-assert-position-nil (point)) + (forward-char)) ;; 's' = String ((= char 115) (context-coloring-test-assert-position-string (point)) @@ -1171,13 +1178,28 @@ see that function." 2222 1 1 2 2 2 000022 1111 1 1 1 0 0 000011"))) -(context-coloring-test-deftest-emacs-lisp-mode depth +(defun context-coloring-test-insert-unread-space () + (setq unread-command-events (cons '(t . 32) + unread-command-events))) + +(defun context-coloring-test-remove-faces () + (remove-text-properties (point-min) (point-max) '(face nil))) + +(context-coloring-test-deftest-emacs-lisp-mode iteration (lambda () (let ((context-coloring-emacs-lisp-iterations-per-pause 1)) (context-coloring-colorize) (context-coloring-test-assert-coloring " ;; `cc' `cc' -(xxxxx x ())"))) +(xxxxx x ())") + (context-coloring-test-remove-faces) + (context-coloring-test-insert-unread-space) + (context-coloring-colorize) + ;; The first iteration will color the first part of the comment, but + ;; that's it. Then it will be interrupted. + (context-coloring-test-assert-coloring " +;; nnnn nnnn +nnnnnn n nnn"))) :setup (lambda () (setq context-coloring-syntactic-comments t) (setq context-coloring-syntactic-strings t))) diff --git a/test/fixtures/depth.el b/test/fixtures/iteration.el similarity index 100% rename from test/fixtures/depth.el rename to test/fixtures/iteration.el