Subject: Re: bug#77255: Treesit font-lock override for embed ranges

From: Juri Linkov <[email-masked]>
Date: Wed, 09 Apr 2025 20:31:28 +0300

BTW, for testing multi-parser ranges I used such a trick that
highlights different ranges using different background colors from hi-lock.
Maybe something like this could be added to 'treesit-explore-mode'
or 'treesit-inspect-mode':

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 8e57a6dae14..5a2721cdda4 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -1036,6 +1026,9 @@ treesit--update-ranges-non-local
                   (overlay-put ov 'treesit-parser embed-parser)
                   (overlay-put ov 'treesit-parser-local-p nil)
                   (overlay-put ov 'treesit-host-parser host-parser)
+                  ;; (overlay-put ov 'font-lock-face (nth embed-level hi-lock-face-defaults))
+                  (overlay-put ov 'font-lock-face (nth (length (memq embed-parser (treesit-parser-list))) hi-lock-face-defaults))
+                  (overlay-put ov 'priority (+ 1000 embed-level))
                   (overlay-put ov 'treesit-parser-ov-timestamp
                                modified-tick)))))
           ;; Set ranges for the embed parser.
@@ -1130,6 +1123,9 @@ treesit--update-ranges-local
                 (treesit-parser-set-embed-level embedded-parser embed-level)
                 (overlay-put ov 'treesit-parser embedded-parser)
                 (overlay-put ov 'treesit-parser-local-p t)
+                ;; (overlay-put ov 'font-lock-face (nth embed-level hi-lock-face-defaults))
+                (overlay-put ov 'font-lock-face (nth (length (memq embedded-parser (treesit-parser-list))) hi-lock-face-defaults))
+                (overlay-put ov 'priority (+ 1000 embed-level))
                 (overlay-put ov 'treesit-host-parser host-parser)
                 (overlay-put ov 'treesit-parser-ov-timestamp
                              modified-tick)