From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Theodor Thornhill <theo@thornhill.no>
Cc: emacs-devel@gnu.org, eliz@gnu.org, casouri@gmail.com
Subject: Re: Plug treesit.el into other emacs constructs
Date: Tue, 13 Dec 2022 18:10:12 -0500 [thread overview]
Message-ID: <jwvpmcm9amw.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87o7s7gji0.fsf@thornhill.no> (Theodor Thornhill's message of "Tue, 13 Dec 2022 21:02:15 +0100")
> And in this case multiple forward-sexps would be
>
> ```
> |public void foo(Array<Foo<List<Int>, String>> bar, String baz)
> public| void foo(Array<Foo<List<Int>, String>> bar, String baz)
> public void| foo|(Array<Foo<List<Int>, String>> bar, String baz)
> public void foo(Array|<Foo<List<Int>, String>> bar, String baz)
No, from before the paren, it should skip to after the paren, like it
has done in the past.
> public void foo(Array<Foo|<List<Int>, String>> bar, String baz)
> public void foo(Array<Foo<List|<Int>, String>> bar, String baz)
Similarly here, I'd expect to jump over the whole `<List<Int>, String>`.
>> Because point was left of the comma and the smallest right child of the
>> corresponding node is "String bar" and not "String" (which is more like
>> the left child of the node that covers "String bar").
> Ok, so you mean that forward-sexp should incrementally cover more and
> more of a node, but transpose-sexp would find the _whole_ node, then
> swap it with the one "in front" of it?
>
> so in 'void(String foo, int bar)'
>
> forward-sexp would go word by word, but transpose-sexp would capture
> "String foo" and "int bar" when point is on the comma?
When point is left of a comma, it can't be claimed to be "just before
String foo" because there's a comma between the two, so `forward-sexp`
can skip over the whole right-hand-side of the comma:
(y + 2,| x + 4) ==forward-sexp==> (y + 2, x| + 4)
(y + 2|, x + 4) ==forward-sexp==> (y + 2, x + 4|)
Similarly when going backward, if we're to the *right* of a comma, we'd
want to jump over the whole left-hand side of the comma:
(y + 2,| x + 4) ==backward-sexp==> (|y + 2, x + 4)
(y + 2|, x + 4) ==backward-sexp==> (y + |2, x + 4|)
For `transpose-sexp` we want to transpose two nodes at the same level of
the tree, so regardless if we're to the left or to the right of a comma,
we want to swap the whole left/right hand sides:
(y + 2,| x + 4) ==backward-sexp==> (x + 4, y + 2|)
(y + 2|, x + 4) ==backward-sexp==> (x + 4, y + 2|)
For SMIE this happens "automatically" because `transpose-sexp` first
"steps back" before jumping over a sexp: it skips punctuation backward
before jumping with `forward-sexp` and skips punctuation forward before
jump with `backward-sexp`.
This works for infix operators that use punctuation syntax, but not for
infix operators like `else`.
>>> I mean, what construct is each one expected to jump over?
>> In my book "sexp" movement should jump over subtrees of the AST.
> So given this ast point should move over each named node, no matter if
> transposing them would create broken code?
Sorry, I don't understand what you mean by "move over each named node".
> Forgive my stupid questions, I just want it to be clear to me what I'm
> doing here ;)
The semantics I advocate aren't necessarily the "right" one.
It's the one I came up with when I tried to make sense of it for SMIE.
I think they make sense and I find it hard to imagine others that make
as much sense, but if I can't convince you, maybe there's something
better out there.
Stefan
next prev parent reply other threads:[~2022-12-13 23:10 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-12 14:33 Plug treesit.el into other emacs constructs Theodor Thornhill
2022-12-12 14:45 ` Eli Zaretskii
2022-12-13 18:17 ` Theodor Thornhill
2022-12-12 15:46 ` Stefan Monnier
2022-12-13 18:27 ` Theodor Thornhill
2022-12-13 19:37 ` Stefan Monnier
2022-12-13 19:53 ` Yuan Fu
2022-12-13 20:06 ` Perry Smith
2022-12-13 23:19 ` Stefan Monnier
2022-12-14 8:14 ` Yuan Fu
2022-12-14 8:42 ` Theodor Thornhill
2022-12-14 14:01 ` Stefan Monnier
2022-12-14 16:24 ` Theodor Thornhill
2022-12-14 17:46 ` Stefan Monnier
2022-12-14 18:07 ` Theodor Thornhill
2022-12-14 19:25 ` Stefan Monnier
2022-12-14 19:35 ` Stefan Monnier
2022-12-14 20:04 ` Theodor Thornhill
2022-12-14 20:50 ` Stefan Monnier
2022-12-14 21:15 ` Theodor Thornhill
2022-12-14 21:34 ` Stefan Monnier
2022-12-15 19:37 ` Theodor Thornhill
2022-12-15 19:56 ` Stefan Monnier
2022-12-15 20:03 ` Theodor Thornhill
2022-12-15 20:33 ` Theodor Thornhill
2022-12-15 20:57 ` Theodor Thornhill
2022-12-24 7:00 ` Eli Zaretskii
2022-12-24 8:44 ` Yuan Fu
2022-12-24 14:01 ` Stefan Monnier
2022-12-24 14:15 ` Theodor Thornhill
2022-12-26 19:11 ` Theodor Thornhill
2022-12-26 22:46 ` Stefan Monnier
2022-12-26 22:51 ` Stefan Monnier
2022-12-27 22:15 ` Theodor Thornhill via Emacs development discussions.
2022-12-28 0:12 ` Stefan Monnier
2022-12-28 9:26 ` Theodor Thornhill via Emacs development discussions.
2022-12-28 18:01 ` Stefan Monnier
2022-12-28 18:27 ` Theodor Thornhill
2022-12-26 22:56 ` Theodor Thornhill
2022-12-27 15:46 ` Lynn Winebarger
2022-12-14 23:31 ` Yuan Fu
2022-12-15 0:05 ` Yuan Fu
2022-12-15 7:09 ` Eli Zaretskii
2022-12-15 7:14 ` Theodor Thornhill
2022-12-15 4:37 ` Stefan Monnier
2022-12-15 5:59 ` Theodor Thornhill
2022-12-15 21:23 ` Yuan Fu
2022-12-15 21:28 ` Theodor Thornhill
2022-12-13 20:02 ` Theodor Thornhill
2022-12-13 23:10 ` Stefan Monnier [this message]
2022-12-14 23:32 ` Stephen Leake
2022-12-16 10:02 ` Kévin Le Gouguec
2022-12-16 11:54 ` [SPAM UNSURE] " Stephen Leake
2022-12-17 15:30 ` Kévin Le Gouguec
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=jwvpmcm9amw.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=casouri@gmail.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--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.