aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/treesit.el26
1 files changed, 21 insertions, 5 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 49eeba64a14..cc7ec977851 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -1791,12 +1791,28 @@ however, smaller in scope than sentences. This is used by
1791 1791
1792(defun treesit-forward-sexp (&optional arg) 1792(defun treesit-forward-sexp (&optional arg)
1793 "Tree-sitter implementation for `forward-sexp-function'. 1793 "Tree-sitter implementation for `forward-sexp-function'.
1794ARG is described in the docstring of `forward-sexp-function'." 1794
1795ARG is described in the docstring of `forward-sexp-function'. If
1796there are no further sexps to move across, signal `scan-error'
1797like `forward-sexp' does. If point is already at top-level,
1798return nil without moving point."
1795 (interactive "^p") 1799 (interactive "^p")
1796 (or arg (setq arg 1)) 1800 (let ((arg (or arg 1))
1797 (funcall 1801 (pred treesit-sexp-type-regexp))
1798 (if (> arg 0) #'treesit-end-of-thing #'treesit-beginning-of-thing) 1802 (or (if (> arg 0)
1799 treesit-sexp-type-regexp (abs arg) 'restricted)) 1803 (treesit-end-of-thing pred (abs arg) 'restricted)
1804 (treesit-beginning-of-thing pred (abs arg) 'restricted))
1805 ;; If we couldn't move, we should signal an error and report
1806 ;; the obstacle, like `forward-sexp' does. If we couldn't
1807 ;; find a parent, we simply return nil without moving point,
1808 ;; then functions like `up-list' will signal "at top level".
1809 (when-let* ((parent (nth 2 (treesit--things-around (point) pred)))
1810 (boundary (if (> arg 0)
1811 (treesit-node-child parent -1)
1812 (treesit-node-child parent 0))))
1813 (signal 'scan-error (list "No more sexp to move across"
1814 (treesit-node-start boundary)
1815 (treesit-node-end boundary)))))))
1800 1816
1801(defun treesit-transpose-sexps (&optional arg) 1817(defun treesit-transpose-sexps (&optional arg)
1802 "Tree-sitter `transpose-sexps' function. 1818 "Tree-sitter `transpose-sexps' function.