如何设置Clang-Format样式选项以在catch之前不保留换行符?

时间:2014-01-23 12:00:50

标签: c++ formatting clang clang-format

所以目前我使用下一种风格:

{ 
  BasedOnStyle: "LLVM", 
  IndentWidth: 4,   
  UseTab: false, 
  ColumnLimit: 150, 
  Standard: "Cpp11",
  BreakBeforeBraces: "Attach",  
  BreakBeforeBinaryOperators: false,    
  AlwaysBreakTemplateDeclarations: true, 
  AllowShortLoopsOnASingleLine: false,
  AllowShortIfStatementsOnASingleLine: false, 
  AllowAllParametersOfDeclarationOnNextLine: true, 
  SpacesInParentheses: true,    
  SpacesBeforeTrailingComments: 1, 
  SpaceInEmptyParentheses: false,
  SpaceAfterControlStatementKeyword: true, 
  PointerBindsToType: true, 
  MaxEmptyLinesToKeep: 1,
  IndentFunctionDeclarationAfterType: true, 
  IndentCaseLabels: true,
  ExperimentalAutoDetectBinPacking: true, 
  DerivePointerBinding: true, 
  Cpp11BracedListStyle: false, 
  ConstructorInitializerAllOnOneLineOrOnePerLine: true,
  BreakConstructorInitializersBeforeComma: true
}

并获取

try {
}
 catch ( ... ) {
}

虽然我想得到

try {
} catch ( ... ) {
}

任何人都可以说Clang-Format Style Option对这种行为负责吗?

2 个答案:

答案 0 :(得分:2)

根据我的理解,

BreakBeforeBraces应该影响您所关注的行为。 Attach看似是描述on the style options page that you referenced中的正确选项。我可以看到它不起作用的唯一原因是BreakBeforeBraces期望BraceBreakingStyle枚举。尝试不使Attach字符串。

BreakBeforeBraces: Attach 

BreakBeforeBraces: BS_Attach 

答案 1 :(得分:1)

最近才添加了对try-catch-blocks的支持。如果您更新到当前版本,则应该修复此问题。