Subject: Re: bug#78458: 31.0.50; treesit.el: thing navigation functions work incorrectly with some Clojure nodes

From: Juri Linkov <[email-masked]>
Date: Mon, 19 May 2025 21:50:37 +0300

>> +      (setq-local down-list-function
>> +                  (lambda (&optional arg)
>> +                    (let ((treesit-sexp-type-regexp 'sexp))
>> +                      (treesit-down-list arg))))
>> +      (setq-local up-list-function
>> +                  (lambda (&optional arg escape-strings no-syntax-crossing)
>> +                    (let ((treesit-sexp-type-regexp 'sexp))
>> +                      (treesit-up-list arg escape-strings no-syntax-crossing))))
>> +
>>        ;; Workaround for treesit-transpose-sexps not correctly working with
>>        ;; treesit-thing-settings on Emacs 30.
>>        ;; Once treesit-transpose-sexps it working again this can be removed
> Thank you very much for the patch Juri. It indeed solves all of the
> problems I mentioned.  However while I was testing the patch I noticed that
> the 'down-list' function behaves a bit odd. If I call it multiple times
> starting from the beginning of the line it moves the point to the following
> positions:
>
> #|(-> (.-value (.-target %)))
> #(->| (.-value (.-target %)))
> #(-> (.-value| (.-target %)))
> #(-> (.-value| (|.-target %)))
> #(-> (.-value| (.-target| %)))
> #(-> (.-value| (.-target %|)))

Then please remove '(setq-local down-list-function ..' from the patch,
it's not needed.

> While it would be more logical to have:
>
> #(|-> (.-value (.-target %)))
> #(-> (|.-value (.-target %)))
> #(-> (.-value (|.-target %)))

Without redefining 'down-list-function'
the 'down-list' function behaves like above.

But we can do nothing to fix the first step:

#|(-> (.-value (.-target %)))

because using treesit nodes, "#" is a child node of
'anon_fn_lit', so 'down-list' goes after it.

Since the treesit grammar can't handle this case,
you could try to use the default function by

  (setq-local down-list-function nil)