[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 3e778f6 18/21: Merge pull request #6 from jacksonrayhamilt
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 3e778f6 18/21: Merge pull request #6 from jacksonrayhamilton/narrow-to-region |
Date: |
Fri, 23 Dec 2016 20:27:52 +0000 (UTC) |
branch: master
commit 3e778f607e72cc5dee7a4f1aa445d6780b8cc1dd
Merge: 45b5ad0 ce29abd
Author: Jackson Ray Hamilton <address@hidden>
Commit: GitHub <address@hidden>
Merge pull request #6 from jacksonrayhamilton/narrow-to-region
Don't color before or beyond the buffer.
---
context-coloring-javascript.el | 23 +++++++++++++++--------
context-coloring-test.el | 9 +++++++++
fixtures/test/narrow-to-region.js | 3 +++
3 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/context-coloring-javascript.el b/context-coloring-javascript.el
index d145184..29bafb8 100644
--- a/context-coloring-javascript.el
+++ b/context-coloring-javascript.el
@@ -73,26 +73,33 @@ this for ES6 code; disable it elsewhere."
;; `js2-prop-get-node', so this always works.
(eq node (js2-prop-get-node-right parent))))))))
+(defvar-local context-coloring-point-min nil
+ "Cached value of `point-min'.")
+
(defvar-local context-coloring-point-max nil
"Cached value of `point-max'.")
+(defsubst context-coloring-js2-bounded-point (point)
+ "Make POINT safe to set text properties.
+POINT may be unsafe if a JS2 node extends beyond the end of the
+buffer (in the case of an unterminated multiline comment). The
+region could also be narrowed and the node thus obscured."
+ (min (max point context-coloring-point-min) context-coloring-point-max))
+
(defsubst context-coloring-js2-colorize-node (node level)
"Color NODE with the color for LEVEL."
- (let ((start (js2-node-abs-pos node)))
+ (let* ((start (js2-node-abs-pos node))
+ (end (+ start (js2-node-len node))))
(context-coloring-colorize-region
- start
- (min
- ;; End
- (+ start (js2-node-len node))
- ;; Somes nodes (like the ast when there is an unterminated multiline
- ;; comment) will stretch to the value of `point-max'.
- context-coloring-point-max)
+ (context-coloring-js2-bounded-point start)
+ (context-coloring-js2-bounded-point end)
level)))
(defun context-coloring-js2-colorize-ast ()
"Color the buffer using the `js2-mode' abstract syntax tree."
;; Reset the hash table; the old one could be obsolete.
(setq context-coloring-js2-scope-level-hash-table (make-hash-table :test
#'eq))
+ (setq context-coloring-point-min (point-min))
(setq context-coloring-point-max (point-max))
(with-silent-modifications
(js2-visit-ast
diff --git a/context-coloring-test.el b/context-coloring-test.el
index 0d1f539..32080bb 100644
--- a/context-coloring-test.el
+++ b/context-coloring-test.el
@@ -663,6 +663,15 @@ ssssssssssss0"))
(context-coloring-test-assert-javascript-global-level))))
:fixture "initial-level.js")
+(context-coloring-test-deftest-javascript narrow-to-region
+ (lambda ()
+ (context-coloring-test-assert-coloring "
+1111111 0 11 11
+11111111 0 11 11
+11111111 0 11 1"))
+ :before (lambda ()
+ (narrow-to-region (+ (point-min) 1) (- (point-max) 2))))
+
(context-coloring-test-deftest-emacs-lisp defun
(lambda ()
(context-coloring-test-assert-coloring "
diff --git a/fixtures/test/narrow-to-region.js
b/fixtures/test/narrow-to-region.js
new file mode 100644
index 0000000..29f9aef
--- /dev/null
+++ b/fixtures/test/narrow-to-region.js
@@ -0,0 +1,3 @@
+function a () {}
+function b () {}
+function c () {}
- [elpa] master updated (580a1b6 -> 5402f35), Jackson Ray Hamilton, 2016/12/23
- [elpa] master 60fca70 03/21: Fix quoting problem in docstring., Jackson Ray Hamilton, 2016/12/23
- [elpa] master 6a2c6fe 04/21: Clean up local variable., Jackson Ray Hamilton, 2016/12/23
- [elpa] master c79499a 02/21: Remove erroneous block scope assertion., Jackson Ray Hamilton, 2016/12/23
- [elpa] master 2de2dd8 12/21: Make binaries configurable in Makefile., Jackson Ray Hamilton, 2016/12/23
- [elpa] master 3e778f6 18/21: Merge pull request #6 from jacksonrayhamilton/narrow-to-region,
Jackson Ray Hamilton <=
- [elpa] master 26f48c5 06/21: Improve Font Lock integration., Jackson Ray Hamilton, 2016/12/23
- [elpa] master c847b0f 01/21: Mention tern-context-coloring in README., Jackson Ray Hamilton, 2016/12/23
- [elpa] master 54593e5 11/21: Add Emacs 25.1 to the build matrix., Jackson Ray Hamilton, 2016/12/23
- [elpa] master abded5f 14/21: Check for compositions on old Emacsen., Jackson Ray Hamilton, 2016/12/23
- [elpa] master 269a382 15/21: Ensure coloring still works after prettification., Jackson Ray Hamilton, 2016/12/23
- [elpa] master b3ea138 19/21: Remove no-byte-compile from development files., Jackson Ray Hamilton, 2016/12/23
- [elpa] master ce29abd 17/21: Don't color before or beyond the buffer., Jackson Ray Hamilton, 2016/12/23
- [elpa] master 45b5ad0 16/21: Merge pull request #5 from jacksonrayhamilton/prettify-symbols, Jackson Ray Hamilton, 2016/12/23
- [elpa] master 5fe3695 07/21: Revert "Clean up local variable.", Jackson Ray Hamilton, 2016/12/23
- [elpa] master 550e61b 08/21: Merge branch 'master' into prettify-symbols, Jackson Ray Hamilton, 2016/12/23