我想使用 clang-format 来生成 C 函数,例如:
void cfg_InitConfig
(
cfg_Config_t* cfg,
char* name
)
{
// TODO function
}
阅读手册后,我认为 clang-format 无法做到。
是否可以?
最佳答案
这是我当前打破函数参数以使用代码围栏而不是长行的最佳解决方案。我希望你能在这里找到有用的东西。
为了被围栏,有问题的代码必须比限制长,所以这里是它如何格式化更长的例子:
void cfg_InitConfig(cfg_Config_t *cfgxxxxxxxxxxxxxx,
char *namexxxxxxxxxxxxxxxxxxx) {
// TODO function
}
! 符号表示这些行与代码围栏有关。
---
Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignOperands: false
AlignTrailingComments: false
# !
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
# !
BinPackArguments: false
BinPackParameters: false
ColumnLimit: 80
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
CompactNamespaces: false
IncludeBlocks: Preserve
IndentWidth: 2
DerivePointerAlignment: false
PointerAlignment: Right
SortIncludes: true
SortUsingDeclarations: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: true
关于clang-format:中断函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58995419/