[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Initial fontification in sh-mode with tree-sittter
From: |
Yuan Fu |
Subject: |
Re: Initial fontification in sh-mode with tree-sittter |
Date: |
Mon, 31 Oct 2022 14:56:02 -0700 |
> On Oct 30, 2022, at 7:13 PM, Yuan Fu <casouri@gmail.com> wrote:
>
>
>
>> On Oct 28, 2022, at 8:09 AM, Daniel Martín <mardani29@yahoo.es> wrote:
>>
>> Yuan Fu <casouri@gmail.com> writes:
>>
>>>
>>> Hmmm, I couldn’t reproduce this in python-mode, also defun is not
>>> recognized in python so I used this snippet:
>>>
>>> def foo():
>>> Return 42
>>>
>>> When I insert “”” before the defun, everything after becomes string face,
>>> when I insert the following “””, everything is updated again.
>>>
>>> I didn’t make any significant change to the font-lock code recently, either.
>>>
>>
>> I can reproduce the problem by following these steps:
>>
>> emacs -Q from top of the feature/tree-sitter branch
>> M-: (require 'treesit)
>> M-x customize-variable treesit-settings RET
>> Set "Activate" to "Yes" and apply the change.
>> C-x b sample.py RET
>> M-x python-mode
>> Write the following program:
>>
>> def main():
>> return 0
>>
>> M-< C-o """ (the code is not fontified as string)
>> M-> """ (the code is not fontified as string)
>> M-x python-mode RET (the code _is_ fontified as string)
>
> Thanks, I can reproduce this on emacs -Q, too (but strangely not on my
> “configured” Emacs).
>
>>
>> A git bisect tells that the first bad commit is
>> 5159789e55d64c7482dff3dc1a621d01f530f83c
>
> Strange, this commit has nothing to do with font-lock, hmm...
>
>>
>> Hope this helps.
>
> Yes! Many thanks.
>
> Yuan
I think I’ve fixed this problem. It is mainly due to how the fortifications
rule is written. When the starting quotes are inserted, normal syntactic
font-lock will mark everything behind it in string-face, but for tree-sitter,
since the source is incomplete, the quotes are in an error node in the parse
tree and there is no string node, so tree-sitter rules can’t capture any string
node, so no string face is applied. And when the ending quotes are inserted,
the only region jit-lock wants tree-sitter to fontify is that three quote, so
again the whole string is not captured. I changed the font-lock rule to match
the ending quote rather than the whole string, and now it’s working fine.
Now it is actually better than before: If you insert an open quote, the rest of
the buffer will not be marked in string face, instead, and when you insert the
ending quote, the string is fontified correctly.
Yuan
- Initial fontification in sh-mode with tree-sittter, João Paulo Labegalini de Carvalho, 2022/10/27
- Re: Initial fontification in sh-mode with tree-sittter, João Paulo Labegalini de Carvalho, 2022/10/27
- Re: Initial fontification in sh-mode with tree-sittter, João Paulo Labegalini de Carvalho, 2022/10/27
- Re: Initial fontification in sh-mode with tree-sittter, Yuan Fu, 2022/10/28
- Re: Initial fontification in sh-mode with tree-sittter, Daniel Martín, 2022/10/28
- Re: Initial fontification in sh-mode with tree-sittter, Yuan Fu, 2022/10/30
- Re: Initial fontification in sh-mode with tree-sittter,
Yuan Fu <=
- Re: Initial fontification in sh-mode with tree-sittter, Daniel Martín, 2022/10/31
- Re: Initial fontification in sh-mode with tree-sittter, Yuan Fu, 2022/10/31
Re: Initial fontification in sh-mode with tree-sittter, Stefan Kangas, 2022/10/27
Re: Initial fontification in sh-mode with tree-sittter, João Paulo Labegalini de Carvalho, 2022/10/28