Function: c-ts-mode--macro-heuristic-rules

c-ts-mode--macro-heuristic-rules is a byte-compiled function defined in c-ts-mode.el.gz.

Signature

(c-ts-mode--macro-heuristic-rules NODE PARENT &rest _)

Documentation

Heuristic indent rule for control flow macros.

Eg,

    #define IOTA(var, n) for (int var = 0; var != (n); ++var)

    int main()
    {
      IOTA (v, 10) {
        printf("%d ", v); <-- Here we want to indent
        counter++; <-- Use baseline rule to align
    } to prev sibling

Checked by "Compound Statement after code (Bug#74507)" test.

NODE and PARENT are the same as other indent rules.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/c-ts-mode.el.gz
(defun c-ts-mode--macro-heuristic-rules (node parent &rest _)
  "Heuristic indent rule for control flow macros.

Eg,

    #define IOTA(var, n) for (int var = 0; var != (n); ++var)

    int main()
    {
      IOTA (v, 10) {
        printf(\"%d \", v);   <-- Here we want to indent
        counter++;            <-- Use baseline rule to align
    }                             to prev sibling

Checked by \"Compound Statement after code (Bug#74507)\" test.

NODE and PARENT are the same as other indent rules."
  (when (and (treesit-node-match-p parent "compound_statement")
             (treesit-node-match-p (treesit-node-prev-sibling parent)
                                   "expression_statement"))
    (let ((parent-bol
           (lambda () (save-excursion
                        (goto-char (treesit-node-start parent))
                        (back-to-indentation)
                        (point)))))
      (cond
       ;; Closing brace.
       ((treesit-node-match-p node "}")
        (cons (funcall parent-bol) 0))
       ;; First sibling.
       ((treesit-node-eq (treesit-node-child parent 0 'named) node)
        (cons (funcall parent-bol)
              c-ts-mode-indent-offset))))))