]> code.delx.au - gnu-emacs-elpa/commitdiff
Improve and test lazy coloring.
authorJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Sun, 7 Jun 2015 08:01:24 +0000 (01:01 -0700)
committerJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Sun, 7 Jun 2015 08:01:24 +0000 (01:01 -0700)
context-coloring.el
test/context-coloring-test.el
test/fixtures/changed.el [new file with mode: 0644]

index 0d860ac3ef45905859e8c237a990e1aed21a17bf..b57cfb3419f291b22b3483fa528674c07a1df635 100644 (file)
@@ -951,12 +951,20 @@ scopes and variables."
       (cond
        ;; Just colorize the changed region.
        (context-coloring-changed-p
-        (let ((start (progn (goto-char context-coloring-changed-start)
-                            (beginning-of-defun)
-                            (point)))
-              (end (progn (goto-char context-coloring-changed-end)
-                          (end-of-defun)
-                          (point))))
+        (let* (;; Prevent `beginning-of-defun' from making poor assumptions.
+               (open-paren-in-column-0-is-defun-start nil)
+               ;; Seek the beginning and end of the previous and next offscreen
+               ;; defuns, so just enough is colored.
+               (start (progn (goto-char context-coloring-changed-start)
+                             (while (and (< (point-min) (point))
+                                         (pos-visible-in-window-p))
+                               (beginning-of-defun))
+                             (point)))
+               (end (progn (goto-char context-coloring-changed-end)
+                           (while (and (> (point-max) (point))
+                                       (pos-visible-in-window-p))
+                             (end-of-defun))
+                           (point))))
           (context-coloring-elisp-colorize-region-initially start end)))
        (t
         (context-coloring-elisp-colorize-region-initially (point-min) (point-max)))))))
index 0d226baa571ee6f9f52b2f99fdffd12cc80c315e..deb40fb0de11009a4771db4f1fc84eac8c27340e 100644 (file)
@@ -25,6 +25,7 @@
 
 ;;; Code:
 
+(require 'cl-lib)
 (require 'context-coloring)
 (require 'ert-async)
 (require 'js2-mode)
@@ -1214,6 +1215,36 @@ cc `CC' `CC'
 cc `CC' `CC'
 nnnnnn n nnn"))))
 
+(context-coloring-test-deftest-emacs-lisp changed
+  (lambda ()
+    (context-coloring-test-remove-faces)
+    ;; Goto line 3.
+    (goto-char (point-min))
+    (forward-line (1- 3))
+    (insert " ")
+    ;; Mock `pos-visible-in-window-p' because in batch mode `get-buffer-window'
+    ;; returns nil.  Emacs must not have a window in that environment.
+    (cl-letf (((symbol-function 'pos-visible-in-window-p)
+               (let ((calls 0))
+                 (lambda ()
+                   (prog1
+                       ;; First and third calls start from center.  Second and
+                       ;; fourth calls are made immediately after moving past
+                       ;; the first defun in either direction "off screen".
+                       (cond
+                        ((= calls 0) t)
+                        ((= calls 1) nil)
+                        ((= calls 2) t)
+                        ((= calls 4) nil))
+                     (setq calls (1+ calls)))))))
+      (context-coloring-colorize))
+    (context-coloring-test-assert-coloring "
+nnnn  n nnn nnnnnnnn
+0000
+
+0000
+nnnnn n nnn nnnnnnnn")))
+
 (provide 'context-coloring-test)
 
 ;;; context-coloring-test.el ends here
diff --git a/test/fixtures/changed.el b/test/fixtures/changed.el
new file mode 100644 (file)
index 0000000..28c9602
--- /dev/null
@@ -0,0 +1,5 @@
+(l1)  ; Not colored.
+(l2)
+
+(l4)
+(l5)  ; Not colored.