我试图弄清楚是否可以使用clang-format来获取参数/参数的方式。
我已经尝试了很多东西但是到目前为止我只能得到这个:
SDL_SetRenderDrawColor(renderer,153 + floor(toGreenRed * percentage),51 + floor(toGreenGreen * percentage),51 + floor(toGreenBlue * percentage),255);
格式化为:
SDL_SetRenderDrawColor(renderer,
153 + floor(toGreenRed * percentage),
51 + floor(toGreenGreen * percentage),
51 + floor(toGreenBlue * percentage),
255);
但我想要这个:
SDL_SetRenderDrawColor(
renderer,
153 + floor(toGreenRed * percentage),
51 + floor(toGreenGreen * percentage),
51 + floor(toGreenBlue * percentage),
255
);
目前也是这样:
void renderHealthBox( SDL_Renderer *renderer, int sideUiWidth, int yOffset, float percentage, float laksjdlkajsdlkasjdlkasjd) {
格式化为:
void renderHealthBox(
SDL_Renderer *renderer, int sideUiWidth, int yOffset, float percentage, float laksjdlkajsdlkasjdlkasjd) {
但是我想要:
void renderHealthBox(
SDL_Renderer *renderer,
int sideUiWidth,
int yOffset,
float percentage,
float laksjdlkajsdlkasjdlkasjd
) {
我想用clang格式寻找什么?
我当前的配置是:
Language: Cpp
IndentWidth: 2
ObjCBlockIndentWidth: 2
ContinuationIndentWidth: 2
ColumnLimit: 120
BinPackArguments: false
BinPackParameters: false
AlignAfterOpenBracket: DontAlign
IndentCaseLabels: true
答案 0 :(得分:0)
这种配置是否足够好?它基于@ hit的评论,但我不认为这个问题与另一个问题重复。它的主要部分是AlignAfterOpenBracket: AlwaysBreak
。来自clang-format documentation:
BAS_AlwaysBreak
(在配置中:AlwaysBreak
)如果参数不适合单行,则在打开括号后总是中断
.clang-format
:
Language: Cpp
IndentWidth: 2
ObjCBlockIndentWidth: 2
ContinuationIndentWidth: 2
ColumnLimit: 120
BinPackArguments: false
BinPackParameters: false
AlignAfterOpenBracket: AlwaysBreak
IndentCaseLabels: true
AllowAllParametersOfDeclarationOnNextLine: false
test.cpp
:
void renderHealthBox(SDL_Renderer *renderer, int sideUiWidth, int yOffset, float percentage, float laksjdlkajsdlkasjdlkasjd) {
}
int main()
{
SDL_SetRenderDrawColor(renderer,153 + floor(toGreenRed * percentage),51 + floor(toGreenGreen * percentage),51 + floor(toGreenBlue * percentage),255);
}
$ clang-format test.cpp
:
void renderHealthBox(
SDL_Renderer *renderer,
int sideUiWidth,
int yOffset,
float percentage,
float laksjdlkajsdlkasjdlkasjd) {}
int main() {
SDL_SetRenderDrawColor(
renderer,
153 + floor(toGreenRed * percentage),
51 + floor(toGreenGreen * percentage),
51 + floor(toGreenBlue * percentage),
255);
}
与您想要的格式的唯一区别是,右括号不在他们自己的行上。我认为这有点奇怪的要求,所以我认为用clang-format
来实现它是不可能的。