clang-format的作用:
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 bodies?在文档中找不到任何有关它的内容。
这就是我到目前为止所知道的:
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发布于 2016-06-15 20:13:12
您在clang-format上使用的是哪个版本?
最新版本(v3.9.0或v3.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还没有专门针对lambda的成员。
发布于 2021-12-27 16:37:01
对于任何想知道2021年的人来说,从Clang 13开始有一个LambdaBodyIndentation选项。
LambdaBodyIndentation: OuterScopehttps://stackoverflow.com/questions/33090649
复制相似问题