Subject: Re: bug#76788: treesit-thing-settings for elixir-ts-mode

From: Wilhelm Kirschbaum <[email-masked]>
Date: Wed, 16 Apr 2025 08:46:33 +0200

On Tue, Apr 15, 2025 at 7:37 PM Juri Linkov <[email-masked]> wrote:

> >     Previously C-M-f jumped from "def" to "end":
> >
> > Yes, this is desired. The expression starts with "def" and the do -> end
> is
> > just an argument to the "def" macro.
> >
> >       def fun(a) do
> >       end
> >
> >     The change is to jump only from "do" to "end" like in other ts-modes.
> >
> > Why is this better?
>
> Because otherwise there is no easy way to navigate to the function name
> and its arguments.  There were many complaints that unlike smie-based sexp
> now tree-sitter jumps too far directly to the end of functions.
> So sadly an idealistic promise of tree-sitter doesn't fit perfectly
> into the real world.
>

In Elixir

   def foo(bar), do: bar

is pretty much the same as

(defun foo (bar) bar)

So I think the original implementation is more natural to Emacs users, and
yes there is one slight downside, but at the cost of a multitude of
improvements for navigation. The majority of users I got feedback from
prefer how the new forward-sexp works. The smie-based sexp hardly worked in
any expected way as well. Look at how ruby-mode works with navigation ( I
have not tried ruby-ts-mode ), as it also properly treats def end blocks as
sexps.

>
> For many years I used elixir-mode before switching to elixir-ts-mode.
> And it caused a minor disruption by the inability to move to the
> function name and arguments as before in elixir-mode.
>

I understand that, but this is one case where it is slightly inconvenient,
for any other block in elixir it is impossible to navigate around now.

>
> > The one huge advantage that elixir-ts-mode brought to
> > the table was to navigate between functions, the existing elixir-mode
> could
> > not get this right.
>
> The new command 'treesit-cycle-sexp-type' keeps this advantage
> while allowing the users to toggle the traditional behavior
> where C-M-f moves over the arguments.
>

How do I enable this? Is this a new setting? Will it make the navigation
work as before?