[Top][All Lists]

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

Re: treesit indentation "blinking"

From: Daniel Martín
Subject: Re: treesit indentation "blinking"
Date: Sat, 08 Apr 2023 20:59:03 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (darwin)

Dmitry Gutov <dmitry@gutov.dev> writes:

> On 07/04/2023 17:20, Daniel Martín wrote:
>> In general, I'd suggest taking a look at Neovim's Tree-sitter
>> implementation and perhaps reuse (part of) their .scm Tree-sitter syntax
>> highlight or indentation queries:
>> https://github.com/nvim-treesitter/nvim-treesitter/tree/master/queries/c
>> Neovim's implementation doesn't "blink" in the scenarios presented here,
>> but I'm not sure about how it performs in other tricky cases.
> Looking at that file, it does contain queries that look for ERROR
> nodes, e.g.
> (
>     "for" "(" @indent.begin ";" ";" ")" @indent.end)
> So perhaps we should revisit that approach too.
>> Now that text editors have access to the same programming language
>> grammars, I'm surprised the Tree-sitter community hasn't started any
>> cross-team effort to work on canonical queries (or slighter richer
>> abstractions) per programming language.  Text editor developers are
>> working and rediscovering complex language problems independently.
> We could do an indent implementation that just uses these indents.scm
> files. Not exactly sure why we didn't start out this way, but note
> that our Lisp based solution is a lot more flexible.
> E.g. there doesn't seem to be an obvious way to support "indentation
> styles" with these.

I think it may be possible to have different query files, say,
"GNU.scm", "K&R.scm", "C.scm" and add to the beginning of "GNU.scm" a
Lisp comment like "; import C.scm".  We would need to do manual parsing
of the .scm files, though.

Another question is how flexible this mechanism is.  If I change
something in an .scm file, would I need to restart Emacs to see the
results?  We could turn the .scm files into proper data Emacs Lisp files
that could be evaluated on the fly, I don't know how over-engineered
that'd be.  Also, I don't know if we could even satisfy advanced CC mode
users who are used to modify their style by just invoking C-c C-o on the
line whose indentation they want to change.

Even if we don't use external .scm files, perhaps we could add the
queries in them to our Tree-sitter rules?  I think we'd need a new
Tree-sitter matcher to match them properly, right?

reply via email to

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