summaryrefslogtreecommitdiff
path: root/lisp/treesit.el
diff options
context:
space:
mode:
authorJuri Linkov <juri@linkov.net>2024-05-09 09:28:50 +0300
committerJuri Linkov <juri@linkov.net>2024-05-09 09:28:50 +0300
commit9b7dd30807ed4be9afe4f66cfa5130aa7d178989 (patch)
tree76ac8f08834c5e35f86344d74c729904c209d569 /lisp/treesit.el
parent24c02c700cad3ed94687cf694856a0bee42405ba (diff)
downloademacs-9b7dd30807ed4be9afe4f66cfa5130aa7d178989.tar.gz
* lisp/treesit.el (treesit-outline-search): Handle bobp specially.
At the beginning of the buffer call 'treesit-outline-search' recursively with the `looking-at' argument set to t, since `treesit-navigate-thing' can't find a thing at bobp (bug#70789).
Diffstat (limited to 'lisp/treesit.el')
-rw-r--r--lisp/treesit.el18
1 files changed, 12 insertions, 6 deletions
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 @@ See the descriptions of arguments in `outline-search-function'."
(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