1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-04-28 01:00:52 -07:00

Improve treesit-search-forward-goto so it doens't stuck at EOF

* lisp/treesit.el (treesit-search-forward-goto): Handle the edge case.
This commit is contained in:
Yuan Fu 2022-10-10 11:14:35 -07:00
parent 2f6b017e3d
commit b341864d90
No known key found for this signature in database
GPG key ID: 56E19BC57664A442

View file

@ -826,6 +826,12 @@ or end of the matches node, it can be either \\='start or
ALL, BACKWARD, and UP are the same as in `treesit-search-forward'."
(let ((node (treesit-node-at (point)))
(start (point)))
;; Often the EOF (point-max) is a newline, and `treesit-node-at'
;; will return nil at that point (which is fair). But we need a
;; node as the starting point to traverse the tree. So we try to
;; use the node before point.
(when (and (not node) (eq (point) (point-max)))
(setq node (treesit-node-at (max (1- (point)) (point-min)))))
;; When searching forward, it is possible for (point) < start,
;; because `treesit-search-forward' goes to parents.
(while (and node (if backward