问题
I would like to use clang-format to product C functions like:
void cfg_InitConfig
(
cfg_Config_t* cfg,
char* name
)
{
// TODO function
}
After reading the manual I don't think clang-format can do it. Is it possible?
回答1:
I have studied lot of lot of documents according to your problem. Unfortunately there is no way to break your code like this
void cfg_InitConfig
(
cfg_Config_t* cfg,
char* name
)
but someone can be create patch for break that kind of alignment it could be possible. Creating that kind of patch not so much easy.
but if you use this, you can get close answer(80% correct) but not actually you want. here is the code
BinPackArguments : false
BinPackParameters: false
AlignConsecutiveAssignments : true
AlignConsecutiveDeclarations: true
using this outcome will be
void cfg_InitConfig(cfg_Config_t* cfgxxxxxxxxxx,
char* namexxxxxxxx)
{
// TODO function
}
you have to extend your variable names of the function unless they could fit on one line
Reference
回答2:
This is my current best solution to break function parameters to have code fences instead of long lines. I hope you can find something useful here.
In order to become fenced the code in question has to be longer than a limit, so here is how it formats the longer example:
void cfg_InitConfig(cfg_Config_t *cfgxxxxxxxxxxxxxx,
char *namexxxxxxxxxxxxxxxxxxx) {
// TODO function
}
The ! symbol means that the lines have to do with code fences.
---
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
来源:https://stackoverflow.com/questions/58995419/clang-format-break-function-parameters