GNU bug report logs - #70789
treesit navigate for outlines at bobp

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Sun, 5 May 2024 16:57:01 UTC

Severity: normal

Fixed in version 30.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Yuan Fu <casouri <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 70789 <at> debbugs.gnu.org
Subject: bug#70789: treesit navigate for outlines at bobp
Date: Wed, 8 May 2024 17:16:22 -0700

> On May 5, 2024, at 11:43 PM, Juri Linkov <juri <at> linkov.net> wrote:
> 
>>> 'treesit-outline-search' didn't match outlines at the beginning of
>>> the buffer because unlike 're-search-forward' (used by outline-mode)
>>> that matches the text that immediately follows point,
>>> 'treesit-navigate-thing' misses text at point and stars the search
>>> after point.
>>> 
>>> So there is a need to handle this difference specially.  Therefore this
>>> patch adds such special-handling of bobp to 'treesit-outline-search’:
>> 
>> Thanks.  Just for me to understand it better, could you show an
>> example where treesit-navigate-thing misses text at point?
> 
> Here is an example:
> 
> 0. emacs -Q
> 1. C-x C-f test/lisp/progmodes/ruby-mode-resources/ruby-method-params-indent.rb
> 2. M-x ruby-ts-mode
> 3. M-: (setq outline-minor-mode-use-buttons t)
> 4. M-x outline-minor-mode
> 
> There are no outline buttons because the top thing "class"
> is at the beginning of the buffer.  Then you can insert
> an empty line before "class", and disable/enable
> outline-minor-mode again, and outline buttons appear
> on "class" and "def" lines.
> 
> Basically this is because
> 
>  (treesit-navigate-thing (point-min) 1 'beg "\\`\\(?:class\\|method\\)\\'")
> 
> can't find "class" at the beginning of the buffer,
> but after inserting an empty line before "class" it can find it.

I see, from treesit-navigate-thing’s point of view, point is already at the beginning of a class, therefore the correct behavior is to go to the beg of the next class. Using ‘end is probably more appropriate here, but I know you must have good reasons to use ‘beg. How about using treesit-search-forward? Wait, am I the one that suggested treesit-navigate-thing to you, because it returns higher-leveled nodes first?

In that case, maybe you can use treesit-thing-next to test if point is at the beginning of an outline header? That feels a bit easier to write and understand to me. If you prefer the current patch I don’t have problem with it either.

Yuan






This bug report was last modified 1 year and 12 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.