GNU bug report logs - #62158
treesit-end-of-defun error

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Mon, 13 Mar 2023 07:36:02 UTC

Severity: normal

Fixed in version 29.0.60

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Yuan Fu <casouri <at> gmail.com>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: 62158 <at> debbugs.gnu.org, Juri Linkov <juri <at> linkov.net>
Subject: bug#62158: treesit-end-of-defun error
Date: Tue, 21 Mar 2023 14:26:26 -0700

> On Mar 20, 2023, at 11:43 AM, Dmitry Gutov <dgutov <at> yandex.ru> wrote:
> 
> On 14/03/2023 00:04, Yuan Fu wrote:
>> We tried that initially, but end-of-defun doesn’t have the notion of nested defuns, which leads to problems when end-of-defun-function recognizes nested defuns. In the following code
>> (defun xxx ()
>>   |
>>   (defun yyy () ...)
>>   (defun zzz () ...)
>>   )
>> If point is at “|” and you call end-of-defun, you’d expect point to move to the end of yyy, but instead it moves to the end of xxx. That’s because end-of-defun first runs (beginning-of-defun -1) followed by (end-of-defun 1) to check if the starting point is in a defun or between two defuns. This is fine in non-nested defuns, but in this example, the point first goes to the beginning of xxx, then goes to the end of xxx. And end-of-defun thinks that we started in a defun and now is at an end of defun, job’s done, and finishes.
>> The plan is to improve end-of-defun to support nested defuns in Emacs 30. For now we rebind end-of-defun to treesit-end-of-defun.
> 
> That makes sense, thanks!
> 
> I guess one of the things to try is to call end-of-defun-function first, followed by beginning-of-defun-function. And see if the resulting position is below the original point.

Unfortunately, end-of-defun-function must be called from the beginning of a defun, according to its docstring. So that won’t do. We got to upgrade beginning/end-of-defun to support nested defuns.

Yuan



This bug report was last modified 2 years and 62 days ago.

Previous Next


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