From: Yuan Fu Date: Mon, 10 Oct 2022 18:14:35 +0000 (-0700) Subject: Improve treesit-search-forward-goto so it doens't stuck at EOF X-Git-Tag: emacs-29.0.90~1843 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b341864d9002fd081a8a6dfeb5a5a00373738a2f;p=emacs.git Improve treesit-search-forward-goto so it doens't stuck at EOF * lisp/treesit.el (treesit-search-forward-goto): Handle the edge case. --- diff --git a/lisp/treesit.el b/lisp/treesit.el index 34b501cfba8..2bcfddb56b6 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -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