GNU bug report logs - #66223
treesit-major-mode-setup should not call font-lock-mode

Previous Next

Package: emacs;

Reported by: Dmitry Gutov <dmitry <at> gutov.dev>

Date: Wed, 27 Sep 2023 00:19:02 UTC

Severity: normal

Done: Yuan Fu <casouri <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Dmitry Gutov <dmitry <at> gutov.dev>
Subject: bug#66223: closed (Re: bug#66223: treesit-major-mode-setup should
 not call font-lock-mode)
Date: Mon, 09 Oct 2023 05:05:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

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

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 66223 <at> debbugs.gnu.org.

-- 
66223: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=66223
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Yuan Fu <casouri <at> gmail.com>
To: Dmitry Gutov <dmitry <at> gutov.dev>
Cc: 66223-done <at> debbugs.gnu.org
Subject: Re: bug#66223: treesit-major-mode-setup should not call font-lock-mode
Date: Sun, 8 Oct 2023 22:04:04 -0700

> On Oct 8, 2023, at 4:05 PM, Dmitry Gutov <dmitry <at> gutov.dev> wrote:
> 
> On 09/10/2023 02:03, Yuan Fu wrote:
>> I think we can apply this to emacs-29. Is there anything I should do? Do we just cheery-pick the commit into emac-29, or there are more elaborate operations required?
> 
> As per admin/notes/git-workflow (I'm not sure why it's that far away),
> 
> ...
> cd ~/emacs/emacs-29
> git cherry-pick -xe <commit hash>
> 
> and add "Backport:" to the commit string.  Then
> ...
> 
> Thanks!

Done, thanks.

Yuan
[Message part 3 (message/rfc822, inline)]
From: Dmitry Gutov <dmitry <at> gutov.dev>
To: bug-gnu-emacs <at> gnu.org
Subject: treesit-major-mode-setup should not call font-lock-mode
Date: Wed, 27 Sep 2023 03:17:57 +0300
X-Debbugs-CC: Yuan Fu <casouri <at> 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".



This bug report was last modified 1 year and 227 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.