c-code-style icon indicating copy to clipboard operation
c-code-style copied to clipboard

May be we need a .clang-format

Open Logiase opened this issue 2 years ago • 3 comments

Many IDE and editors use clang-format to format code, like VSCode, Clion, Visual Studio, QtCreator.

clang-format style docs: https://clang.llvm.org/docs/ClangFormatStyleOptions.html

BasedOnStyle: GNU may help

Logiase avatar Apr 27 '22 10:04 Logiase

Many IDE and editors use clang-format to format code, like VSCode, Clion, Visual Studio, QtCreator.

clang-format style docs: https://clang.llvm.org/docs/ClangFormatStyleOptions.html

BasedOnStyle: GNU may help

Can you make a pull request?

MaJerle avatar Apr 27 '22 11:04 MaJerle

---
Language: Cpp
BasedOnStyle: GNU
IndentWidth: 4
AllowShortBlocksOnASingleLine: Empty
AllowShortFunctionsOnASingleLine: None
BreakBeforeBraces: Custom
SpaceBeforeParens: ControlStatements
BraceWrapping:
  AfterFunction: false

This may help, just put it to your project root and rename to .clang-format, and format code, most editors will use it.

I use template.c and template.h, it works fine, but it need more tests.

Logiase avatar Apr 27 '22 17:04 Logiase

I came up with this so far.

Do you know how to align macro definitions to certain column?

---
Language: Cpp
BasedOnStyle: GNU
IndentWidth: 4
AllowShortBlocksOnASingleLine: Empty
AllowShortFunctionsOnASingleLine: None
SpaceBeforeParens: ControlStatements
BreakBeforeBraces: Custom
BraceWrapping:
  AfterFunction: false
  AfterCaseLabel: false
  AfterEnum: false
  AfterControlStatement: Never
  AfterStruct : false
  AfterUnion : false
  AfterExternBlock : false
  BeforeElse : false
  BeforeWhile : false
AlignAfterOpenBracket: Align
AlignArrayOfStructures: Left
AlignEscapedNewlines: Right
AlignOperands: Align
AllowShortBlocksOnASingleLine: Empty
AllowShortEnumsOnASingleLine: False
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine : false
AlwaysBreakAfterReturnType: AllDefinitions
AlignTrailingComments : true
AlignConsecutiveMacros: AcrossEmptyLines
InsertBraces : true
KeepEmptyLinesAtTheStartOfBlocks : false
PointerAlignment : Left
QualifierAlignment : Left
ReferenceAlignment : Left
RemoveBracesLLVM : false
SpaceAfterCStyleCast : false
SpaceAfterLogicalNot : false
SpaceAfterTemplateKeyword : false
SpaceAroundPointerQualifiers : Before
SpaceBeforeAssignmentOperators : true
SpaceBeforeCaseColon : false
SpaceBeforeCpp11BracedList : false
SpaceBeforeParens : ControlStatements
SpaceBeforeParensOptions :
  AfterControlStatements : true
  AfterFunctionDeclarationName : false
  AfterFunctionDefinitionName : false
  AfterOverloadedOperator : false
SpaceBeforeRangeBasedForLoopColon : false
SpaceBeforeSquareBrackets : false
SpaceInEmptyBlock : false
SpaceInEmptyParentheses : false
SpacesInCStyleCastParentheses : false
SpacesInConditionalStatement : false
SpacesInContainerLiterals : false
SpacesInParentheses: false
SpacesInSquareBrackets : false
UseTab : Never

BitFieldColonSpacing: None
BreakBeforeBinaryOperators: true

MaJerle avatar May 03 '22 19:05 MaJerle

if it helps, ive also found this site when i was testing for clang-format configurations:

https://zed0.co.uk/clang-format-configurator/ source: https://github.com/zed0/clang-format-configurator

negativeExponent avatar Sep 24 '22 05:09 negativeExponent

邮件已收到,我会尽快回复的!

EmbeddedLife615 avatar Sep 24 '22 05:09 EmbeddedLife615

邮件已收到,我会尽快回复的!

EmbeddedLife615 avatar Oct 11 '22 07:10 EmbeddedLife615