使用 clang 格式缩进大括号

问题描述 投票:0回答:1

我想使用 clang-format 像这样缩进大括号,

for(...) 
   {
   [...] 
   [...]
   }

Clang-format 可以使用

BreakBeforeBraces: Whitesmiths
来做到这一点,但我想自定义它。手册似乎表明
IndentBraces
可以解决问题,但这会产生

for(...)
{
      [...]
   [...]
   }

还有其他奇怪的事情。是我使用错误还是这是一个错误? (使用 clang-format-13 进行测试)。

indentation code-formatting clang-format braces
1个回答
0
投票

我真的不知道怎么做,但我成功地使用了下面的配置,使 clang-format-17 具有大括号,并用这样的代码缩进

  template<concepts::point_type point_type>
  [[nodiscard, gnu::always_inline]]
  inline constexpr bool is_near_bound(rectangle_t<point_type> const & rect, point_type p) noexcept
    {
    auto const pl(algo::round(p));
    return (
      geom::detail::equals(x(pl), left(rect)) || geom::detail::equals(y(pl), top(rect))
      || geom::detail::equals(x(pl), right(rect)) || geom::detail::equals(y(pl), bottom(rect))
    );
    }

---
AlignConsecutiveBitFields:
  Enabled: true
  AcrossEmptyLines: false
  AcrossComments: false
BreakAfterAttributes: Always
BracedInitializerIndentWidth: 2
BraceWrapping:
  SplitEmptyNamespace: true
  AfterCaseLabel: true
  AfterClass: true
  AfterControlStatement: Always
  AfterEnum: true
  AfterFunction: true
  AfterNamespace: true
  AfterObjCDeclaration: true
  AfterStruct: true
  AfterExternBlock: true
  AfterUnion: true
  BeforeCatch: true
  BeforeElse: true
  BeforeLambdaBody: true
  BeforeWhile: true
  IndentBraces: true
  SplitEmptyFunction: true
  SplitEmptyRecord: true
BitFieldColonSpacing: Both
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Whitesmiths
BreakBeforeConceptDeclarations: Always
BreakBeforeInlineASMColon: Always
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
BreakStringLiterals: true
ColumnLimit: 120
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
FixNamespaceComments: true
IncludeBlocks: Preserve
IndentAccessModifiers: false
IndentCaseBlocks: true
IndentCaseLabels: true
IndentExternBlock: Indent
IndentGotoLabels: false
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 2
IndentWrappedFunctionNames: true
InsertBraces: false
InsertNewlineAtEOF: true
InsertTrailingCommas: None
KeepEmptyLinesAtEOF: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
Language: Cpp
LineEnding: DeriveLF
NamespaceIndentation: Inner
PPIndentWidth: 0
PackConstructorInitializers: CurrentLine
PointerAlignment: Middle
QualifierAlignment: Right
ReferenceAlignment: Middle
ReflowComments: true
RemoveBracesLLVM: true
RemoveParentheses: MultipleParentheses
RemoveSemicolon: true
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Always
ShortNamespaceLines: 1
SortIncludes: Never
SortUsingDeclarations: Never
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: Both
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeJsonColon: true
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: false
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: Never
SpacesInContainerLiterals: false
SpacesInLineCommentPrefix:
  Minimum: 1
  Maximum: -1
SpacesInParens: Never
SpacesInParensOptions:
  InCStyleCasts: false
  InConditionalStatements: false
  InEmptyParentheses: false
  Other: false
SpacesInSquareBrackets: false
Standard: Latest
TabWidth: 2
UseTab: Never
AlignConsecutiveAssignments:
  Enabled: false
  AcrossEmptyLines: false
  AcrossComments: false
AlignConsecutiveDeclarations:
  Enabled: false
AlignConsecutiveMacros:
  Enabled: false
AlignConsecutiveShortCaseStatements:
  Enabled: true
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments:
  Kind: Always
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
AlignAfterOpenBracket: BlockIndent
© www.soinside.com 2019 - 2024. All rights reserved.