From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Perry Smith <pedz@easesoftware.com>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: More Tree Sitter Questions / Problems.
Date: Wed, 14 Dec 2022 16:15:41 -0500 [thread overview]
Message-ID: <jwv1qp1vh6j.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <365D3BA2-298F-4B99-9707-FE8BC658701F@easesoftware.com> (Perry Smith's message of "Wed, 14 Dec 2022 14:43:09 -0600")
> 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
next prev parent reply other threads:[~2022-12-14 21:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-14 20:43 More Tree Sitter Questions / Problems Perry Smith
2022-12-14 21:15 ` Stefan Monnier [this message]
2022-12-14 23:22 ` Perry Smith
2022-12-14 23:48 ` Yuan Fu
2022-12-14 23:53 ` Stefan Monnier
2022-12-15 6:56 ` Eli Zaretskii
2022-12-26 16:28 ` Dmitry Gutov
2022-12-15 6:05 ` Yuri Khan
2022-12-26 16:24 ` Dmitry Gutov
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv1qp1vh6j.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=pedz@easesoftware.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).