unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Alan Mackenzie <acm@muc.de>
Cc: "João Paulo Labegalini de Carvalho" <jaopaulolc@gmail.com>,
	emacs-devel@gnu.org
Subject: Re: Code navigation for sh-mode with Tree-sitter
Date: Mon, 05 Dec 2022 16:56:15 -0500	[thread overview]
Message-ID: <jwv4ju9cyk3.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <Y45ivJU3gSxAgLLR@ACM> (Alan Mackenzie's message of "Mon, 5 Dec 2022 21:29:32 +0000")

> Even the existence of the variable end-of-defun-moves-to-eol is so crass
> it can't be other than broken.  João's patch contains a
> beginning-of-defun-function and and end-of-defun-function which
> intrinsically work.  Emacs's end-of-defun messes this up with it's
> ridiculous call to beginning-of-defun-raw, followed by a later call to
> (beginning-of-defun-raw -1).

Maybe I misunderstood.  I thought your claim of brokenness was relating to
`beginning/end-of-defun-function` rather than to `beginning/end-of-defun`.

>> 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.
>
> It's not.  With starting point between two defuns, that sequence could
> leave point at any of before, at, or after starting point.

Exactly, and this tells you if you're after the "immediately preceding"
function or inside of it.

> That's entirely disregarding nested functions, and how to handle them.

If you need to handle nested functions, then after the begin+end which
told you you're after the previous function, you need to go back to the
beginning of the previous function (i.e. where you were after the call
to BODF) and call BODF again (and EODF again to check whether you
started from within that outer function or not, and maybe iterate if
needed).

> CC Mode's C-M-e works.  João's new functions look like they will work.
> Both of these analyse, as a distinct operation, the starting position to
> determine whether or not it is inside or outside a defun.  Why not fix
> the standard end-of-defun (and beginning-of-defun) in lisp.el so that it
> will likewise work?

As soon as we can find an API that works *both* for the case of
tree-sitter (i.e. where we have more or less direct access to a global
information telling us where we are relative to the surrounding code
constructs) as well as for the case where we don't have much more info
than what BODF/EODF work with (i.e. a regexp to match a defun-start and
a function to jump over a defun).


        Stefan




  reply	other threads:[~2022-12-05 21:56 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 [this message]
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
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=jwv4ju9cyk3.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    --cc=jaopaulolc@gmail.com \
    /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).