emacs-devel
[Top][All Lists]
Advanced

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

Code navigation for sh-mode with Tree-sitter


From: João Paulo Labegalini de Carvalho
Subject: Code navigation for sh-mode with Tree-sitter
Date: Sat, 3 Dec 2022 13:23:25 -0700

Hi all,

I am working on basic navigation for sh-mode. My idea is that in sh-mode invoking C-M-a or C-M-e moves point to the beginning/end of the surrounding function if the point was inside of said function or to the beginning/end of the next/previous top-level function otherwise.

I got the functions to do so in the attached patch (I did not include the C-M-a with a negative argument yet).

If the functions are defined and used in isolation they work as intended. However, because `end-of-defun' calls `beginning-of-defun-raw' (which, AFAIK, uses `beginning-of-defun-function') it causes the C-M-e to not work when the point is not inside of a function.

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.

I have also noticed that calling the private function I defined directly via M-: brings the point to a slightly different location. For example:

<---- point before C-M-e
A {
} <--- point after M-: (sh-mode--treesit-end-of-defun)
<---- pint after C-M-e

Calling sh-mode--treesit-end-of-defun brings the point right after the closing curly brace and with C-M-e the point is positioned at the next line.

That might be due to additional processing done inside `end-of-defun'.

So, would it be ok to override `beginning-of-defun' and `end-of-defun' and thus have bash-ts-mode use the functions I wrote directly? If so, how could I do that? If not, how can I fix the "miss-behavior"?

I would appreciate all feedback and suggestions.

--
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

Attachment: 0001-Basic-navigation-for-sh-mode.patch
Description: Text Data


reply via email to

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