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: Wed, 14 Dec 2022 09:01:55 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

> I would argue that the purpose of forward-sexp is to move over items in
> a list.

There are different ways to look at it.  In the Lisp context where it
emerged, we only have "identifiers" and "parenthesized thingies", so
that doesn't give much guidance about what to do in-between.

The semantics I chose for SMIE is what I found to be closest to
past practice.

> Always going for the smallest subtree doesn’t seem to align with it.
> Take that example above, going across the smallest subtree means
> moving over X, then moving over “.”,

No: when you're left of ".", as in "(X|.y(z), alpha)", the SMIE
semantics of `forward-sexp` moves over ".y(z)", i.e. to
"(X.y(z)|, alpha)"

> that doesn’t feel like what forward-sexp should do to me.

Indeed, moving just over "." would be very far from my understanding of
what `forward-sexp` intends to do.

> You mean in the following code
>
> int a = 0[1];
> int b = 1;[2]
>
> Forward-sexp would move [1] to [2]?

No, SMIE's `forward-sexp` moves from

    int a = 0|;
    int b = 1;

to

    int a = 0;
    int b = 1|;

[ You can try it by installing Tuareg and moving around in an OCaml
  file, for example.  ]

and when moving backward it moves from

    int a = 0;
    int b = 1;|

to

    int a = 0;|
    int b = 1;

> But if we move over the smallest
> subtree, I’d imagine it only move across the semicolon after [1].

In my view ";" is not a substree.  It's the node of a substree.
We can't actually move over a proper subtree in that case because there
is no substree whose left boundary starts right before the ";", so the
closest is to move over the ";" *plus* its right child.

> Even if it moves from [1] to [2], needing to adjust point feels very
> inconvenient to me, at least I wouldn’t want to use something
> like that.

Moving point is the way to tell SMIE's `forward-sexp` which level of the tree
we want to navigate.  I don't believe Emacs can reliably guess the right
level, and I don't believe choosing an arbitrary level for the users
serves them best either.  I can imagine other ways to specify the
intended tree level, tho: maybe we could have a kind of prefix command
for that.  E.g. a new command that would work a bit like `C-M-u` (or its
younger sibling `expand-region`) but would only affect the next sexp
command instead.

> I want to type a single binding and move to where I want, and
> type that binding multiple times to move multiple steps.

I don't think a single binding can always jump to where you want.
That would require magic :-)

But yes, SMIE's `forward-sexp` does work well when repeated to jump over
N instructions, it was indeed an important design goal.


        Stefan




reply via email to

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