Skip to content

Instantly share code, notes, and snippets.

@pingwinator
Forked from mralexgray/.clang-format.myold
Created February 23, 2014 20:33
Show Gist options
  • Save pingwinator/9176839 to your computer and use it in GitHub Desktop.
Save pingwinator/9176839 to your computer and use it in GitHub Desktop.
---
BasedOnStyle: WebKit
AccessModifierOffset: -2
AlignEscapedNewlinesLeft: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackParameters: false
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Stroustrup
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DerivePointerBinding: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
IndentFunctionDeclarationAfterType: true
IndentWidth: 2
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 60
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerBindsToType: false
SpaceAfterControlStatementKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
Standard: LS_Cpp11 # Auto
TabWidth: 2
UseTab: UT_Always
---

My first sweep at a clang-format configuration. There are a couple of issues:

  • Braces for block function bodies are pushed to the next line
  • Method calls are being pushed across multiple lines (although parameters are being aligned)
  • Literal arrays and dictionaries are being spread out a bit too much for my liking

Regardless, the output is still very readable and consistent. My guess is that this will be integrated into the next major release of Xcode (pleasepleaseplease), so I'm just going to suck it up, have a spoonful of concrete and adapt to the whatever the output is.

Currently best used with ClangFormat-Xcode. Place the contents in a file named .clang-format at the root of your project, and select the "Edit > Clang Format > File" menu item in Xcode. Assign a keyboard shortcut for bonus points — I use `^```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment