我正在尝试在Visual Studio 2017中使用.clang格式的文件,我快到了,但是我在成员访问运算符(特别是->和。)上遇到了麻烦。我发现clang格式总是想在成员访问运算符之前放一个换行符,并且似乎没有办法告诉它不要这样做(我认为Visual Studio 2017支持clang 5:{{3} }。
我希望代码的格式如下:
const auto result = object->DoAThing(
input1,
input2->DoSomethingElse(),
input3 )->DoAnotherThing();
但我最终得到:
const auto result = object
->DoAThing(
input1,
input2->DoSomethingElse(),
input3 )
->DoAnotherThing();
似乎唯一可以防止此行为的参数是如果我增加了ColumnLimit(我不想这样做)。 我的.clang格式文件如下:
Language: Cpp
#DisableFormat: true
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
BreakStringLiterals: true
ColumnLimit: 110
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
FixNamespaceComments: true
IncludeCategories:
- Regex: '\/stdafx.h'
Priority: -1
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakAssignment: 10000
PenaltyBreakBeforeFirstCallParameter: 10
PenaltyBreakComment: 0
PenaltyBreakFirstLessLess: 100
PenaltyBreakString: 50
PenaltyExcessCharacter: 5
PenaltyReturnTypeOnItsOwnLine: 100
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesInAngles: true
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpacesInParentheses: true
SpacesInSquareBrackets: true
TabWidth: 4
UseTab: Never