From: "Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 59628@debbugs.gnu.org
Subject: bug#59628: 29.0.50; treesit-beginning/end-of-defun problems in C/C++
Date: Mon, 28 Nov 2022 11:56:14 +0100 [thread overview]
Message-ID: <m1lenv4ab5.fsf@yahoo.es> (raw)
In-Reply-To: <83v8n0puxi.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 27 Nov 2022 12:12:57 +0200")
Eli Zaretskii <eliz@gnu.org> writes:
> To reproduce, visit any C source file in the Emacs tree, turn on c-ts-mode
> or c++-ts-mode, go to the middle of some function, and type
>
> M-: (treesit-beginning-of-defun) RET
> or
> M-: (treesit-end-of-defun) RET
>
> This will move point to very strange places, which generally are neither the
> beginning nor the end of the function. In very simple functions, like this
> one:
>
> void
> __executable_start (void)
> {
> emacs_abort ();
> }
>
> the result is correct. But once the function is even slightly more
> complicated, for example, like this:
>
> static int
> margin_glyphs_to_reserve (struct window *w, int total_glyphs, int margin)
> {
> if (margin > 0)
> {
> int width = w->total_cols;
> double d = max (0, margin);
> d = min (width / 2 - 1, d);
> /* Since MARGIN is positive, we cannot possibly have less than
> one glyph for the marginal area. */
> return max (1, (int) ((double) total_glyphs / width * d));
> }
> return 0;
> }
>
> the results are very far off the mark.
>
> These two functions are the only ones to move by defuns in treesit-based
> modes, right? So they should be improved, IMO.
>
If I type
M-: (setq treesit-defun-type-regexp "function_definition") RET
treesit-beginning-of-defun and treesit-end-of-defun do the right thing.
That begs the question: Is it really necessary to have a Tree-sitter
regexp variable to match defun nodes? If yes, should it already have a
sensible default value so things work out of the box in most major
modes?
next prev parent reply other threads:[~2022-11-28 10:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-27 10:12 bug#59628: 29.0.50; treesit-beginning/end-of-defun problems in C/C++ Eli Zaretskii
2022-11-28 10:56 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-11-28 22:08 ` Yuan Fu
2022-11-29 0:12 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-30 23:07 ` Yuan Fu
2022-12-01 8:08 ` Eli Zaretskii
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=m1lenv4ab5.fsf@yahoo.es \
--to=bug-gnu-emacs@gnu.org \
--cc=59628@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=mardani29@yahoo.es \
/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).