Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include a .clang-format file to have formatting done by clang-format #1078

Open
uyha opened this issue Jul 4, 2023 · 3 comments
Open

include a .clang-format file to have formatting done by clang-format #1078

uyha opened this issue Jul 4, 2023 · 3 comments

Comments

@uyha
Copy link

uyha commented Jul 4, 2023

No description provided.

@uyha uyha changed the title include a .clang-format to have formatting done by clang-format include a .clang-format file to have formatting done by clang-format Jul 4, 2023
@redboltz
Copy link
Contributor

redboltz commented Jul 4, 2023

NOTE:

I tried to apply clang-format at Apr 2022 at other project.
See redboltz/mqtt_cpp#927 (comment)

At that time, lambda capture list and template <> adjustment is not enough for me.

I expect the following format:

template <
    typename T,
    std::enable_if_t<
        std::is_same_v<T, int>
    >
>
foo(
    T param1,
    char param2,
    double param3
) {
    async_function(
        arg1,
        arg2,
        [
            capture1,
            capture2 = std::move(outer),
            capture3
        ]
        () mutable -> std::size_t {
            // body
            ++capture1;
        }
    );
}

The important points I want to achieve are as follows:

  1. Avoiding longer lines. The following example is not good.

    void foo() {
        [lambda_capture_argument1, lambda_capture_argument2 = std::move(lambda_capture_argument2)] () mutable {
        }
    }
  2. Replacing tool (e.g. perl) friendly.
    The following one is good because only one element for each line.

         [
             capture1,
             capture2 = std::move(outer),
             capture3
         ]

    But the following is not good befause capture1 and capture2 are not tool friendly.

         [capture1, capture2 = std::move(outer),
          capture3
         ]

Here is the setting file when I tried:

Language: Cpp

# Indent
IndentWidth: 4
AccessModifierOffset: -4
#IndentBraces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExternBlock: NoIndent
AlignAfterOpenBracket: AlwaysBreak
AllowAllParametersOfDeclarationOnNextLine: true
IndentGotoLabels: false
IndentPPDirectives: None
IndentRequires: true
IndentWrappedFunctionNames: false
LambdaBodyIndentation: Signature
UseTab: Never

#namespace
#AfterNamespace: false
#SplitEmptyNamespace: false
CompactNamespaces: false
FixNamespaceComments: true

# Align
AlignAfterOpenBracket: BlockIndent
#AlignAfterOpenBracket: AlwaysBreak
AlignArrayOfStructures: Right
AlignConsecutiveAssignments: AcrossEmptyLinesAndComments
AlignConsecutiveBitFields: AcrossEmptyLinesAndComments
AlignConsecutiveDeclarations: AcrossEmptyLinesAndComments
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments: true
PointerAlignment: Left
ReferenceAlignment: Left

# Break
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
PenaltyBreakTemplateDeclaration: 0
BinPackArguments: false
BinPackParameters: false

BreakBeforeBraces: Custom
BraceWrapping:
  AfterCaseLabel: false
  BeforeCatch: true
  BeforeElse: true
  BeforeLambdaBody: true
  BeforeWhile: false

BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: AfterColon
BreakStringLiterals: false

AllowAllConstructorInitializersOnNextLine: true
PackConstructorInitializers: Never



# SingleLine
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: false
#SplitEmptyFunction: true
#SplitEmptyRecord: true

#Macro

#Space
Cpp11BracedListStyle: false
DerivePointerAlignment: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInParentheses: false
SpacesInSquareBrackets: false

# Other
FixNamespaceComments: true
IncludeBlocks: Preserve
MaxEmptyLinesToKeep: 2
SortIncludes: CaseSensitive
SortUsingDeclarations: true

@uyha
Copy link
Author

uyha commented Jul 4, 2023

I also tried to have clang-format break the template parameter list into individual lines and having > on a seperate line, but no luck. I would like to keep this issue open and come back to it later if clang-format gets better or an alternative pops up.

@redboltz
Copy link
Contributor

redboltz commented Jul 4, 2023

Yes, clang-format 's template parameter formatting and lambda related formatting is not enough for me.
Unfortunately, I don't have much time to treat the clang-format but if you or someone report a feature request https://github.com/llvm/llvm-project or pull request to clang format, it would be helpful.

BTW, my template formatting is based on Dave Abrahams one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants