Function: treesit-end-of-defun
treesit-end-of-defun is an interactive and byte-compiled function
defined in treesit.el.gz.
Signature
(treesit-end-of-defun &optional ARG _)
Documentation
Move forward to next end of defun.
With argument ARG, do it that many times. Negative argument -N means move back to Nth preceding end of defun.
This is a tree-sitter equivalent of end-of-defun. Behavior of
this function depends on treesit-defun-type-regexp and
treesit-defun-skipper.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-end-of-defun (&optional arg _)
"Move forward to next end of defun.
With argument ARG, do it that many times.
Negative argument -N means move back to Nth preceding end of defun.
This is a tree-sitter equivalent of `end-of-defun'. Behavior of
this function depends on `treesit-defun-type-regexp' and
`treesit-defun-skipper'."
(interactive "^p\nd")
(let ((orig-point (point)))
(if (or (null arg) (= arg 0)) (setq arg 1))
(or (not (eq this-command 'treesit-end-of-defun))
(eq last-command 'treesit-end-of-defun)
(and transient-mark-mode mark-active)
(push-mark))
(catch 'done
(dotimes (_ 2) ; Not making progress is better than infloop.
(when (treesit-end-of-thing treesit-defun-type-regexp arg)
(when treesit-defun-skipper
(funcall treesit-defun-skipper)))
;; If we end up at the same point, it means we went to the
;; prev end-of-defun, but defun skipper moved point back to
;; where we started, in this case we just move one step
;; further.
(if (or (eq arg 0) (not (eq orig-point (point))))
(throw 'done nil)
(setq arg (if (> arg 0) (1+ arg) (1- arg))))))))