GNU bug report logs - #68664
29.1.50; treesit defun commands broken with nested functions

Previous Next

Package: emacs;

Reported by: Troy Brown <brownts <at> troybrown.dev>

Date: Mon, 22 Jan 2024 23:12:02 UTC

Severity: normal

Found in version 29.1.50

Full log


View this message in rfc822 format

From: Yuan Fu <casouri <at> gmail.com>
To: Troy Brown <brownts <at> troybrown.dev>
Cc: 68664 <at> debbugs.gnu.org, Daniel Martín <mardani29 <at> yahoo.es>
Subject: bug#68664: 29.1.50; treesit defun commands broken with nested functions
Date: Tue, 23 Jan 2024 22:29:40 -0800

> On Jan 23, 2024, at 6:30 AM, Troy Brown <brownts <at> troybrown.dev> wrote:
> 
> On Mon, Jan 22, 2024 at 7:32 PM Daniel Martín <mardani29 <at> yahoo.es> wrote:
>> 
>> Troy Brown <brownts <at> troybrown.dev> writes:
>> 
>>> I've noticed that "defun" related treesit commands do not appear to work
>>> correctly when nested functions are involved.  I've seen this behavior
>>> in multiple languages and believe the problem is an issue in the
>>> treesit.el library.
>> 
>> Customize the treesit-defun-tactic variable to 'top-level to ignore
>> nested defuns in navigation commands.
> 
> But I don't want it to just go to the top-level, I want it to respect
> the current
> nesting level.  If I insert yet another level in the example, and
> point is within
> the second level of nesting, I want it to move to the beginning and end of that
> nested function (i.e., "secondLevel" in the sample below when point is on the
> call to innerFunction).  As mentioned in my original email, python-mode does
> respect the nesting level correctly, but python-ts-mode, and other "ts" modes
> that support nesting, don't respect it.

The behavior is expected. But I can see that it doesn’t match your expectations. The logic behind the current behavior is to first move between siblings in the same level; if there’s no sibling to move across anymore, move to the beginning/end of the immediate parent, and so on.

To get the behavior you want, we would need to add a fourth defun navigation tactic, in addition to the existing three: nested, top-level, and restricted.

If you are interested and able, maybe you can look into adding it to treesit--navigate-thing or treesit-beginning/end-of-defun?

Yuan



This bug report was last modified 1 year and 141 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.