]> git.eshelyaron.com Git - emacs.git/commitdiff
Add special indent rule for FOR_EACH_TAIL in c-ts-mode
authorYuan Fu <casouri@gmail.com>
Mon, 13 Jan 2025 07:03:41 +0000 (23:03 -0800)
committerEshel Yaron <me@eshelyaron.com>
Mon, 13 Jan 2025 12:12:05 +0000 (13:12 +0100)
* lisp/progmodes/c-ts-mode.el:
(c-ts-mode--emacs-macro-rules): New function
(c-ts-mode--simple-indent-rules): Add new rule.

(cherry picked from commit 8cfa3447b71a3586378e90e5690da6c1faaa77b6)

lisp/progmodes/c-ts-mode.el

index 99e624412b2c52e367e7c9b9ec764c42199983e8..d0ed110abbba13599d999375390230ecf7055501 100644 (file)
@@ -445,6 +445,18 @@ NODE and PARENT are the same as other indent rules."
         (cons (funcall parent-bol)
               c-ts-mode-indent-offset))))))
 
+(defun c-ts-mode--emacs-macro-rules (_ parent &rest _)
+  "Rules for indenting macros in Emacs C source.
+
+PARENT is the same as other simple-indent rules."
+  (cond
+   ((and (treesit-node-match-p parent "function_definition")
+         (equal (treesit-node-text
+                 (treesit-node-child-by-field-name parent "type"))
+                "FOR_EACH_TAIL"))
+    (cons (treesit-node-start parent)
+          c-ts-mode-indent-offset))))
+
 (defun c-ts-mode--simple-indent-rules (mode style)
   "Return the indent rules for MODE and STYLE.
 
@@ -466,6 +478,7 @@ MODE can be `c' or `cpp'.  STYLE can be `gnu', `k&r', `linux', `bsd'."
            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.