铿锵格式:
QObject::connect(&w, &sap::Window::keyPress, [&w](auto* event)
{
if(event->key() == Qt::Key_Escape)
w.close();
});
我想要的是什么:
QObject::connect(&w, &sap::Window::keyPress, [&w](auto* event)
{
if(event->key() == Qt::Key_Escape)
w.close();
});
有没有办法让clang-format不缩进lambda体?在文档中找不到任何相关内容。
这是我到目前为止所做的:
BasedOnStyle: LLVM,
BreakBeforeBraces: Allman,
NamespaceIndentation: All,
SpaceBeforeParens: Never,
AccessModifierOffset: -4,
AllowShortIfStatementsOnASingleLine: false,
AllowShortBlocksOnASingleLine: false,
AllowShortFunctionsOnASingleLine: None,
AllowShortCaseLabelsOnASingleLine: false,
AllowShortLoopsOnASingleLine: false,
ColumnLimit: 100,
AlwaysBreakTemplateDeclarations: true,
PenaltyReturnTypeOnItsOwnLine: 9999,
IndentWidth: 4,
PointerAlignment: Left
答案 0 :(得分:1)
您使用clang-format
上的哪个版本?
最新版本(v3.9.0
或v 3.8.0
)的默认配置几乎可以满足您的需求:
QObject::connect(&w, &sap::Window::keyPress, [&w](auto *event) {
if (event->key() == Qt::Key_Escape)
w.close();
});
您可以在线试用:http://zed0.co.uk/clang-format-configurator/
但是对于更长的参数包,默认配置返回:
QObject::connect(sender, &sap::ClassName::signalName, receiver,
&sap::OtherClass::slotFunc,
[this](auto dummy, const auto* event) {
if (event->key() == Qt::Key_Escape)
doStuff();
});
.clang-format
这样:
BasedOnStyle: LLVM
IndentWidth: 4
ColumnLimit: 80
Language: Cpp
AlignAfterOpenBracket: AlwaysBreak
BinPackArguments: false
BinPackParameters: false
PointerAlignment: Left
你会得到:
QObject::connect(&w, &sap::Window::keyPress, [&w](auto* event) {
if (event->key() == Qt::Key_Escape)
w.close();
});
QObject::connect(
sender,
&sap::ClassName::signalName,
receiver,
&sap::OtherClass::slotFunc,
[this](auto dummy, const auto* event) {
if (event->key() == Qt::Key_Escape)
doStuff();
});
目前,BraceWrapping
没有lambdas的特殊成员。