[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: treesit indentation "blinking"
From: |
Alan Mackenzie |
Subject: |
Re: treesit indentation "blinking" |
Date: |
Mon, 3 Apr 2023 12:56:51 +0000 |
Hello, Dmitry.
On Mon, Apr 03, 2023 at 15:07:11 +0300, Dmitry Gutov wrote:
> On 03/04/2023 12:59, Alan Mackenzie wrote:
> > Hello, Dmitry.
> > On Mon, Apr 03, 2023 at 00:21:18 +0300, Dmitry Gutov wrote:
> >> On 02/04/2023 20:23, João Távora wrote:
> >>> So my initial idea was to tone down electric-indent-chars, at least
> >>> for the moment. And Dmitry's idea was to make electric-indent-chars
> >>> be ambitious_only_ if electric-pair-mode is enabled (by the user).
> >>> Maybe we should bring back that idea, and it seems the least bad of the
> >>> bunch right now.
> >> Alternatively, we only perform "electric indent" (aside from after RET)
> >> when the parse tree does not contain errors.
> > That is NOT electric indentation. The whole point about electric
> > indentation is for it to take effect whilst point is still on the line
> > being edited. Thus, for example, you can see whether or not the line
> > needs breaking, or whether there's room for a short comment at the end
> > of the line.
> Wouldn't you know whether the line needs breaking, as long as the line
> was indented correctly when you opened it with RET?
Maybe sometimes, but often not.
> > What you're proposing is something which would almost never trigger,
> > since a line being edited will not have a parse tree without errors (if
> > I've understood that properly). If it did trigger at some point, that
> > would likely cause annoyance and puzzlement.
> That's a fair assessment, but it's going to trigger in a lot of cases
> still: after ;, or after a paren or brace being closed.
OK.
> This is not a substitute for enabling electric-pair-mode, alas.
As you've no doubt gathered, I particularly dislike electric-pair-mode.
I'm likely far from rare in that respect. I think we'll be doing our
users a disservice if indentation only works when e-p-m is enabled.
> Just a less hackish way to check the same thing rather than check for
> this particular mode being enabled.
> I would also prefer c++-ts-mode supported indentation with closing
> braces missing, but we're really limited by what the parser provides.
> E.g. for this code
> int foo() {
> for (;;) {
> we get this parse tree:
> (ERROR (primitive_type)
> (function_declarator declarator: (identifier)
> parameters: (parameter_list ( )))
> { for ( ; ; ) {)
> where the "for" statement isn't even present (the separate tokens are
> parsed as leaf nodes, and that's it). It's difficult to write meaningful
> indentation rules that would match this.
Why do we get a parse tree with ERROR in it when the source isn't
erroneous? It is merely incomplete. Tree sitter was surely designed for
editors, where source code being entered is typically incomplete, not
just for things like code formatters. Why do we not get a full valid
parse tree indicating the current (incomplete) state?
--
Alan Mackenzie (Nuremberg, Germany).
- Re: treesit indentation "blinking", (continued)
- Re: treesit indentation "blinking", João Távora, 2023/04/02
- Re: treesit indentation "blinking", Eli Zaretskii, 2023/04/02
- Re: treesit indentation "blinking", João Távora, 2023/04/02
- Re: treesit indentation "blinking", Eli Zaretskii, 2023/04/02
- Re: treesit indentation "blinking", João Távora, 2023/04/02
- Re: treesit indentation "blinking", Dmitry Gutov, 2023/04/02
- Re: treesit indentation "blinking", João Távora, 2023/04/02
- Re: treesit indentation "blinking", Alan Mackenzie, 2023/04/03
- Re: treesit indentation "blinking", João Távora, 2023/04/03
- Re: treesit indentation "blinking", Dmitry Gutov, 2023/04/03
- Re: treesit indentation "blinking",
Alan Mackenzie <=
- Re: treesit indentation "blinking", Dmitry Gutov, 2023/04/03
- Re: treesit indentation "blinking", Daniel Colascione, 2023/04/03
- Re: treesit indentation "blinking", Dmitry Gutov, 2023/04/03
- Re: treesit indentation "blinking", João Távora, 2023/04/04
- Re: treesit indentation "blinking", Daniel Martín, 2023/04/07
- Re: treesit indentation "blinking", Dmitry Gutov, 2023/04/07
- Re: treesit indentation "blinking", Yuan Fu, 2023/04/07
- Re: treesit indentation "blinking", Daniel Martín, 2023/04/08
- parser error recovery algorithm vs treesit indentation "blinking", Stephen Leake, 2023/04/03
- Re: parser error recovery algorithm vs treesit indentation "blinking", John Yates, 2023/04/04