emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/tree-sitter 377ee8158b 3/5: Add tresit--font-lock-verbose


From: Yuan Fu
Subject: feature/tree-sitter 377ee8158b 3/5: Add tresit--font-lock-verbose
Date: Mon, 31 Oct 2022 03:24:25 -0400 (EDT)

branch: feature/tree-sitter
commit 377ee8158b2fab3efccb4e9b262e6129b51e28f8
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    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.
---
 lisp/treesit.el | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 4bba221832..4844127509 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -572,6 +572,13 @@ ignored.
                        `("Unexpected value" ,token))))))
       (nreverse result))))
 
+;; `font-lock-fontify-region-function' has the LOUDLY argument, but
+;; `jit-lock-functions' doesn't pass that argument.  So even if we set
+;; `font-lock-verbose' to t, if jit-lock is enabled (and it's almost
+;; always is), we don't get debug messages.  So we add our own.
+(defvar tresit--font-lock-verbose nil
+  "If non-nil, print debug messages when fontifying.")
+
 (defun treesit-font-lock-recompute-features ()
   "Enable/disable font-lock settings according to decoration level.
 Set the ENABLE flag for each setting in
@@ -597,6 +604,8 @@ Set the ENABLE flag for each setting in
     (start end &optional loudly)
   "Fontify the region between START and END.
 If LOUDLY is non-nil, display some debugging information."
+  (when (or loudly tresit--font-lock-verbose)
+    (message "Fontifying region: %s-%s" start end))
   (treesit-update-ranges start end)
   (font-lock-unfontify-region start end)
   (dolist (setting treesit-font-lock-settings)
@@ -644,13 +653,14 @@ If LOUDLY is non-nil, display some debugging information."
                 ;; Don't raise an error if FACE is neither a face nor
                 ;; a function.  This is to allow intermediate capture
                 ;; names used for #match and #eq.
-                (when loudly
+                (when (or loudly tresit--font-lock-verbose)
                   (message "Fontifying text from %d to %d, Face: %s Language: 
%s"
                            start end face language)))))))))
   ;; Call regexp font-lock after tree-sitter, as it is usually used
   ;; for custom fontification.
   (let ((font-lock-unfontify-region-function #'ignore))
-    (funcall #'font-lock-default-fontify-region start end loudly)))
+    (funcall #'font-lock-default-fontify-region start end loudly))
+  `(jit-lock-bounds ,start . ,end))
 
 (defun treesit-font-lock-enable ()
   "Enable tree-sitter font-locking for the current buffer."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]