]> code.delx.au - gnu-emacs-elpa/commitdiff
Swallow scan errors.
authorJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Sun, 7 Jun 2015 08:14:35 +0000 (01:14 -0700)
committerJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Sun, 7 Jun 2015 08:14:35 +0000 (01:14 -0700)
context-coloring.el
test/context-coloring-test.el
test/fixtures/unbalanced-parenthesis.el [new file with mode: 0644]

index b57cfb3419f291b22b3483fa528674c07a1df635..d296f0d217426b1aa7b078ece839ff2411a411dd 100644 (file)
@@ -948,26 +948,30 @@ scopes and variables."
   (interactive)
   (with-silent-modifications
     (save-excursion
-      (cond
-       ;; Just colorize the changed region.
-       (context-coloring-changed-p
-        (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)))))))
+      (condition-case nil
+          (cond
+           ;; Just colorize the changed region.
+           (context-coloring-changed-p
+            (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))))
+        ;; Scan errors can happen virtually anywhere if parenthesis are
+        ;; unbalanced.  Just swallow them.  (`progn' for test coverage.)
+        (scan-error (progn))))))
 
 
 ;;; Shell command scopification / colorization
index deb40fb0de11009a4771db4f1fc84eac8c27340e..95a081d6e61cf664900f5f49a1492e01cdcdb537 100644 (file)
@@ -1245,6 +1245,12 @@ nnnn  n nnn nnnnnnnn
 0000
 nnnnn n nnn nnnnnnnn")))
 
+(context-coloring-test-deftest-emacs-lisp unbalanced-parenthesis
+  (lambda ()
+    (context-coloring-test-assert-coloring "
+1111 111
+nnnn nn")))
+
 (provide 'context-coloring-test)
 
 ;;; context-coloring-test.el ends here
diff --git a/test/fixtures/unbalanced-parenthesis.el b/test/fixtures/unbalanced-parenthesis.el
new file mode 100644 (file)
index 0000000..caaf7e2
--- /dev/null
@@ -0,0 +1,2 @@
+(let ())
+(let ()