Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 1 | ========================== |
| 2 | Clang-Format Style Options |
| 3 | ========================== |
| 4 | |
| 5 | :doc:`ClangFormatStyleOptions` describes configurable formatting style options |
| 6 | supported by :doc:`LibFormat` and :doc:`ClangFormat`. |
| 7 | |
| 8 | When using :program:`clang-format` command line utility or |
| 9 | ``clang::format::reformat(...)`` functions from code, one can either use one of |
| 10 | the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit) or create a |
| 11 | custom style by configuring specific style options. |
| 12 | |
| 13 | |
| 14 | Configuring Style with clang-format |
| 15 | =================================== |
| 16 | |
| 17 | :program:`clang-format` supports two ways to provide custom style options: |
| 18 | directly specify style configuration in the ``-style=`` command line option or |
Hans Wennborg | 9a7a50e | 2013-09-10 15:41:12 +0000 | [diff] [blame] | 19 | use ``-style=file`` and put style configuration in the ``.clang-format`` or |
| 20 | ``_clang-format`` file in the project directory. |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 21 | |
| 22 | When using ``-style=file``, :program:`clang-format` for each input file will |
| 23 | try to find the ``.clang-format`` file located in the closest parent directory |
| 24 | of the input file. When the standard input is used, the search is started from |
| 25 | the current directory. |
| 26 | |
| 27 | The ``.clang-format`` file uses YAML format: |
| 28 | |
| 29 | .. code-block:: yaml |
| 30 | |
| 31 | key1: value1 |
| 32 | key2: value2 |
| 33 | # A comment. |
| 34 | ... |
| 35 | |
| 36 | An easy way to get a valid ``.clang-format`` file containing all configuration |
| 37 | options of a certain predefined style is: |
| 38 | |
| 39 | .. code-block:: console |
| 40 | |
| 41 | clang-format -style=llvm -dump-config > .clang-format |
| 42 | |
| 43 | When specifying configuration in the ``-style=`` option, the same configuration |
| 44 | is applied for all input files. The format of the configuration is: |
| 45 | |
| 46 | .. code-block:: console |
| 47 | |
| 48 | -style='{key1: value1, key2: value2, ...}' |
| 49 | |
| 50 | |
| 51 | Configuring Style in Code |
| 52 | ========================= |
| 53 | |
| 54 | When using ``clang::format::reformat(...)`` functions, the format is specified |
| 55 | by supplying the `clang::format::FormatStyle |
| 56 | <http://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_ |
| 57 | structure. |
| 58 | |
| 59 | |
| 60 | Configurable Format Style Options |
| 61 | ================================= |
| 62 | |
| 63 | This section lists the supported style options. Value type is specified for |
| 64 | each option. For enumeration types possible values are specified both as a C++ |
Alexander Kornienko | c4f73e0 | 2013-09-04 15:14:18 +0000 | [diff] [blame] | 65 | enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in |
| 66 | the configuration (without a prefix: ``Auto``). |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 67 | |
| 68 | |
| 69 | **BasedOnStyle** (``string``) |
| 70 | The style used for all options not specifically set in the configuration. |
| 71 | |
| 72 | This option is supported only in the :program:`clang-format` configuration |
| 73 | (both within ``-style='{...}'`` and the ``.clang-format`` file). |
| 74 | |
| 75 | Possible values: |
| 76 | |
| 77 | * ``LLVM`` |
| 78 | A style complying with the `LLVM coding standards |
| 79 | <http://llvm.org/docs/CodingStandards.html>`_ |
| 80 | * ``Google`` |
| 81 | A style complying with `Google's C++ style guide |
| 82 | <http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml>`_ |
| 83 | * ``Chromium`` |
| 84 | A style complying with `Chromium's style guide |
| 85 | <http://www.chromium.org/developers/coding-style>`_ |
| 86 | * ``Mozilla`` |
| 87 | A style complying with `Mozilla's style guide |
| 88 | <https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style>`_ |
| 89 | * ``WebKit`` |
| 90 | A style complying with `WebKit's style guide |
| 91 | <http://www.webkit.org/coding/coding-style.html>`_ |
| 92 | |
| 93 | .. START_FORMAT_STYLE_OPTIONS |
| 94 | |
| 95 | **AccessModifierOffset** (``int``) |
| 96 | The extra indent or outdent of access modifiers, e.g. ``public:``. |
| 97 | |
| 98 | **AlignEscapedNewlinesLeft** (``bool``) |
| 99 | If ``true``, aligns escaped newlines as far left as possible. |
| 100 | Otherwise puts them into the right-most column. |
| 101 | |
| 102 | **AlignTrailingComments** (``bool``) |
| 103 | If ``true``, aligns trailing comments. |
| 104 | |
| 105 | **AllowAllParametersOfDeclarationOnNextLine** (``bool``) |
| 106 | Allow putting all parameters of a function declaration onto |
| 107 | the next line even if ``BinPackParameters`` is ``false``. |
| 108 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 109 | **AllowShortBlocksOnASingleLine** (``bool``) |
| 110 | Allows contracting simple braced statements to a single line. |
| 111 | |
| 112 | E.g., this allows ``if (a) { return; }`` to be put on a single line. |
| 113 | |
| 114 | **AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``) |
| 115 | Dependent on the value, ``int f() { return 0; }`` can be put |
| 116 | on a single line. |
| 117 | |
| 118 | Possible values: |
| 119 | |
| 120 | * ``SFS_None`` (in configuration: ``None``) |
| 121 | Never merge functions into a single line. |
| 122 | * ``SFS_Inline`` (in configuration: ``Inline``) |
| 123 | Only merge functions defined inside a class. |
| 124 | * ``SFS_All`` (in configuration: ``All``) |
| 125 | Merge all functions fitting on a single line. |
| 126 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 127 | |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 128 | **AllowShortIfStatementsOnASingleLine** (``bool``) |
| 129 | If ``true``, ``if (a) return;`` can be put on a single |
| 130 | line. |
| 131 | |
| 132 | **AllowShortLoopsOnASingleLine** (``bool``) |
| 133 | If ``true``, ``while (true) continue;`` can be put on a |
| 134 | single line. |
| 135 | |
| 136 | **AlwaysBreakBeforeMultilineStrings** (``bool``) |
| 137 | If ``true``, always break before multiline string literals. |
| 138 | |
| 139 | **AlwaysBreakTemplateDeclarations** (``bool``) |
| 140 | If ``true``, always break after the ``template<...>`` of a |
| 141 | template declaration. |
| 142 | |
| 143 | **BinPackParameters** (``bool``) |
| 144 | If ``false``, a function call's or function definition's parameters |
| 145 | will either all be on the same line or will have one line each. |
| 146 | |
| 147 | **BreakBeforeBinaryOperators** (``bool``) |
| 148 | If ``true``, binary operators will be placed after line breaks. |
| 149 | |
| 150 | **BreakBeforeBraces** (``BraceBreakingStyle``) |
| 151 | The brace breaking style to use. |
| 152 | |
| 153 | Possible values: |
| 154 | |
| 155 | * ``BS_Attach`` (in configuration: ``Attach``) |
| 156 | Always attach braces to surrounding context. |
| 157 | * ``BS_Linux`` (in configuration: ``Linux``) |
| 158 | Like ``Attach``, but break before braces on function, namespace and |
| 159 | class definitions. |
| 160 | * ``BS_Stroustrup`` (in configuration: ``Stroustrup``) |
| 161 | Like ``Attach``, but break before function definitions. |
| 162 | * ``BS_Allman`` (in configuration: ``Allman``) |
| 163 | Always break before braces. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 164 | * ``BS_GNU`` (in configuration: ``GNU``) |
| 165 | Always break before braces and add an extra level of indentation to |
| 166 | braces of control statements, not to those of class, function |
| 167 | or other definitions. |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 168 | |
| 169 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 170 | **BreakBeforeTernaryOperators** (``bool``) |
| 171 | If ``true``, ternary operators will be placed after line breaks. |
| 172 | |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 173 | **BreakConstructorInitializersBeforeComma** (``bool``) |
| 174 | Always break constructor initializers before commas and align |
| 175 | the commas with the colon. |
| 176 | |
| 177 | **ColumnLimit** (``unsigned``) |
| 178 | The column limit. |
| 179 | |
| 180 | A column limit of ``0`` means that there is no column limit. In this case, |
| 181 | clang-format will respect the input's line breaking decisions within |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 182 | statements unless they contradict other rules. |
| 183 | |
| 184 | **CommentPragmas** (``std::string``) |
| 185 | A regular expression that describes comments with special meaning, |
| 186 | which should not be split into lines or otherwise changed. |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 187 | |
| 188 | **ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``) |
| 189 | If the constructor initializers don't fit on a line, put each |
| 190 | initializer on its own line. |
| 191 | |
| 192 | **ConstructorInitializerIndentWidth** (``unsigned``) |
| 193 | The number of characters to use for indentation of constructor |
| 194 | initializer lists. |
| 195 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 196 | **ContinuationIndentWidth** (``unsigned``) |
| 197 | Indent width for line continuations. |
| 198 | |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 199 | **Cpp11BracedListStyle** (``bool``) |
| 200 | If ``true``, format braced lists as best suited for C++11 braced |
| 201 | lists. |
| 202 | |
| 203 | Important differences: |
| 204 | - No spaces inside the braced list. |
| 205 | - No line break before the closing brace. |
| 206 | - Indentation with the continuation indent, not with the block indent. |
| 207 | |
| 208 | Fundamentally, C++11 braced lists are formatted exactly like function |
| 209 | calls would be formatted in their place. If the braced list follows a name |
| 210 | (e.g. a type or variable name), clang-format formats as if the ``{}`` were |
| 211 | the parentheses of a function call with that name. If there is no name, |
| 212 | a zero-length name is assumed. |
| 213 | |
| 214 | **DerivePointerBinding** (``bool``) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 215 | If ``true``, analyze the formatted file for the most common binding |
| 216 | and use ``PointerBindsToType`` only as fallback. |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 217 | |
| 218 | **ExperimentalAutoDetectBinPacking** (``bool``) |
| 219 | If ``true``, clang-format detects whether function calls and |
| 220 | definitions are formatted with one parameter per line. |
| 221 | |
| 222 | Each call can be bin-packed, one-per-line or inconclusive. If it is |
| 223 | inconclusive, e.g. completely on one line, but a decision needs to be |
| 224 | made, clang-format analyzes whether there are other bin-packed cases in |
| 225 | the input file and act accordingly. |
| 226 | |
| 227 | NOTE: This is an experimental flag, that might go away or be renamed. Do |
| 228 | not use this in config files, etc. Use at your own risk. |
| 229 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 230 | **ForEachMacros** (``std::vector<std::string>``) |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 231 | A vector of macros that should be interpreted as foreach loops |
| 232 | instead of as function calls. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 233 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 234 | These are expected to be macros of the form: |
| 235 | \code |
| 236 | FOREACH(<variable-declaration>, ...) |
| 237 | <loop-body> |
| 238 | \endcode |
| 239 | |
| 240 | For example: BOOST_FOREACH. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 241 | |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 242 | **IndentCaseLabels** (``bool``) |
| 243 | Indent case labels one level from the switch statement. |
| 244 | |
| 245 | When ``false``, use the same indentation level as for the switch statement. |
| 246 | Switch statement body is always indented one level more than case labels. |
| 247 | |
| 248 | **IndentFunctionDeclarationAfterType** (``bool``) |
| 249 | If ``true``, indent when breaking function declarations which |
| 250 | are not also definitions after the type. |
| 251 | |
| 252 | **IndentWidth** (``unsigned``) |
Alexander Kornienko | f6a6882 | 2013-09-27 16:16:55 +0000 | [diff] [blame] | 253 | The number of columns to use for indentation. |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 254 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 255 | **KeepEmptyLinesAtTheStartOfBlocks** (``bool``) |
| 256 | If true, empty lines at the start of blocks are kept. |
| 257 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 258 | **Language** (``LanguageKind``) |
| 259 | Language, this format style is targeted at. |
| 260 | |
| 261 | Possible values: |
| 262 | |
| 263 | * ``LK_None`` (in configuration: ``None``) |
| 264 | Do not use. |
| 265 | * ``LK_Cpp`` (in configuration: ``Cpp``) |
| 266 | Should be used for C, C++, ObjectiveC, ObjectiveC++. |
| 267 | * ``LK_JavaScript`` (in configuration: ``JavaScript``) |
| 268 | Should be used for JavaScript. |
| 269 | * ``LK_Proto`` (in configuration: ``Proto``) |
| 270 | Should be used for Protocol Buffers |
| 271 | (https://developers.google.com/protocol-buffers/). |
| 272 | |
| 273 | |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 274 | **MaxEmptyLinesToKeep** (``unsigned``) |
| 275 | The maximum number of consecutive empty lines to keep. |
| 276 | |
| 277 | **NamespaceIndentation** (``NamespaceIndentationKind``) |
| 278 | The indentation used for namespaces. |
| 279 | |
| 280 | Possible values: |
| 281 | |
| 282 | * ``NI_None`` (in configuration: ``None``) |
| 283 | Don't indent in namespaces. |
| 284 | * ``NI_Inner`` (in configuration: ``Inner``) |
| 285 | Indent only in inner namespaces (nested in other namespaces). |
| 286 | * ``NI_All`` (in configuration: ``All``) |
| 287 | Indent in all namespaces. |
| 288 | |
| 289 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 290 | **ObjCSpaceAfterProperty** (``bool``) |
| 291 | Add a space after ``@property`` in Objective-C, i.e. use |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 292 | ``\@property (readonly)`` instead of ``\@property(readonly)``. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 293 | |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 294 | **ObjCSpaceBeforeProtocolList** (``bool``) |
| 295 | Add a space in front of an Objective-C protocol list, i.e. use |
| 296 | ``Foo <Protocol>`` instead of ``Foo<Protocol>``. |
| 297 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 298 | **PenaltyBreakBeforeFirstCallParameter** (``unsigned``) |
| 299 | The penalty for breaking a function call after "call(". |
| 300 | |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 301 | **PenaltyBreakComment** (``unsigned``) |
| 302 | The penalty for each line break introduced inside a comment. |
| 303 | |
| 304 | **PenaltyBreakFirstLessLess** (``unsigned``) |
| 305 | The penalty for breaking before the first ``<<``. |
| 306 | |
| 307 | **PenaltyBreakString** (``unsigned``) |
| 308 | The penalty for each line break introduced inside a string literal. |
| 309 | |
| 310 | **PenaltyExcessCharacter** (``unsigned``) |
| 311 | The penalty for each character outside of the column limit. |
| 312 | |
| 313 | **PenaltyReturnTypeOnItsOwnLine** (``unsigned``) |
| 314 | Penalty for putting the return type of a function onto its own |
| 315 | line. |
| 316 | |
| 317 | **PointerBindsToType** (``bool``) |
| 318 | Set whether & and * bind to the type as opposed to the variable. |
| 319 | |
Daniel Jasper | 9b4de85 | 2013-09-25 15:15:02 +0000 | [diff] [blame] | 320 | **SpaceBeforeAssignmentOperators** (``bool``) |
Alexander Kornienko | f6a6882 | 2013-09-27 16:16:55 +0000 | [diff] [blame] | 321 | If ``false``, spaces will be removed before assignment operators. |
Daniel Jasper | 9b4de85 | 2013-09-25 15:15:02 +0000 | [diff] [blame] | 322 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 323 | **SpaceBeforeParens** (``SpaceBeforeParensOptions``) |
| 324 | Defines in which cases to put a space before opening parentheses. |
| 325 | |
| 326 | Possible values: |
| 327 | |
| 328 | * ``SBPO_Never`` (in configuration: ``Never``) |
| 329 | Never put a space before opening parentheses. |
| 330 | * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``) |
| 331 | Put a space before opening parentheses only after control statement |
| 332 | keywords (``for/if/while...``). |
| 333 | * ``SBPO_Always`` (in configuration: ``Always``) |
| 334 | Always put a space before opening parentheses, except when it's |
| 335 | prohibited by the syntax rules (in function-like macro definitions) or |
| 336 | when determined by other style rules (after unary operators, opening |
| 337 | parentheses, etc.) |
| 338 | |
| 339 | |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 340 | **SpaceInEmptyParentheses** (``bool``) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 341 | If ``true``, spaces may be inserted into '()'. |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 342 | |
| 343 | **SpacesBeforeTrailingComments** (``unsigned``) |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 344 | The number of spaces before trailing line comments |
| 345 | (``//`` - comments). |
| 346 | |
| 347 | This does not affect trailing block comments (``/**/`` - comments) as those |
| 348 | commonly have different usage patterns and a number of special cases. |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 349 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 350 | **SpacesInAngles** (``bool``) |
| 351 | If ``true``, spaces will be inserted after '<' and before '>' in |
| 352 | template argument lists |
| 353 | |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 354 | **SpacesInCStyleCastParentheses** (``bool``) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 355 | If ``true``, spaces may be inserted into C style casts. |
| 356 | |
| 357 | **SpacesInContainerLiterals** (``bool``) |
| 358 | If ``true``, spaces are inserted inside container literals (e.g. |
| 359 | ObjC and Javascript array and dict literals). |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 360 | |
| 361 | **SpacesInParentheses** (``bool``) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 362 | If ``true``, spaces will be inserted after '(' and before ')'. |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 363 | |
| 364 | **Standard** (``LanguageStandard``) |
| 365 | Format compatible with this standard, e.g. use |
| 366 | ``A<A<int> >`` instead of ``A<A<int>>`` for LS_Cpp03. |
| 367 | |
| 368 | Possible values: |
| 369 | |
| 370 | * ``LS_Cpp03`` (in configuration: ``Cpp03``) |
| 371 | Use C++03-compatible syntax. |
| 372 | * ``LS_Cpp11`` (in configuration: ``Cpp11``) |
| 373 | Use features of C++11 (e.g. ``A<A<int>>`` instead of |
| 374 | ``A<A<int> >``). |
| 375 | * ``LS_Auto`` (in configuration: ``Auto``) |
| 376 | Automatic detection based on the input. |
| 377 | |
| 378 | |
Alexander Kornienko | f6a6882 | 2013-09-27 16:16:55 +0000 | [diff] [blame] | 379 | **TabWidth** (``unsigned``) |
| 380 | The number of columns used for tab stops. |
| 381 | |
| 382 | **UseTab** (``UseTabStyle``) |
| 383 | The way to use tab characters in the resulting file. |
| 384 | |
| 385 | Possible values: |
| 386 | |
| 387 | * ``UT_Never`` (in configuration: ``Never``) |
| 388 | Never use tab. |
| 389 | * ``UT_ForIndentation`` (in configuration: ``ForIndentation``) |
| 390 | Use tabs only for indentation. |
| 391 | * ``UT_Always`` (in configuration: ``Always``) |
| 392 | Use tabs whenever we need to fill whitespace that spans at least from |
| 393 | one tab stop to the next one. |
| 394 | |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 395 | |
| 396 | .. END_FORMAT_STYLE_OPTIONS |
| 397 | |
| 398 | Examples |
| 399 | ======== |
| 400 | |
| 401 | A style similar to the `Linux Kernel style |
| 402 | <https://www.kernel.org/doc/Documentation/CodingStyle>`_: |
| 403 | |
| 404 | .. code-block:: yaml |
| 405 | |
| 406 | BasedOnStyle: LLVM |
| 407 | IndentWidth: 8 |
Alexander Kornienko | 62a5565 | 2013-09-27 16:19:25 +0000 | [diff] [blame] | 408 | UseTab: Always |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 409 | BreakBeforeBraces: Linux |
| 410 | AllowShortIfStatementsOnASingleLine: false |
| 411 | IndentCaseLabels: false |
| 412 | |
| 413 | The result is (imagine that tabs are used for indentation here): |
| 414 | |
| 415 | .. code-block:: c++ |
| 416 | |
| 417 | void test() |
| 418 | { |
| 419 | switch (x) { |
| 420 | case 0: |
| 421 | case 1: |
| 422 | do_something(); |
| 423 | break; |
| 424 | case 2: |
| 425 | do_something_else(); |
| 426 | break; |
| 427 | default: |
| 428 | break; |
| 429 | } |
| 430 | if (condition) |
| 431 | do_something_completely_different(); |
| 432 | |
| 433 | if (x == y) { |
| 434 | q(); |
| 435 | } else if (x > y) { |
| 436 | w(); |
| 437 | } else { |
| 438 | r(); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | A style similar to the default Visual Studio formatting style: |
| 443 | |
| 444 | .. code-block:: yaml |
| 445 | |
Alexander Kornienko | 62a5565 | 2013-09-27 16:19:25 +0000 | [diff] [blame] | 446 | UseTab: Never |
Alexander Kornienko | 62d06b7 | 2013-09-04 15:09:13 +0000 | [diff] [blame] | 447 | IndentWidth: 4 |
| 448 | BreakBeforeBraces: Allman |
| 449 | AllowShortIfStatementsOnASingleLine: false |
| 450 | IndentCaseLabels: false |
| 451 | ColumnLimit: 0 |
| 452 | |
| 453 | The result is: |
| 454 | |
| 455 | .. code-block:: c++ |
| 456 | |
| 457 | void test() |
| 458 | { |
| 459 | switch (suffix) |
| 460 | { |
| 461 | case 0: |
| 462 | case 1: |
| 463 | do_something(); |
| 464 | break; |
| 465 | case 2: |
| 466 | do_something_else(); |
| 467 | break; |
| 468 | default: |
| 469 | break; |
| 470 | } |
| 471 | if (condition) |
| 472 | do_somthing_completely_different(); |
| 473 | |
| 474 | if (x == y) |
| 475 | { |
| 476 | q(); |
| 477 | } |
| 478 | else if (x > y) |
| 479 | { |
| 480 | w(); |
| 481 | } |
| 482 | else |
| 483 | { |
| 484 | r(); |
| 485 | } |
| 486 | } |
| 487 | |