From 63485b3d92e44c759895a2378663a3f950d5e490 Mon Sep 17 00:00:00 2001 From: Thomas Adam Date: Sat, 21 Jan 2023 23:53:48 +0000 Subject: [PATCH] formatting: add .clang-format config file Fvwm has had a long history, with contributions from many people over the years. As a result the code formatting which has crept in is varied -- both in terms of whitespace, indentation, etc., with there being mass inconsistencies all over the code base. Even as far back as 2006 (see commit: 1c9e17f89ca394d94de40c66a80df2ba6621bcf5), there was an attempt at reformatting some of FvwmButton's code, but not all of it. Thankfully, technology exists to bring consistency to this automatically. clang-format (from llvm) is one example, but it seems to do the job well enough. This definition cribs from FreeBSD's style, which isn't too far off the codebase as it stands at the moment. --- .clang-format | 190 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 170 insertions(+), 20 deletions(-) diff --git a/.clang-format b/.clang-format index 5bba8a18e..c9361c107 100644 --- a/.clang-format +++ b/.clang-format @@ -1,33 +1,183 @@ ---- +# Basic .clang-format +--- +BasedOnStyle: WebKit AlignAfterOpenBracket: DontAlign +AlignArrayOfStructures: Left AlignConsecutiveAssignments: true AlignConsecutiveDeclarations: true -AlignEscapedNewlinesLeft: true -AlignOperands: true +AlignEscapedNewlines: Left +AlignOperands: false AlignTrailingComments: true -AllowShortBlocksOnASingleLine: false +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortIfStatementsOnASingleLine: false +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: Never AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterReturnType: All -BasedOnStyle: LLVM +AlwaysBreakAfterReturnType: TopLevelDefinitions +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine BinPackArguments: true BinPackParameters: true -BreakAfterJavaFieldAnnotations: true -BreakBeforeBinaryOperators: NonAssignment -BreakBeforeBraces: Mozilla -ColumnLimit: 80 -ContinuationIndentWidth: 4 +BreakBeforeBinaryOperators: None +BreakBeforeBraces: WebKit +BreakBeforeTernaryOperators: false +# TODO: BreakStringLiterals can cause very strange formatting so turn it off? +BreakStringLiterals: false +# Prefer: +# some_var = function(arg1, +# arg2) +# over: +# some_var = +# function(arg1, arg2) +PenaltyBreakAssignment: 100 +# Prefer: +# some_long_function(arg1, arg2 +# arg3) +# over: +# some_long_function( +# arg1, arg2, arg3) +PenaltyBreakBeforeFirstCallParameter: 100 +CompactNamespaces: true DerivePointerAlignment: false -ExperimentalAutoDetectBinPacking: false -IndentWidth: 8 +DisableFormat: false +ForEachMacros: + - ARB_ARRFOREACH + - ARB_ARRFOREACH_REVWCOND + - ARB_ARRFOREACH_REVERSE + - ARB_FOREACH + - ARB_FOREACH_FROM + - ARB_FOREACH_SAFE + - ARB_FOREACH_REVERSE + - ARB_FOREACH_REVERSE_FROM + - ARB_FOREACH_REVERSE_SAFE + - BIT_FOREACH_ISCLR + - BIT_FOREACH_ISSET + - CPU_FOREACH + - CPU_FOREACH_ISCLR + - CPU_FOREACH_ISSET + - FOREACH_THREAD_IN_PROC + - FOREACH_PROC_IN_SYSTEM + - FOREACH_PRISON_CHILD + - FOREACH_PRISON_DESCENDANT + - FOREACH_PRISON_DESCENDANT_LOCKED + - FOREACH_PRISON_DESCENDANT_LOCKED_LEVEL + - MNT_VNODE_FOREACH_ALL + - MNT_VNODE_FOREACH_ACTIVE + - RB_FOREACH + - RB_FOREACH_FROM + - RB_FOREACH_SAFE + - RB_FOREACH_REVERSE + - RB_FOREACH_REVERSE_FROM + - RB_FOREACH_REVERSE_SAFE + - SLIST_FOREACH + - SLIST_FOREACH_FROM + - SLIST_FOREACH_FROM_SAFE + - SLIST_FOREACH_SAFE + - SLIST_FOREACH_PREVPTR + - SPLAY_FOREACH + - LIST_FOREACH + - LIST_FOREACH_FROM + - LIST_FOREACH_FROM_SAFE + - LIST_FOREACH_SAFE + - STAILQ_FOREACH + - STAILQ_FOREACH_FROM + - STAILQ_FOREACH_FROM_SAFE + - STAILQ_FOREACH_SAFE + - TAILQ_FOREACH + - TAILQ_FOREACH_FROM + - TAILQ_FOREACH_FROM_SAFE + - TAILQ_FOREACH_REVERSE + - TAILQ_FOREACH_REVERSE_FROM + - TAILQ_FOREACH_REVERSE_FROM_SAFE + - TAILQ_FOREACH_REVERSE_SAFE + - TAILQ_FOREACH_SAFE + - VM_MAP_ENTRY_FOREACH + - VM_PAGE_DUMP_FOREACH +IndentCaseLabels: false +IndentPPDirectives: None Language: Cpp -NamespaceIndentation: All +NamespaceIndentation: None PointerAlignment: Right -PointerBindsToType: false -ReflowComments: true -SortIncludes: true +ContinuationIndentWidth: 4 +IndentWidth: 8 TabWidth: 8 +ColumnLimit: 80 UseTab: Always -... +SpaceAfterCStyleCast: false +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^\"config\.h\"' + Priority: 1 + SortPriority: 1 + - Regex: '^\"opt_.*\.h\"' + Priority: 1 + SortPriority: 10 + - Regex: '^' + Priority: 2 + SortPriority: 20 + - Regex: '^' + Priority: 2 + SortPriority: 21 + - Regex: '^' + Priority: 2 + SortPriority: 22 + - Regex: '^' + Priority: 2 + SortPriority: 23 + - Regex: '^