I'm looking for a way to format the C++ code below with clang-format (version 9.0.0) such that function definitions that exceed the 80 column limit are broken after argument declarations instead of C++ function qualifiers like noexcept
:
void scheduler::stop_mark(service ¤t, service const &stopped) const
noexcept {
// ...
}
The snippet above shows my code formatted with the LLVM
default style and the code below is the one I want to have after proper formatting:
void scheduler::stop_mark(service& current,
service const& stopped) const noexcept {
// ...
}
The difference between both snippets is that the line is broken after service& current,
instead of noexcept
.
This behaviour is reproducible when using the LLVM
default style but I'm using the options below for reference:
---
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
...
Is it possible to get such a formatting through clang-format?
I inspected all possible options on https://zed0.co.uk/clang-format-configurator/ already and could not find the matching clang-format option.
I am in agreement that no combination of rules will get the desired output, but there is a way to force it when you spot stuff like this.
Add a line comment (can be empty) after your first parameter. clang-format will then align your parameters for you.
void scheduler::stop_mark(service& current, //
service const& stopped) const noexcept {
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With