Function: c-ts-mode--for-loop-indent-rule

c-ts-mode--for-loop-indent-rule is a byte-compiled function defined in c-ts-mode.el.gz.

Signature

(c-ts-mode--for-loop-indent-rule NODE PARENT &rest _)

Documentation

Indentation rule for the for-loop.

NODE and PARENT as usual.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/c-ts-mode.el.gz
(defun c-ts-mode--for-loop-indent-rule (node parent &rest _)
  "Indentation rule for the for-loop.

NODE and PARENT as usual."
  (when (treesit-node-match-p parent "for_statement")
    ;; The first version of this function tests for the field name of
    ;; NODE, which is a lot cleaner.  Alas, older tree-sitter library
    ;; has a bug in treesit-node-field-name-for-child, which make it
    ;; give the wrong field name for a child node.
    (cond
     ;; Body (Check if NODE is the last child, because when
     ;; initializer/condition/update is empty, the index of body can
     ;; change). Eg, for (;;) {...}
     ((treesit-node-eq node (treesit-node-child parent -1 'named))
      (cons (c-ts-common--standalone-parent parent)
            c-ts-mode-indent-offset))
     ;; Initializer.
     ((and (treesit-node-check node 'named)
           (eq (treesit-node-index node 'named) 0 ))
      ;; Anchor is the opening paren.
      (cons (treesit-node-start (treesit-node-child parent 1)) 1))
     ;; Condition and update.
     ((and (treesit-node-check node 'named)
           (<= 1 (treesit-node-index node 'named) 2))
      (cons (treesit-node-start (treesit-node-prev-sibling node 'named))
            0))
     ((treesit-node-match-p node ")")
      ;; Anchor is the opening paren.
      (cons (treesit-node-start (treesit-node-child parent 1)) 0))
     (t nil))))