Subject: Re: bug#70789: treesit navigate for outlines at bobp

From: Juri Linkov <[email-masked]>
Date: Mon, 06 May 2024 09:43:54 +0300

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

> If it does, that should be a bug that treesit-navigate-thing should
> fix, right?

I'm not sure if this is a bug.  Maybe it can be described just as
a difference between re-search-forward and treesit-navigate-thing.