unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Theodor Thornhill <theo@thornhill.no>
Cc: Yuan Fu <casouri@gmail.com>,  emacs-devel@gnu.org,  eliz@gnu.org
Subject: Re: Plug treesit.el into other emacs constructs
Date: Wed, 14 Dec 2022 14:25:19 -0500	[thread overview]
Message-ID: <jwvzgbpvlmc.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <4315EFC6-7AA8-4A48-845C-9CA8B88034D9@thornhill.no> (Theodor Thornhill's message of "Wed, 14 Dec 2022 19:07:23 +0100")

>>In this case, yes.  But in other cases it will move at different levels
>>of the tree.  E.g.:
>>
>>   int x = f (b + 4, c * 7 - z * 2, d, e);
>>
>>It will sometimes move over the whole instruction, and other times over
>>just a single variable or over a whole argument or over just a "factor".
>>This depends on where point is when `forward/backward-sexp` is called.
>
> Yeah. I think this example shows what I find unintuitive. If point is right
> before the first comma, and we transpose-sexps, it could end up swapping
> 4 for c * 7 - z * 2, which would rarely make sense in this context.

If so, that would be a bug in `transpose-sexp`, agreed.
I'm talking here about `forward/backward-sexp`.
The two are linked, but we shouldn't use one to justify a bug in the other.

`Forward-sexp` from

    int x = f (b + 4|, c * 7 - z * 2, d, e);

should work by delimiting the two things to swap *plus* the thing
in-between, and in this case it should be:

    int x = f (<b + 4>, <c * 7 - z * 2>, d, e);

Notice how it needs to figure out the ", ".  Once this is figured out,
it's easy to use `forward/backward-sexp` to find the other 2 boundaries
(if you want to re-use the `forward/backward-sexp`, like the code
currently does):

Use `forward-sexp` from

    int x = f (b + 4|, c * 7 - z * 2, d, e);

and `backward-sexp` from

    int x = f (b + 4, |c * 7 - z * 2, d, e);

> Swapping b + 4 with c * 7 - z * 2 would make sense here,  imo.
> I believe this is not how you see it? 

Looks like I wasn't clear enough.  I do agree with you on this, and SMIE
agrees with you as well, if you try `M-C-t` on the above code in
tuareg-mode.


        Stefan




  reply	other threads:[~2022-12-14 19:25 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 [this message]
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

  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=jwvzgbpvlmc.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 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).