unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#70789: treesit navigate for outlines at bobp
@ 2024-05-05 16:52 Juri Linkov
  2024-05-06  3:11 ` Yuan Fu
  0 siblings, 1 reply; 5+ messages in thread
From: Juri Linkov @ 2024-05-05 16:52 UTC (permalink / raw)
  To: 70789; +Cc: Yuan Fu

[-- Attachment #1: Type: text/plain, Size: 414 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: treesit-outline-search-bobp.patch --]
[-- Type: text/x-diff, Size: 1493 bytes --]

diff --git a/lisp/treesit.el b/lisp/treesit.el
index e55e04e53b3..86ed1bbae33 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -2884,15 +2884,21 @@ treesit-outline-search
                   (start (treesit-node-start node)))
         (eq (pos-bol) (save-excursion (goto-char start) (pos-bol))))
 
-    (let* ((pos
+    (let* ((bob-pos
+            ;; `treesit-navigate-thing' can't find a thing at bobp,
+            ;; so use `looking-at' to match at bobp.
+            (and (bobp) (treesit-outline-search bound move backward t) (point)))
+           (pos
             ;; When function wants to find the current outline, point
             ;; is at the beginning of the current line.  When it wants
             ;; to find the next outline, point is at the second column.
-            (if (eq (point) (pos-bol))
-                (if (bobp) (point) (1- (point)))
-              (pos-eol)))
-           (found (treesit-navigate-thing pos (if backward -1 1) 'beg
-                                          treesit-outline-predicate)))
+            (unless bob-pos
+              (if (eq (point) (pos-bol))
+                  (if (bobp) (point) (1- (point)))
+                (pos-eol))))
+           (found (or bob-pos
+                      (treesit-navigate-thing pos (if backward -1 1) 'beg
+                                              treesit-outline-predicate))))
       (if found
           (if (or (not bound) (if backward (>= found bound) (<= found bound)))
               (progn

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-05-09  6:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-05 16:52 bug#70789: treesit navigate for outlines at bobp Juri Linkov
2024-05-06  3:11 ` Yuan Fu
2024-05-06  6:43   ` Juri Linkov
2024-05-09  0:16     ` Yuan Fu
2024-05-09  6:28       ` Juri Linkov

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