unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Troy Brown <brownts@troybrown.dev>
Cc: 68664@debbugs.gnu.org, "Daniel Martín" <mardani29@yahoo.es>
Subject: bug#68664: 29.1.50; treesit defun commands broken with nested functions
Date: Fri, 26 Jan 2024 20:26:38 -0800	[thread overview]
Message-ID: <B93AEC04-510A-4EA8-8E7E-D930FC9849A5@gmail.com> (raw)
In-Reply-To: <CABvCZ42KjK-eK2z+zAjqqhJ-yv0wRiBWF3v7qzieWpvZY0Oakg@mail.gmail.com>



> On Jan 24, 2024, at 9:25 AM, Troy Brown <brownts@troybrown.dev> wrote:
> 
> On Wed, Jan 24, 2024 at 9:13 AM Troy Brown <brownts@troybrown.dev> wrote:
>> 
>> On Wed, Jan 24, 2024 at 1:29 AM Yuan Fu <casouri@gmail.com> wrote:
>>> 
>>> 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
>> 
>> I find it quite odd that this is the expected behavior.  Per the Emacs
>> manual (section "Moving by Defuns"), I expected the point to be moved
>> to the "innermost defun around point", since treesit-defun-tactic is
>> set to "nested", as that is precisely what is documented there.  I
>> interpret "innermost defun around point" to mean the innermost defun
>> that encompasses point.  Additionally, the documentation strings for
>> treesit-beginning-of-defun and treesit-end-of-defun indicate that they
>> are a tree-sitter equivalent of the beginning-of-defun and
>> end-of-defun commands respectively.  If so, and since they are mapped
>> to the same key bindings in the tree-sitter modes, shouldn't the
>> expectation be that they behave the same way as the non-tree-sitter
>> commands?  If not, people transitioning between the non-tree-sitter
>> mode and the tree-sitter mode are in for a surprise when the commands
>> behave differently.
>> 
>> With the current behavior there is no way to move the point directly
>> to the beginning of the function without moving through all of the
>> nested functions first, which could be significant.  When you say the
>> behavior is to "move between siblings in the same level", should the
>> level refer to where point is, or to the level corresponding to the
>> function encompassing the point?  I think it probably makes sense to
>> move between siblings if you are at a function boundary (there is a
>> function immediately before or after the point), but if you are
>> already deep in a function, I think it makes sense to first move to
>> that function's begin/end before attempting to move between siblings.
>> I believe this behavior would be consistent with the non-tree-sitter
>> modes and expectations based on the description in the manual.
> 
> To add further support to my belief that the current implementation is
> not the expected behavior, consider how the current implementation
> behaves when used with mark-defun.  When the point is on the call to
> innerFunction and I execute "M-x mark-defun RET", the nested function
> following the point (i.e., innerFunction2) is selected rather than the
> function containing point.  For comparison, the non-tree-sitter
> python-mode behaves correctly and selects the function containing
> point, not the next nested function.

Yeah, I mean, I can definitely see the validity of the behavior you’re describing. But I think the current behavior is equally valid. Right now you can easily go to the previous/next sibling in the same level, _and_ go to the beginning/end of the parent. You just need to press a few more times. OTOH if you go straight to the parent, there’s no way to go to siblings.

As for mark-defun, I think it’s similarly equally valid to either mark the next sibling or the parent. Right now mark-defun doesn’t really have a notion of nested defun, we should upgrade it to support nested defun like we did beginning/end-of-defun, either by a toggle like mark-defun-tactic or let user control which defun to mark interactively.

Yuan




  reply	other threads:[~2024-01-27  4:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-22 23:10 bug#68664: 29.1.50; treesit defun commands broken with nested functions Troy Brown
2024-01-23  0:32 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-23 14:30   ` Troy Brown
2024-01-24  6:29     ` Yuan Fu
2024-01-24 14:13       ` Troy Brown
2024-01-24 17:25         ` Troy Brown
2024-01-27  4:26           ` Yuan Fu [this message]
2024-01-27  7:32             ` Eli Zaretskii
2024-01-28  4:03               ` Yuan Fu
2024-01-28  6:53                 ` Eli Zaretskii
2024-01-28  7:29                   ` Yuan Fu
2024-01-28  7:43                     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=B93AEC04-510A-4EA8-8E7E-D930FC9849A5@gmail.com \
    --to=casouri@gmail.com \
    --cc=68664@debbugs.gnu.org \
    --cc=brownts@troybrown.dev \
    --cc=mardani29@yahoo.es \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).