Function: python-imenu-treesit-create-index
python-imenu-treesit-create-index is a byte-compiled function defined
in python.el.gz.
Signature
(python-imenu-treesit-create-index &optional NODE)
Documentation
Return tree Imenu alist for the current Python buffer.
Change python-imenu-format-item-label-function,
python-imenu-format-parent-item-label-function,
python-imenu-format-parent-item-jump-label-function to
customize how labels are formatted.
NODE is the root node of the subtree you want to build an index of. If nil, use the root node of the whole parse tree.
Similar to python-imenu-create-index but use tree-sitter.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(defun python-imenu-treesit-create-index (&optional node)
"Return tree Imenu alist for the current Python buffer.
Change `python-imenu-format-item-label-function',
`python-imenu-format-parent-item-label-function',
`python-imenu-format-parent-item-jump-label-function' to
customize how labels are formatted.
NODE is the root node of the subtree you want to build an index
of. If nil, use the root node of the whole parse tree.
Similar to `python-imenu-create-index' but use tree-sitter."
(let* ((node (or node (treesit-buffer-root-node 'python)))
(tree (treesit-induce-sparse-tree
node
(rx (seq bol
(or "function" "class")
"_definition"
eol))
nil 1000)))
(python--imenu-treesit-create-index-1 tree)))