all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Theodor Thornhill <theo@thornhill.no>
To: Stefan Monnier <monnier@iro.umontreal.ca>
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 19:27:58 +0100	[thread overview]
Message-ID: <87r0x3gnv5.fsf@thornhill.no> (raw)
In-Reply-To: <jwvwn6wiqhu.fsf-monnier+emacs@gnu.org>

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



  reply	other threads:[~2022-12-13 18:27 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 [this message]
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
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=87r0x3gnv5.fsf@thornhill.no \
    --to=theo@thornhill.no \
    --cc=casouri@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.