bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#66223: treesit-major-mode-setup should not call font-lock-mode


From: Yuan Fu
Subject: bug#66223: treesit-major-mode-setup should not call font-lock-mode
Date: Wed, 27 Sep 2023 00:21:16 -0700


> On Sep 26, 2023, at 5:17 PM, Dmitry Gutov <dmitry@gutov.dev> wrote:
> 
> X-Debbugs-CC: Yuan Fu <casouri@gmail.com>
> 
> It doesn't seem necessary (everything seems to work okay without that call), 
> and it's not the right thing idiomatically (the user should have the ability 
> to disable global-font-lock-mode).
> 
> If it does get called, the call to treesit-font-lock-recompute-features 
> should happen before that.
> 
> The report was triggered by somewhat unusual circumstances (somebody trying 
> out mmm-mode together with typescript-ts-mode: 
> https://github.com/dgutov/mmm-mode/issues/138), but the fix seems easy and 
> natural enough.
> 
> To reproduce the bug, though, try this:
> 
> (with-current-buffer (generate-new-buffer "foo")
>  (let (font-lock-support-mode)
>    (typescript-ts-mode)))
> 
> It results in
> 
> Debugger entered--Lisp error: (treesit-query-error "Node type error at" 2 
> "(jsx_opening_element [(nested_identifier (identifier)) (identifier)] 
> @typescript-ts-jsx-tag-face) (jsx_closing_element [(nested_identifier 
> (identifier)) (identifier)] @typescript-ts-jsx-tag-face) 
> (jsx_self_closing_element [(nested_identifier (identifier)) (identifier)] 
> @typescript-ts-jsx-tag-face) (jsx_attribute (property_identifier) 
> @typescript-ts-jsx-attribute-face)" "Debug the query with 
> `treesit-query-validate'")
>  treesit-query-capture(#<treesit-node program in 1-1> 
> #<treesit-compiled-query> 1 1)
>  (let* ((delta-start ...
>  treesit--font-lock-fontify-region-1(#<treesit-node program in 1-1> 
> #<treesit-compiled-query> 1 1 nil nil)
>  (let ((sub-node (car tail)))...
>  treesit-font-lock-fontify-region(1 1 nil)
>  font-lock-fontify-syntactically-region(1 1 nil)
>  font-lock-default-fontify-region(1 1 nil)
>  font-lock-fontify-region(1 1 nil)
>  font-lock-default-fontify-buffer()
>  font-lock-fontify-buffer()
>  font-lock-initial-fontify()
>  font-lock-mode(1)
>  (progn (set (make-lo...
>  treesit-major-mode-setup()
>  typescript-ts-mode()
> 
> because typescript-ts-mode's treesit-font-lock-settings hide the jsx rule 
> (which the typescript grammar itself doesn't support, only the tsx one does) 
> using the absence of that feature in treesit-font-lock-feature-list. But for 
> that to take effect, the call to 'treesit-font-lock-recompute-features' needs 
> to happen first. The jit-lock conceals the problem by inhibiting the first 
> fontification until the major mode function has run and the buffer is 
> visible. I ended up disabling it in mmm-mode's auxiliary temp buffer because 
> it spams the message "Not enabling jit-lock: it does not work in indirect 
> buffer”.

Makes sense. We can remove that line in master, and see if anything comes up. I 
don’t remember why I added it, I don’t think there was any particular reason.

Yuan




reply via email to

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