Function: treesit--forward-list-with-default
treesit--forward-list-with-default is a byte-compiled function defined
in treesit.el.gz.
Signature
(treesit--forward-list-with-default ARG DEFAULT-FUNCTION)
Documentation
Move forward across a list.
Fall back to DEFAULT-FUNCTION as long as it doesn't cross the boundaries of the list.
ARG is described in the docstring of forward-list.
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit--forward-list-with-default (arg default-function)
"Move forward across a list.
Fall back to DEFAULT-FUNCTION as long as it doesn't cross
the boundaries of the list.
ARG is described in the docstring of `forward-list'."
(let* ((pred (or treesit-sexp-thing 'list))
(arg (or arg 1))
(treesit--parser-overlay-offset (if (> arg 0) 0 -1))
(cnt arg)
(inc (if (> arg 0) 1 -1)))
(while (/= cnt 0)
(let* ((default-pos
(condition-case _
(save-excursion
(funcall default-function inc)
(point))
(scan-error nil)))
(parent (treesit-thing-at (point) pred t))
(sibling (if (> arg 0)
(treesit-thing-next (point) pred)
(treesit-thing-prev (point) pred))))
(when (and parent sibling
(not (treesit-node-enclosed-p sibling parent)))
(setq sibling nil))
;; Use the default function only if it doesn't go
;; over the sibling and doesn't go out of the current group.
(or (when (and default-pos
;; Fallback to the default sexp function when
;; matching the thing 'sexp-default' at point.
(treesit-node-match-p
(treesit-node-at (if (> arg 0) (point)
(max (1- (point)) (point-min))))
'sexp-default t))
(goto-char default-pos))
(when (and default-pos
(or (null sibling)
(if (> arg 0)
(<= default-pos (treesit-node-start sibling))
(>= default-pos (treesit-node-end sibling))))
(or (null parent)
(if (> arg 0)
(< default-pos (treesit-node-end parent))
(> default-pos (treesit-node-start parent)))))
(goto-char default-pos))
(when sibling
(goto-char (if (> arg 0)
(treesit-node-end sibling)
(treesit-node-start sibling))))
(treesit--scan-error pred arg)))
(setq cnt (- cnt inc)))))