如何配置clang-format使宏定义的函数声明保持逐行显示
Alright, I've got you covered here. The key is to tell clang-format that your DECL_DigOut macro should be treated as a standalone statement—this way, it'll automatically break each invocation onto its own line.
Here's how to do it:
Update your .clang-format configuration
Add theStatementMacrosoption to your config file, and includeDECL_DigOutin the list. This tells clang-format to treat calls to this macro as individual statements, just like regular function calls or variable declarations.Example .clang-format snippet:
# Other existing config options... StatementMacros: - DECL_DigOutRun clang-format again
With this change, your problematic line of consecutiveDECL_DigOutcalls will be formatted to:DECL_DigOut(LED0, 4, 23, 0) DECL_DigOut(LED1, 4, 25, 0) DECL_DigOut(MAIN_HW0, 3, 14, 0) DECL_DigOut(MAIN_HW1, 3, 15, 0) DECL_DigOut(MAIN_HW2, 3, 16, 0)
Why this works
The StatementMacros list identifies macros that act as statements (even if they don't end with a semicolon). Clang-format will then apply statement-level formatting rules to them, including breaking each invocation onto a new line instead of keeping them all in one line.
If you have other similar macros (like DECL_GPO if you ever call it directly), you can add those to the StatementMacros list too to get the same behavior.
内容的提问来源于stack exchange,提问作者mastupristi

