Function: treesit--indent-1

treesit--indent-1 is a byte-compiled function defined in treesit.el.gz.

Signature

(treesit--indent-1)

Documentation

Indent the current line.

Return (ANCHOR . OFFSET). This function is used by treesit-indent and treesit-indent-region.

Source Code

;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit--indent-1 ()
  "Indent the current line.
Return (ANCHOR . OFFSET).  This function is used by
`treesit-indent' and `treesit-indent-region'."
  ;; Basically holds the common part between the two indent function.
  (let* ((bol (save-excursion
                (forward-line 0)
                (skip-chars-forward " \t")
                (point)))
         (smallest-node
          (cond ((null (treesit-parser-list)) nil)
                ((eq 1 (length (treesit-parser-list)))
                 (treesit-node-at bol))
                ((treesit-language-at bol)
                 (treesit-node-at bol (treesit-language-at bol)))
                (t (treesit-node-at bol))))
         (root (treesit-parser-root-node
                (treesit-node-parser smallest-node)))
         (node (treesit-parent-while
                smallest-node
                (lambda (node)
                  (and (eq bol (treesit-node-start node))
                       (not (treesit-node-eq node root)))))))
    (let*
        ((parser (if smallest-node
                     (treesit-node-parser smallest-node)
                   nil))
         ;; NODE would be nil if BOL is on a whitespace.  In that case
         ;; we set PARENT to the "node at point", which would
         ;; encompass the whitespace.
         (parent (cond ((and node parser)
                        (treesit-node-parent node))
                       (t (treesit-node-on bol bol)))))
      (funcall treesit-indent-function node parent bol))))