Function: treesit-cycle-sexp-thing

treesit-cycle-sexp-thing is an interactive and byte-compiled function defined in treesit.el.gz.

Signature

(treesit-cycle-sexp-thing &optional INTERACTIVE)

Documentation

Cycle the type of navigation for sexp and list commands.

This type affects navigation commands such as treesit-forward-sexp, treesit-forward-list, treesit-down-list, treesit-up-list.

The type can be list (the default) or sexp.

The list type uses the list thing defined in treesit-thing-settings. See treesit-thing-at-point. With this type commands use syntax tables to navigate symbols and treesit definitions to navigate lists.

The sexp type uses the sexp thing defined in treesit-thing-settings. With this type commands use only the treesit definitions of parser nodes, without distinction between symbols and lists. Since tree-sitter grammars could group node types in arbitrary ways, navigation by sexp might not match your expectations, and might produce different results in different treesit-based modes.

Probably introduced at or before Emacs version 31.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-cycle-sexp-thing (&optional interactive)
  "Cycle the type of navigation for sexp and list commands.
This type affects navigation commands such as `treesit-forward-sexp',
`treesit-forward-list', `treesit-down-list', `treesit-up-list'.

The type can be `list' (the default) or `sexp'.

The `list' type uses the `list' thing defined in `treesit-thing-settings'.
See `treesit-thing-at-point'.  With this type commands use syntax tables to
navigate symbols and treesit definitions to navigate lists.

The `sexp' type uses the `sexp' thing defined in `treesit-thing-settings'.
With this type commands use only the treesit definitions of parser nodes,
without distinction between symbols and lists.  Since tree-sitter grammars
could group node types in arbitrary ways, navigation by `sexp' might not
match your expectations, and might produce different results in different
treesit-based modes."
  (interactive "p")
  (if (not (treesit-thing-defined-p 'list (treesit-language-at (point))))
      (user-error "No `list' thing is defined in `treesit-thing-settings'")
    (setq-local treesit-sexp-thing
                (unless treesit-sexp-thing
                  (if (treesit-thing-defined-p
                       'sexp (treesit-language-at (point)))
                      'sexp
                    #'treesit-node-named))
                forward-sexp-function
                (if treesit-sexp-thing
                    #'treesit-forward-sexp
                  #'treesit-forward-sexp-list))
    (when interactive
      (message "Cycle sexp thing to navigate %s"
               (or (and treesit-sexp-thing
                        "treesit nodes")
                   "syntax symbols and treesit lists")))))