Function: treesit-outline-level

treesit-outline-level is a byte-compiled function defined in treesit.el.gz.

Signature

(treesit-outline-level)

Documentation

Return the depth of the current outline heading.

Source Code

;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-outline-level ()
  "Return the depth of the current outline heading."
  (let* ((node (treesit-outline--at-point))
         (level 1)
         (pred (if treesit-aggregated-outline-predicate
                   (alist-get (treesit-language-at (point))
                              treesit-aggregated-outline-predicate)
                 treesit-outline-predicate)))
    (while (setq node (treesit-parent-until node pred))
      (setq level (1+ level)))

    ;; Continue counting the host nodes.
    (dolist (parser (mapcar #'cdr (treesit-parsers-at (point) nil t '(global local))))
      (let* ((node (treesit-node-at (point) parser))
             (lang (treesit-parser-language parser))
             (pred (alist-get lang treesit-aggregated-outline-predicate)))
        (while (setq node (treesit-parent-until node pred))
          (setq level (1+ level)))))

    level))