Reputation: 143
I want to use clang-format, but it always starts with a new line after the returnType. I read the documentation and tried
"AlwaysBreakAfterReturnType : None"
but this seams to have no effect. I'm using clang-format 6.0 in ubuntu 17.10 inside QT creator.
is:
int
main() {
...
}
expected:
int main() {
...
}
Version: clang-format 6.0, clang-format config file:
BasedOnStyle: Mozilla
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments : true
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: true
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakStringLiterals : false
ColumnLimit: 120
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: true
IndentCaseLabels: false
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword : false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 3
SpacesInAngles: false
SpacesInCStyleCastParentheses: true
SpacesInContainerLiterals: true
SpacesInParentheses: true
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
Any ideas?
Upvotes: 7
Views: 4607
Reputation: 346
Just try to assign the deprecated property 'AlwaysBreakAfterDefinitionReturnType' to 'None' too.
This works well for me.
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
Upvotes: 6
Reputation: 1973
You should read the documentation carefully:
RTBS_None (in configuration: None) Break after return type automatically. PenaltyReturnTypeOnItsOwnLine is taken into account.
So "None" doesn't mean that it will never break after return type, it will take into account other settings like BinPackParameters
, BraceWrapping
, etc. and their penalties.
To make breaking after return type less likely or "almost" turned off you can set PenaltyReturnTypeOnItsOwnLine
to a very high value, for example:
PenaltyReturnTypeOnItsOwnLine: 1000000
Please note that I'm not that familiar what exactly penalties numbers mean, how they relate to each other and how the final line breaking is calculated. You'll have to find that information elsewhere (source code of clang-format?).
Upvotes: 7
Reputation: 16497
I can't reproduce your issue on the minimal example you provide as comment:
$ cat .clang-format
BasedOnStyle: Mozilla
AlwaysBreakAfterReturnType: None
$ cat main.c
int main() {
return 0;
}
$ clang-format main.c
int
main()
{
return 0;
}
$ clang-format --version
clang-format version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Indeed, you have also set IndentWrappedFunctionNames
, whose behavior is exactly the one you obtain. If you don't want this behavior, then don't set IndentWrappedFunctionNames
.
Upvotes: 0