[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Plug treesit.el into other emacs constructs
From: |
Theodor Thornhill |
Subject: |
Re: Plug treesit.el into other emacs constructs |
Date: |
Tue, 13 Dec 2022 19:27:58 +0100 |
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> Cool, thanks, a few comments (based on my experience with adding
> similar things based on `smie`):
>
>> ** Forward-sexp:
>> Executing C-M-f repeatedly will go from:
>> ```
>> public void foo(|String bar, String baz) {}
>> ```
>> to
>> ```
>> public void foo(String bar|, String baz) {}
>> ```
>
> That looks wrong. `String` is a valid AST node. Whether it gets a node
> in tree-sitter or not, I don't know, but here there are several "sexps"
> that start at point and I think `forward-sexp` should be conservative
> and keep advancing by the smallest option.
I understand. My reasoning is that 'forward-word' is suitable for that,
and to actually gain something from these we need to use a little bigger
constructs. In tree-sitter 'String' isn't really valid, because you
need the identifier to create a complete node.
>
> There can be many more than 2 choices, of course, e.g.:
>
> x = |f (x) * 3 + 2;
>
> Here "f" is the smallest sexp after point, "f (x)" is the next one up,
> then "f (x) * 3" and finally "f (x) * 3 + 2".
>
In this case I'd think that forward-sexp would do:
```
x = |f (x) * 3 + 2;
x = f (x)| * 3 + 2;
x = f (x) * 3| + 2;
x = f (x) * 3 + 2;|
```
Or something like that. So that multiple transpose-sexps would move
'f(x)' over the operators, swapping with the integers.
>> ```
>> public void foo(String bar, String baz|) {}
>> ```
>
> That one's right :-)
>
Why is this one right, and the above not?
>> ** transpose-sexp:
>> Executing C-M-t repeatedly will go from:
>> ```
>> public void foo(int bar,| String baz) {}
>> ```
>> to
>> ```
>> public void foo(String baz, int bar|) {}
>> ```
>
> And this one it right as well (regardless if | starts after or before the
> comma).
>
> Does it work as well for infix keywords that are made of normal letters,
> like say `else` (or the `and` and `or` used in some languages instead
> of `&&` and `||`)?
I see no reason it shouldn't but I need to investigate that a bit
further. I'm still trying to understand how all the forward-* functions
work, to see whether I need to modify my functions.
Thanks for the feedback so far. I interpret this that this feature is
wanted, so I'll make a more serious effort and get back to you.
BTW, where are the semantics for these movement functions defined? I
mean, what construct is each one expected to jump over?
Theo
- Plug treesit.el into other emacs constructs, Theodor Thornhill, 2022/12/12
- Re: Plug treesit.el into other emacs constructs, Eli Zaretskii, 2022/12/12
- Re: Plug treesit.el into other emacs constructs, Stefan Monnier, 2022/12/12
- Re: Plug treesit.el into other emacs constructs,
Theodor Thornhill <=
- Re: Plug treesit.el into other emacs constructs, Stefan Monnier, 2022/12/13
- Re: Plug treesit.el into other emacs constructs, Yuan Fu, 2022/12/13
- Re: Plug treesit.el into other emacs constructs, Perry Smith, 2022/12/13
- Re: Plug treesit.el into other emacs constructs, Stefan Monnier, 2022/12/13
- Re: Plug treesit.el into other emacs constructs, Yuan Fu, 2022/12/14
- Re: Plug treesit.el into other emacs constructs, Theodor Thornhill, 2022/12/14
- Re: Plug treesit.el into other emacs constructs, Stefan Monnier, 2022/12/14
- Re: Plug treesit.el into other emacs constructs, Theodor Thornhill, 2022/12/14
- Re: Plug treesit.el into other emacs constructs, Stefan Monnier, 2022/12/14
- Re: Plug treesit.el into other emacs constructs, Theodor Thornhill, 2022/12/14