Function: python-info-treesit-current-defun

python-info-treesit-current-defun is a byte-compiled function defined in python.el.gz.

Signature

(python-info-treesit-current-defun &optional INCLUDE-TYPE)

Documentation

Identical to python-info-current-defun but use tree-sitter.

For INCLUDE-TYPE see python-info-current-defun.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(defun python-info-treesit-current-defun (&optional include-type)
  "Identical to `python-info-current-defun' but use tree-sitter.
For INCLUDE-TYPE see `python-info-current-defun'."
  (let ((node (treesit-node-at (point)))
        (name-list ())
        (type 'def))
    (cl-loop while node
             if (pcase (treesit-node-type node)
                  ("function_definition"
                   (setq type 'def))
                  ("class_definition"
                   (setq type 'class))
                  (_ nil))
             do (push (treesit-node-text
                       (treesit-node-child-by-field-name node "name")
                       t)
                      name-list)
             do (setq node (treesit-node-parent node))
             finally return (concat (if include-type
                                        (format "%s " type)
                                      "")
                                    (string-join name-list ".")))))