all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Dmitry Gutov <dmitry@gutov.dev>
Cc: "Daniel Martín" <mardani29@yahoo.es>,
	"Daniel Colascione" <dancol@dancol.org>,
	"Dmitry Gutov" <dgutov@yandex.ru>, "Alan Mackenzie" <acm@muc.de>,
	"João Távora" <joaotavora@gmail.com>,
	"Eli Zaretskii" <eliz@gnu.org>,
	"theodor thornhill" <theo@thornhill.no>,
	geza.herman@gmail.com, emacs-devel@gnu.org
Subject: Re: treesit indentation "blinking"
Date: Fri, 7 Apr 2023 19:42:56 -0700	[thread overview]
Message-ID: <836E537D-0146-4F1D-BF04-863C3029C50E@gmail.com> (raw)
In-Reply-To: <f83e2df3-8eca-7eb1-6ecc-b40f21537d3f@gutov.dev>



> On Apr 7, 2023, at 6:32 PM, Dmitry Gutov <dmitry@gutov.dev> wrote:
> 
> 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.
> 
> (
>  ERROR
>    "for" "(" @indent.begin ";" ";" ")" @indent.end)
> 
> So perhaps we should revisit that approach too.

Yeah, some more specific error handling can be only beneficial.

> 
>> 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.

The indent.scm way basically queries the whole file with all the queries, build a hash map out of the captured nodes, then get the node at the current line and go up the tree; at each parent, check if it’s a node that was captured, if so, add an indentation level.

To be honest, this will work fine in even largish files, but it’ll be slow when you indent a region instead of a line (in a large file). And as you said, it’s a bit more work to support styles. But, there are ways to make this method more efficient, by using some caching and localizing, so maybe it could work.

indent.scm definitely looks neater and more convenient to write than the rules we use (plus it already exists). So it would be nice to somehow make it compatible. I’ve been trying to conceive some way to convert the normal query into something more flexible, so that it can be used for more than querying “top-down” from a node. For example, verifying that a node would be captured as xxx in a query.

Ideas and patches are welcome :-)

Yuan


  reply	other threads:[~2023-04-08  2:42 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-22 20:49 treesit indentation "blinking" Daniel Colascione
2023-03-23  0:00 ` Yuan Fu
2023-03-23  0:07   ` Daniel Colascione
2023-03-23  1:02     ` Yuan Fu
2023-03-23  4:51       ` Daniel Colascione
2023-03-23 20:04         ` Yuan Fu
2023-03-23 21:10           ` Daniel Colascione
2023-03-23 21:24             ` Dmitry Gutov
2023-03-25  9:05               ` João Távora
2023-03-25 12:42                 ` Dmitry Gutov
2023-03-25 14:42                   ` Eli Zaretskii
2023-03-25 16:18                     ` João Távora
2023-03-28 22:11                       ` João Távora
2023-03-28 23:57                         ` Daniel Colascione
2023-03-29  2:26                         ` Eli Zaretskii
2023-03-29 22:30                           ` João Távora
2023-03-29 22:37                             ` Herman, Géza
2023-03-29 23:25                               ` João Távora
2023-03-30  7:47                                 ` Herman, Géza
2023-03-29 22:56                             ` Lynn Winebarger
2023-03-30  7:43                             ` Eli Zaretskii
2023-03-30  8:58                               ` Dmitry Gutov
2023-03-30  9:15                                 ` João Távora
2023-03-30  9:06                               ` João Távora
2023-03-30  9:20                                 ` Dmitry Gutov
2023-03-30  9:28                                   ` João Távora
2023-03-30  9:36                                     ` Dmitry Gutov
2023-03-30 10:00                                       ` João Távora
2023-03-30 16:29                                         ` Dmitry Gutov
2023-03-30 17:14                                           ` João Távora
2023-03-30 10:07                                 ` Eli Zaretskii
2023-03-30 10:26                                   ` Herman, Géza
2023-03-30 13:39                                     ` Eli Zaretskii
2023-03-30 15:03                                       ` Herman, Géza
2023-03-30 14:58                                     ` Eli Zaretskii
2023-04-01 19:39                                       ` Yuan Fu
2023-04-02  1:49                                         ` Yuan Fu
2023-04-02  5:31                                           ` Eli Zaretskii
2023-04-02 14:26                                           ` Alan Mackenzie
2023-04-02 15:48                                             ` João Távora
2023-04-02 17:04                                               ` Alan Mackenzie
2023-04-02 17:23                                                 ` João Távora
2023-04-02 17:51                                                   ` Eli Zaretskii
2023-04-02 18:04                                                     ` João Távora
2023-04-02 18:14                                                       ` Eli Zaretskii
2023-04-02 21:38                                                         ` João Távora
2023-04-02 21:21                                                   ` Dmitry Gutov
2023-04-02 21:40                                                     ` João Távora
2023-04-03  9:59                                                     ` Alan Mackenzie
2023-04-03 10:28                                                       ` João Távora
2023-04-03 12:07                                                       ` Dmitry Gutov
2023-04-03 12:56                                                         ` Alan Mackenzie
2023-04-03 20:58                                                           ` Dmitry Gutov
2023-04-03 21:59                                                         ` Daniel Colascione
2023-04-03 22:10                                                           ` Dmitry Gutov
2023-04-04  8:31                                                           ` João Távora
2023-04-07 14:20                                                           ` Daniel Martín
2023-04-08  1:32                                                             ` Dmitry Gutov
2023-04-08  2:42                                                               ` Yuan Fu [this message]
2023-04-08 18:59                                                               ` Daniel Martín
2023-04-03 21:47                                             ` parser error recovery algorithm vs " Stephen Leake
2023-04-04 12:01                                               ` John Yates
2023-04-04 13:40                                                 ` Dmitry Gutov
2023-04-04 16:00                                                   ` Stephen Leake
2023-04-04 13:50                                                 ` Stephen Leake
2023-04-04 14:05                                                   ` Dmitry Gutov
2023-03-30 11:05                                   ` João Távora
2023-03-30 14:00                                     ` Eli Zaretskii
2023-03-30 14:43                                       ` João Távora
2023-03-30 14:52                                         ` Eli Zaretskii
2023-03-30 15:42                                           ` João Távora
2023-03-25 16:14                   ` João Távora
2023-03-24 11:39             ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=836E537D-0146-4F1D-BF04-863C3029C50E@gmail.com \
    --to=casouri@gmail.com \
    --cc=acm@muc.de \
    --cc=dancol@dancol.org \
    --cc=dgutov@yandex.ru \
    --cc=dmitry@gutov.dev \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=geza.herman@gmail.com \
    --cc=joaotavora@gmail.com \
    --cc=mardani29@yahoo.es \
    --cc=theo@thornhill.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.