【发布时间】:2020-06-26 00:01:55
【问题描述】:
我正在寻找一种方法来使用 clang-format(版本 9.0.0)格式化下面的 C++ 代码,以便在参数声明后破坏超过 80 列限制的函数定义,而不是像 noexcept 这样的 C++ 函数限定符:
void scheduler::stop_mark(service ¤t, service const &stopped) const
noexcept {
// ...
}
上面的 sn-p 显示了我使用 LLVM 默认样式格式化的代码,下面的代码是我在正确格式化后想要的代码:
void scheduler::stop_mark(service& current,
service const& stopped) const noexcept {
// ...
}
这两种sn-ps的区别在于,断行是在service& current,之后,而不是noexcept之后。
使用LLVM 默认样式时,此行为是可重现的,但我使用以下选项作为参考:
---
BasedOnStyle: LLVM
AlignAfterOpenBracket: Align
AllowAllArgumentsOnNextLine: 'true'
AllowAllConstructorInitializersOnNextLine: 'true'
AllowAllParametersOfDeclarationOnNextLine: 'true'
AllowShortCaseLabelsOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: Empty
AllowShortLambdasOnASingleLine: Empty
AlwaysBreakTemplateDeclarations: 'Yes'
BinPackArguments: 'true'
BinPackParameters: 'true'
BreakConstructorInitializers: BeforeComma
BreakConstructorInitializersBeforeComma: 'true'
ConstructorInitializerIndentWidth: 2
FixNamespaceComments: 'true'
IndentCaseLabels: 'true'
IndentPPDirectives: AfterHash
PenaltyBreakAssignment: 1000
PenaltyBreakBeforeFirstCallParameter: 50
PointerAlignment: Left
...
是否可以通过clang-format得到这样的格式?
我已经检查了https://zed0.co.uk/clang-format-configurator/ 上所有可能的选项,但找不到匹配的 clang-format 选项。
【问题讨论】:
-
FWIW,它似乎将括号括起来的输入(例如:param decl)视为一个单元,在匹配括号时不会拆分,即
(和)在同一行内列限制。
标签: c++ llvm clang-format