Handle narrowed buffers in treesit-forward-sentence (bug#76679)

* lisp/treesit.el (treesit-forward-sentence): When no more
sentences are found, move to the end of the buffer or to
the range boundary at the 'treesit-parser' overlay's end.
This commit is contained in:
Juri Linkov 2025-03-13 20:44:54 +02:00
parent d1ce9fbf49
commit 59a67dcde4

View file

@ -3418,9 +3418,16 @@ What constitutes as text and source code sentence is determined
by `text' and `sentence' in `treesit-thing-settings'."
(if (treesit-node-match-p (treesit-node-at (point)) 'text t)
(funcall #'forward-sentence-default-function arg)
(funcall
(if (> arg 0) #'treesit-end-of-thing #'treesit-beginning-of-thing)
'sentence (abs arg))))
(or (funcall
(if (> arg 0) #'treesit-end-of-thing #'treesit-beginning-of-thing)
'sentence (abs arg))
;; On failure jump to the buffer's end as `forward-sentence' does,
;; but no further than the boundary of the current range.
(goto-char (if (> arg 0)
(min (point-max) (next-single-char-property-change
(point) 'treesit-parser))
(max (point-min) (previous-single-char-property-change
(point) 'treesit-parser)))))))
(defun treesit-forward-comment (&optional count)
"Tree-sitter `forward-comment-function' implementation.