Function: treesit-transpose-sexps
treesit-transpose-sexps is a byte-compiled function defined in
treesit.el.gz.
Signature
(treesit-transpose-sexps &optional ARG)
Documentation
Tree-sitter transpose-sexps function.
ARG is the same as in transpose-sexps.
Locate the named node closest to POINT, and transpose that node with its named sibling node ARG nodes away.
Return a pair of positions as described by
transpose-sexps-function for use in transpose-subr and
friends.
Probably introduced at or before Emacs version 30.1.
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-transpose-sexps (&optional arg)
"Tree-sitter `transpose-sexps' function.
ARG is the same as in `transpose-sexps'.
Locate the named node closest to POINT, and transpose that node with
its named sibling node ARG nodes away.
Return a pair of positions as described by
`transpose-sexps-function' for use in `transpose-subr' and
friends."
(let* ((pred #'treesit-node-named)
(arg (or arg 1))
(cnt arg)
(inc (if (> arg 0) 1 -1))
(pos (point))
first sibling)
(while (and pos (/= cnt 0))
(setq sibling (if (> arg 0)
(treesit-thing-next pos pred)
(treesit-thing-prev pos pred)))
(unless first
(setq first (if (> arg 0)
(treesit-node-start sibling)
(treesit-node-end sibling))))
(setq pos (when sibling
(if (> arg 0)
(treesit-node-end sibling)
(treesit-node-start sibling))))
(setq cnt (- cnt inc)))
(or (and sibling (cons pos first))
(transpose-sexps-default-function arg))))