]> git.eshelyaron.com Git - emacs.git/commitdiff
Don't always filter out captured tree-sitter nodes outside of region
authorYuan Fu <casouri@gmail.com>
Wed, 23 Nov 2022 23:20:19 +0000 (15:20 -0800)
committerYuan Fu <casouri@gmail.com>
Thu, 24 Nov 2022 03:48:28 +0000 (19:48 -0800)
* lisp/treesit.el (treesit-font-lock-fontify-region): If the capture
name is a function, don't filter.

lisp/treesit.el

index 3140358167c6c007502db4d645b9bdf47378080b..73a499bfa9596b92bbf69453ac284ce0f997bbe4 100644 (file)
@@ -912,12 +912,17 @@ If LOUDLY is non-nil, display some debugging information."
                        (node (cdr capture))
                        (node-start (treesit-node-start node))
                        (node-end (treesit-node-end node)))
-                  ;; Turns out it is possible to capture a node that's
+                  ;; It is possible to capture a node that's
                   ;; completely outside the region between START and
-                  ;; END.  If the node is outside of that region, (max
-                  ;; node-start start) and friends return bad values.
-                  (when (and (< start node-end)
-                             (< node-start end))
+                  ;; END: as long as the whole pattern intersects the
+                  ;; region, all the captured nodes in that pattern
+                  ;; are returned.  If the node is outside of that
+                  ;; region, (max node-start start) and friends return
+                  ;; bad values.
+                  (if (and (facep face) (or (>= start node-end)
+                                            (>= node-start end)))
+                      (when (or loudly treesit--font-lock-verbose)
+                        (message "Captured node %s(%s-%s) but it is outside of fontifing region" node node-start node-end))
                     (cond
                      ((facep face)
                       (treesit-fontify-with-override