emacs-devel
[Top][All Lists]
Advanced

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

Re: Plug treesit.el into other emacs constructs


From: Stefan Monnier
Subject: Re: Plug treesit.el into other emacs constructs
Date: Tue, 13 Dec 2022 18:10:12 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

> 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




reply via email to

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