-
-
Notifications
You must be signed in to change notification settings - Fork 431
"ctrl+T" changes the braces position I HATE that #94
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
Comments
hi @Master811129 the Java IDE does not use ClangD for formatting. |
Yes, this is a reasonable request. However, we have to figure out how users can/will customize it. |
+1 for leaving it the way the Java IDE did it, as that is what Arduino users are familiar with. |
BackgroundHi @Master811129. As mentioned above, we switched from the Artistic Style code formatter used by Arduino IDE 1.x to a new code formatting tool: ClangFormat. I believe this was the right decision since ClangFormat is one of the most popular formatters and because it is actively maintained as part of the LLVM project, while Artistic Style is no longer actively maintained (note the developer even recommends ClangFormat in that statement). Current statusAs also mentioned above, at the time you wrote this the formatter was using the default configuration (since the team had not yet had time to work on a custom configuration for the beta IDE), which had significant differences from the Arduino IDE 1.x formatter configuration. Since that time, I was given the opportunity to create a custom Arduino style configuration. I dedicated myself to making every possible effort to exactly reproduce the behavior of the IDE 1.x formatter. Unfortunately, due to differences in the two tools, it was not possible to achieve an exact match. I'm sorry to say that the issue you reported here is one of those few remaining discrepancies. Configuration fileThe good news is that ClangFormat is very configurable (far more so than Artistic Style). It is now possible to define your own custom configuration in two different ways: Global scopeIf you add a Windows
- OR -
Linux
- OR -
macOS
- OR -
Sketch scopeIf you add a ConfigurationIf you prefer "broken" braces, you can set that via the ❗ Please note that the custom configuration file completely overrides the Arduino default configuration, rather than merging with it. Any configuration option you don't set in your custom file will be set to the ClangFormat default value. Here is Arduino's default configuration file in case you would like to use it as a base for your custom configuration: ---
Language: Cpp
# LLVM is the default style setting, used when a configuration option is not set here
BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: false
AlignEscapedNewlines: DontAlign
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: Empty
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: No
BinPackArguments: true
BinPackParameters: true
# Only used when "BreakBeforeBraces" set to "Custom"
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
#AfterObjCDeclaration:
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
# Java-specific
#BreakAfterJavaFieldAnnotations:
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: false
ColumnLimit: 0
# "" matches none
CommentPragmas: ""
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: false
DeriveLineEnding: true
DerivePointerAlignment: true
DisableFormat: false
# Docs say "Do not use this in config files". The default (LLVM 11.0.1) is "false".
#ExperimentalAutoDetectBinPacking:
FixNamespaceComments: false
ForEachMacros: []
IncludeBlocks: Preserve
IncludeCategories: []
# "" matches none
IncludeIsMainRegex: ""
IncludeIsMainSourceRegex: ""
IndentCaseBlocks: true
IndentCaseLabels: true
IndentExternBlock: Indent
IndentGotoLabels: false
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
# Java-specific
#JavaImportGroups:
# JavaScript-specific
#JavaScriptQuotes:
#JavaScriptWrapImports
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ""
MacroBlockEnd: ""
# Set to a large number to effectively disable
MaxEmptyLinesToKeep: 100000
NamespaceIndentation: None
NamespaceMacros: []
# Objective C-specific
#ObjCBinPackProtocolList:
#ObjCBlockIndentWidth:
#ObjCBreakBeforeNestedBlockParam:
#ObjCSpaceAfterProperty:
#ObjCSpaceBeforeProtocolList
PenaltyBreakAssignment: 1
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 1
PenaltyBreakFirstLessLess: 1
PenaltyBreakString: 1
PenaltyBreakTemplateDeclaration: 1
PenaltyExcessCharacter: 1
PenaltyReturnTypeOnItsOwnLine: 1
# Used as a fallback if alignment style can't be detected from code (DerivePointerAlignment: true)
PointerAlignment: Right
RawStringFormats: []
ReflowComments: false
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
StatementMacros: []
TabWidth: 2
TypenameMacros: []
# Default to LF if line endings can't be detected from the content (DeriveLineEnding).
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros: [] At this point, we have done everything in our power to mitigate this issue so I will close it. |
I didn't quite follow your description of how to switch from clang to artistic style, but I would like to request that this be made as easy as possible. The artistic style is one of the things I quite liked about the Processing style we started with, and I will miss it when I finally have to switch to 2.0. |
There is nothing at all the user needs to do to switch. It is integrated into the Arduino IDE 2.x. Simply use the auto format functionality just as you do with Arduino IDE 1.x. The information I shared above is for any advanced users who happen to have their own formatting style preferences (e.g., "broken" instead of "attached" braces) and want to configure the Arduino IDE 2.x formatter to work differently than it does by default.
We plan to clearly and thoroughly document the formatter configuration system (something that was never done for Arduino IDE 1.x). I have left #42 open so that we can track that remaining task. |
I'm still getting some strange behavior on the autoformat. Steps to repeat it on Windows 11 and 2.0.0 rc6:
So the artistic formatting seems to be back, but it doesn't do it on ctrl-T, it does it on app switching -- or perhaps on some timed file update? Can't tell, but I'll try on MacOS this afternoon. |
Thanks for testing @tigoe. A very important improvement was made to the formatter system last week: #1019. That should fix the problem you encountered (the cause is explained here: #1009). That fix is currently only available from the nightly build of the Arduino IDE. The download links to the nightly build are here: https://github.com/arduino/arduino-ide#nightly-builds |
Beautiful! Test: Wrote a complex sketch with no tabs. Every few seconds it would auto-tab correctly for the artistic format. When I reached the end, I ctrl-T and it all formatted immediately and correctly. Nice work, thank you! |
after auto-fomating in Arduino Pro IDE. It changes the braces position (but legacy IDE doesn't):

The text was updated successfully, but these errors were encountered: