emacs-devel
[Top][All Lists]
Advanced

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

Re: More Tree Sitter Questions / Problems.


From: Stefan Monnier
Subject: Re: More Tree Sitter Questions / Problems.
Date: Wed, 14 Dec 2022 16:15:41 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

> foodog = 12 + 4 *
>     18 * 99 + 8

[ Trying to provide some SMIE perspective:  ]

In the context of sh-mode, I've had requests to provide that kind of
"AST-oblivious" indentation.  The result is controlled by
`sh-indent-after-continuation`.

> variable = 12 + 4 *
>                 18 * 99 + 8

That's my favorite, yes.
[ Tho GNU style would recommend breaking the line just before the `*`
  rather than just after it.  ]

> I also wrote ancestor-is and ancestor so now I get:
>
> eddie = (a + b *
>          c * d + 12)

I think this one sucks.  Do we really need it?
Can we have

    eddie = (a + b *
                 c * d + 12)

instead?

> bobby = a + b *
>   c * d + 12
>
> I fear as I test and play with this more I’m going to need more rules
> to catch all the cases where a line starts with a term of an
> arithmetic expression.

I'm not sure how you're looking at it, but for me, I've found it
important to try and understand what those indentation choices "mean".

I can see two interpretations of

    foodog = 12 + 4 *
        18 * 99 + 8

one is that this is one logical line spread over several physical lines
and the syntactic structure should be ignored, so it leads to:

    foodog = (12 + 4 *
        18 * 99 + 8)

That's the interpretation I used in `sh-indent-after-continuation` and
which I found to be easier to understand (and hence define in code).

Another way to look at it is via what I call "virtual indentation" in
SMIE: while "12 + 4 *" in the above code is indented 9 columns deeper
than "foodog", we could decide that what follows a "=" assignment is always
"virtually indented" only 4 columns deeper than the var.  So we get

    foodog = 12 + 4 +
        18 * 99 + 8

because the "18" is aligned with (the virtual indentation of) "12".
Then we also get

    foodog = (12 + 4 +
              18 * 99 + 8)

because "18" is still aligned "12" but while "(" is virtually indented
to +4, the virtual indentation of "12" is not special (it's the same as
its real indentation).

But if want to obey the syntactic structure we still won't get

    foodog = 12 + 4 *
        18 * 99 + 8

because "18" shouldn't be aligned with "12" in this case.


        Stefan




reply via email to

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