aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorYuan Fu2022-10-30 20:56:21 -0700
committerYuan Fu2022-10-30 20:56:21 -0700
commit377ee8158b2fab3efccb4e9b262e6129b51e28f8 (patch)
tree92d3d761e722862aafc725f201c160f1bfe4cadf /lisp
parent52c8fdde1667ac4b5d7f2af5eff94d6512d83caa (diff)
downloademacs-377ee8158b2fab3efccb4e9b262e6129b51e28f8.tar.gz
emacs-377ee8158b2fab3efccb4e9b262e6129b51e28f8.zip
Add tresit--font-lock-verbose
* lisp/treesit.el (tresit--font-lock-verbose): New variable. (treesit-font-lock-fontify-region): Take tresit--font-lock-verbose into account. Return jit-lock-bounds.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/treesit.el14
1 files changed, 12 insertions, 2 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 4bba2218327..48441275092 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -572,6 +572,13 @@ ignored.
572 `("Unexpected value" ,token)))))) 572 `("Unexpected value" ,token))))))
573 (nreverse result)))) 573 (nreverse result))))
574 574
575;; `font-lock-fontify-region-function' has the LOUDLY argument, but
576;; `jit-lock-functions' doesn't pass that argument. So even if we set
577;; `font-lock-verbose' to t, if jit-lock is enabled (and it's almost
578;; always is), we don't get debug messages. So we add our own.
579(defvar tresit--font-lock-verbose nil
580 "If non-nil, print debug messages when fontifying.")
581
575(defun treesit-font-lock-recompute-features () 582(defun treesit-font-lock-recompute-features ()
576 "Enable/disable font-lock settings according to decoration level. 583 "Enable/disable font-lock settings according to decoration level.
577Set the ENABLE flag for each setting in 584Set the ENABLE flag for each setting in
@@ -597,6 +604,8 @@ Set the ENABLE flag for each setting in
597 (start end &optional loudly) 604 (start end &optional loudly)
598 "Fontify the region between START and END. 605 "Fontify the region between START and END.
599If LOUDLY is non-nil, display some debugging information." 606If LOUDLY is non-nil, display some debugging information."
607 (when (or loudly tresit--font-lock-verbose)
608 (message "Fontifying region: %s-%s" start end))
600 (treesit-update-ranges start end) 609 (treesit-update-ranges start end)
601 (font-lock-unfontify-region start end) 610 (font-lock-unfontify-region start end)
602 (dolist (setting treesit-font-lock-settings) 611 (dolist (setting treesit-font-lock-settings)
@@ -644,13 +653,14 @@ If LOUDLY is non-nil, display some debugging information."
644 ;; Don't raise an error if FACE is neither a face nor 653 ;; Don't raise an error if FACE is neither a face nor
645 ;; a function. This is to allow intermediate capture 654 ;; a function. This is to allow intermediate capture
646 ;; names used for #match and #eq. 655 ;; names used for #match and #eq.
647 (when loudly 656 (when (or loudly tresit--font-lock-verbose)
648 (message "Fontifying text from %d to %d, Face: %s Language: %s" 657 (message "Fontifying text from %d to %d, Face: %s Language: %s"
649 start end face language))))))))) 658 start end face language)))))))))
650 ;; Call regexp font-lock after tree-sitter, as it is usually used 659 ;; Call regexp font-lock after tree-sitter, as it is usually used
651 ;; for custom fontification. 660 ;; for custom fontification.
652 (let ((font-lock-unfontify-region-function #'ignore)) 661 (let ((font-lock-unfontify-region-function #'ignore))
653 (funcall #'font-lock-default-fontify-region start end loudly))) 662 (funcall #'font-lock-default-fontify-region start end loudly))
663 `(jit-lock-bounds ,start . ,end))
654 664
655(defun treesit-font-lock-enable () 665(defun treesit-font-lock-enable ()
656 "Enable tree-sitter font-locking for the current buffer." 666 "Enable tree-sitter font-locking for the current buffer."