emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Code navigation for sh-mode with Tree-sitter


From: João Paulo Labegalini de Carvalho
Subject: Re: Code navigation for sh-mode with Tree-sitter
Date: Mon, 5 Dec 2022 08:24:37 -0700



On Sat, Dec 3, 2022 at 2:46 PM Alan Mackenzie <acm@muc.de> wrote:
Yes.  beginning-of-defun and end-of-defun are broken, and have been for
a long time.  They cannot, in general, work, for the reason you've just
noted.

Thanks for confirming this, Alan. For a moment I thought that I was making one of those elisp newbie mistakes.
 
The problem has been raised on emacs-devel before, without the problem
getting solved.  CC Mode, for example, works around the problem by
binding c-beginning-of-defun and c-end-of-defun directly to C-M-a and
C-M-e, bypassing the offending code.

I think for now I will use the same workaround.
 
The tactic of using beginning-of-defun-raw is only valid in certain
circumstances, and is an inappropriate inefficiency in modes such as
the one you're writing, where it is just as easy to go directly to an
end of defun as a beginning of defun.

> What I think is happening is that, when `end-of-defun' calls
> `beginning-of-defun-raw' it brings point to the beginning of a top-level
> function, so the subsequent call to `end-of-defun' moves point to the start
> location, does it make it seems as the point did not move.

Yes.  I suggest you submit a bug report for this bug.

I will put some time into this and see if I can come up with a patch before flagging it as a bug.
 
To work properly, beginning/end-of-defun need to know whether the
starting point is inside a defun or between defuns.  Your patch includes
a macro which determines this (as CC Mode includes a function which
determines this).  Possibly, a proper bug fix might include a function
supplied by the major mode for this analysis.

Indeed. I am not sure if that would be as easy as without tree-sitter, but such a function is definitely handy and easy to implement thanks to Yuan's efforts to bring tree-sitter to core. 

--
João Paulo L. de Carvalho
Ph.D Computer Science |  IC-UNICAMP | Campinas , SP - Brazil
Postdoctoral Research Fellow | University of Alberta | Edmonton, AB - Canada
joao.carvalho@ic.unicamp.br
joao.carvalho@ualberta.ca

reply via email to

[Prev in Thread] Current Thread [Next in Thread]