Function: c-ts-mode--simple-indent-rules
c-ts-mode--simple-indent-rules is a byte-compiled function defined in
c-ts-mode.el.gz.
Signature
(c-ts-mode--simple-indent-rules MODE STYLE)
Documentation
Return the indent rules for MODE and STYLE.
The returned value can be set to treesit-simple-indent-rules.
MODE can be c or cpp. STYLE can be gnu, k&r, linux, bsd.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/c-ts-mode.el.gz
(defun c-ts-mode--simple-indent-rules (mode style)
"Return the indent rules for MODE and STYLE.
The returned value can be set to `treesit-simple-indent-rules'.
MODE can be `c' or `cpp'. STYLE can be `gnu', `k&r', `linux', `bsd'."
(let ((rules
`((c-ts-mode--for-each-tail-body-matcher
prev-line c-ts-mode-indent-offset)
;; Misc overrides.
((parent-is "translation_unit") column-0 0)
((node-is ,(rx (or "else" "case"))) standalone-parent 0)
;; Align the while keyword to the do keyword.
((match "while" "do_statement") parent 0)
c-ts-mode--parenthesized-expression-indent-rule
;; Thanks to tree-sitter-c's weird for-loop grammar, we can't
;; use the baseline indent rule for it.
c-ts-mode--for-loop-indent-rule
c-ts-mode--label-indent-rules
,@c-ts-mode--preproc-indent-rules
c-ts-mode--macro-heuristic-rules
c-ts-mode--emacs-macro-rules
;; Make sure type and function definition components align and
;; don't indent. Also takes care of GNU style opening braces.
((parent-is ,(rx (or "function_definition"
"struct_specifier"
"enum_specifier"
"function_declarator"
"template_declaration")))
standalone-parent 0)
;; This is for the trailing-star stype: int *
;; func()
((match "function_declarator" nil "declarator") parent-bol 0)
;; ((match nil "function_definition" "declarator") parent 0)
;; ((match nil "struct_specifier" "name") parent 0)
;; ((match nil "function_declarator" "parameters") parent 0)
;; ((parent-is "template_declaration") parent 0)
;; `c-ts-common-looking-at-star' has to come before
;; `c-ts-common-comment-2nd-line-matcher'.
;; FIXME: consolidate into a single rule.
((and (parent-is "comment") c-ts-common-looking-at-star)
c-ts-common-comment-start-after-first-star -1)
(c-ts-common-comment-2nd-line-matcher
c-ts-common-comment-2nd-line-anchor
1)
((parent-is "comment") prev-adaptive-prefix 0)
;; Preproc directives
((node-is "preproc_arg") no-indent)
((node-is "preproc") column-0 0)
((node-is "#endif") column-0 0)
;; C++
((node-is "access_specifier") parent-bol 0)
((prev-line-is "access_specifier")
parent-bol c-ts-mode-indent-offset)
c-ts-common-baseline-indent-rule)))
(setq rules
(pcase style
('gnu rules)
('k&r rules)
('linux
;; Reference:
;; https://www.kernel.org/doc/html/latest/process/coding-style.html,
;; and script/Lindent in Linux kernel repository.
`(((node-is "labeled_statement") column-0 0)
,@rules))
('bsd
`(((match "compound_statement" "compound_statement")
standalone-parent c-ts-mode-indent-offset)
((node-is "compound_statement") standalone-parent 0)
,@rules))))
(pcase mode
('c `((c . ,rules)))
('cpp `((cpp . ,rules))))))