unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Yuan Fu <casouri@gmail.com>
Cc: "Stefan Monnier" <monnier@iro.umontreal.ca>,
	"João Paulo Labegalini de Carvalho" <jaopaulolc@gmail.com>,
	emacs-devel@gnu.org
Subject: Re: Code navigation for sh-mode with Tree-sitter
Date: Tue, 6 Dec 2022 21:40:34 +0000	[thread overview]
Message-ID: <Y4+20sfVdFHs+i/w@ACM> (raw)
In-Reply-To: <BE7CD46D-29E1-4F9C-8C51-DBEE1A4F22AB@gmail.com>

Hello, Yuan.

On Tue, Dec 06, 2022 at 13:08:19 -0800, Yuan Fu wrote:


> > On Dec 6, 2022, at 1:04 PM, Yuan Fu <casouri@gmail.com> wrote:



> >> On Dec 6, 2022, at 8:48 AM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> >>>> Calling beginning-of-defun-function followed by
> >>>> end-of-defun-function (and comparing the resulting position to the
> >>>> start position) should be sufficient to let you know whether or
> >>>> not you're inside the function whose definition starts most
> >>>> closely before point.


> >>> Hmm. In sh-mode `beginning-of-defun-function' is nil and in the
> >>> example below, calling `end-of-defun-function' with M-: (funcall
> >>> end-of-defun-function) brings point to fi and not the end of the
> >>> function.

> >> Many major modes do not implement those two functions in a fully
> >> reliable way, indeed.

> >> `bash-ts-mode` should be able to implement them reliably, OTOH.

> >>> In the example above, C-M-a and C-M-e do the right thing. However,
> >>> in the presence of nested functions, C-M-a and C-M-e only navigate
> >>> over top-level functions.  For example:

> >> Yes, it's a common limitation when the major mode is unable to do
> >> proper parsing of the code.

> > It seems there are not convention on whether defun movements should
> > move across top-level defun’s or both top-level and nested ones. I’ve
> > seen bug report on python-ts-mode complaining about both sides.

> > Should we make it configurable, then? A variable that makes
> > tree-sitter defun navigation switch between two modes: top-level only
> > and not top-level only. 

In CC Mode, it has been configurable via the user option c-defun-tactic
for somewhere between ten and fifteen years.  When c-defun-tactic is t,
C-M-a/e go to the start/end of the top level defuns.  When it is the
symbol go-outward, C-M-a/e move to the next start/end of defun, if any,
at the current level of class/namespace nesting, and move outwards to
the next level of class/namespace nesting when a class/namespace boundary
is reached.

I don't remember any complaints about this mechanism.

> And for functions nested in a class: if you type C-M-e at the beginning
> of a class, should it go to the end of the first function in that
> class, or should it go to the end of the class? Right now because of
> how end-of-defun works, it will jump to the end of the class if point
> is at the beginning of the class (1), and jump to the first function if
> point is before the beginning of the class (2).

This doesn't seem sensible.

> (2)
> (1)class class1():
>     prop = 0
>     def method1(self):
>         pass

>     def method2(self):
>         pass



> Yuan

-- 
Alan Mackenzie (Nuremberg, Germany).



  reply	other threads:[~2022-12-06 21:40 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-03 20:23 Code navigation for sh-mode with Tree-sitter João Paulo Labegalini de Carvalho
2022-12-03 21:46 ` Alan Mackenzie
2022-12-05 15:24   ` João Paulo Labegalini de Carvalho
2022-12-05 20:12     ` Stefan Monnier
2022-12-05 21:29       ` Alan Mackenzie
2022-12-05 21:56         ` Stefan Monnier
2022-12-06 15:51       ` João Paulo Labegalini de Carvalho
2022-12-06 16:48         ` Stefan Monnier
2022-12-06 21:04           ` Yuan Fu
2022-12-06 21:08             ` Yuan Fu
2022-12-06 21:40               ` Alan Mackenzie [this message]
2022-12-06 21:46                 ` João Paulo Labegalini de Carvalho
2022-12-06 21:55                   ` João Paulo Labegalini de Carvalho
2022-12-06 22:35                     ` Stefan Monnier
2022-12-06 22:41                       ` João Paulo Labegalini de Carvalho
2022-12-06 22:57                       ` Stefan Monnier
2022-12-06 23:43                         ` João Paulo Labegalini de Carvalho
2022-12-06 23:50                           ` Stefan Monnier
2022-12-07  1:12                             ` João Paulo Labegalini de Carvalho
2022-12-07 17:20                               ` João Paulo Labegalini de Carvalho
2022-12-10  4:58                                 ` Yuan Fu
2022-12-13  4:55                                 ` Yuan Fu
2022-12-13 16:00                                   ` João Paulo Labegalini de Carvalho
2022-12-13  5:20                                 ` New defun navigation for tree-sitter (Was: Code navigation for sh-mode with Tree-sitter) Yuan Fu
2022-12-13 16:11                                   ` João Paulo Labegalini de Carvalho
2022-12-13 16:38                                     ` Eli Zaretskii
2022-12-13 18:03                                       ` João Paulo Labegalini de Carvalho
2022-12-13 18:07                                     ` Yuan Fu
2022-12-13 18:48                                       ` João Paulo Labegalini de Carvalho
2022-12-13 18:56                                         ` Yuan Fu
2022-12-13 19:46                                           ` João Paulo Labegalini de Carvalho
2022-12-16  1:49                                             ` Yuan Fu
2022-12-16 16:24                                               ` João Paulo Labegalini de Carvalho
2022-12-17 23:32                                                 ` Yuan Fu
2022-12-07  0:41                 ` Code navigation for sh-mode with Tree-sitter Yuan Fu

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=Y4+20sfVdFHs+i/w@ACM \
    --to=acm@muc.de \
    --cc=casouri@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=jaopaulolc@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    /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).