diff options
| author | Yuan Fu | 2023-05-19 00:15:21 -0700 |
|---|---|---|
| committer | Yuan Fu | 2023-05-19 00:20:33 -0700 |
| commit | 156973639cc57dec47705f76f63c2ef3dc00a61d (patch) | |
| tree | 47b54c7795fc3f68b0026978b8fd5dff51b75fe5 | |
| parent | 7ef20e0c81147bcbca0f5cc3fabc9bef5f6c3539 (diff) | |
| download | emacs-156973639cc57dec47705f76f63c2ef3dc00a61d.tar.gz emacs-156973639cc57dec47705f76f63c2ef3dc00a61d.zip | |
Implement treesit-forward-sexp correctly (bug#63487)
* lisp/treesit.el (treesit-forward-sexp): Signal scan-error when we
can't move across sexps further.
| -rw-r--r-- | lisp/treesit.el | 26 |
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'. |
| 1794 | ARG is described in the docstring of `forward-sexp-function'." | 1794 | |
| 1795 | ARG is described in the docstring of `forward-sexp-function'. If | ||
| 1796 | there are no further sexps to move across, signal `scan-error' | ||
| 1797 | like `forward-sexp' does. If point is already at top-level, | ||
| 1798 | return 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. |