Subject: Re: bug#78503: 30.0.92; tree-sitter elixir-ts-mode structural movement broken

From: Juri Linkov <[email-masked]>
Date: Tue, 20 May 2025 09:46:34 +0300

> Trying to use elixir treesit mode, it seems the navigation of defun and lists seems broken.
>
> 1.) `defmodule` is considered a function definition and so moving up from the first
> actual function definition `def my_fun do` causes the point to jump to
> 'defmodule my_mod do'. Invoking `end-of-defun` jumps to the end of the defmodule block.
> Effectively, you have been ejected from the module body.
>
> ;; current scoped workaround
> ;; does not jump up to defmodule when using `beginning-of-defun`
> (defun elixir-ts--defun-p (node)
>   "Return non-nil when NODE is a defun."
>   (member (treesit-node-text
>            (treesit-node-child-by-field-name node "target"))
>           (append
>            (remove "defmodule" elixir-ts--definition-keywords)
>           elixir-ts--test-definition-keywords)))

This behavior may look logically flawed,
but still it makes sense for user convenience:
while navigating with 'C-M-a' it's handy
to use the same key to move over modules too.

The same navigation exists in other ts-modes as well:
for example, in java-ts-mode 'C-M-a' moves over classes, etc.
OTOH, in ruby-ts-mode it's restricted to methods only.

> 2.) When you use `down-list` while on a function definition line,
> nothing happens. I tried to fix it, ony to find out that
> `backward-up-list` will jump to `defmodule` when invoked while point is at a
> function argument, instead of navigating out of the argument list only.  
>
> Structural movement might need some extra love.

This part is not reproducible.  Do you use the latest master?