The oddly named text file '.clang-format' has been used to auto-format my sketches for over two years. I'd forgotten about its existence until starting to use IDE 2.3.6 in earnest this morning. I assume it needs changing because on using <Ctrl + t> I'm getting some unwanted results.
I recall I based it closely on one used by Bob Helliwell. I've pasted its 155 lines below and would appreciate learning if there is a 2.3.6 replacement please, to avoid tedious editing.
#default format originally from
#https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-customize-auto-formatter
---
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
# bbb BreakBeforeBraces: Attach
BreakBeforeBraces: Allman
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
# bbb KeepEmptyLinesAtTheStartOfBlocks: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ""
MacroBlockEnd: ""
# Set to a large number to effectively disable
# bbb MaxEmptyLinesToKeep: 10000000
MaxEmptyLinesToKeep: 0
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: []
There hasn't been any change to the format of this file, so the file that worked with a previous version of Arduino IDE will work just the same with Arduino IDE 2.3.6.
If you provide a detailed description of the results, the forum helpers may be able to advise you on how you might overcome the problem.
Make sure to provide minimal demonstration code, in the following forms:
Indeed I do, sorry - not enough caffeine or something. I did know a Bob Helliwell a decade or three ago, long time before Arduino's emergence!
From @ptillisch I understand there should be no change. Yet the behaviour I've seen is different. For example, if a blank line is created and ctrl+t used the blank line is retained in 1.8.19. But in 2.3.6 it is deleted.
Using 1.8.19
void pausePlayToggle()
{
Add an empty line
void pausePlayToggle()
{
Use Ctrl+t
void pausePlayToggle()
{
i.e. the blank line remains
Using 2.3.6
void pausePlayToggle()
{
Add an empty line
void pausePlayToggle()
{
Use Ctrl+t
void pausePlayToggle()
{
i.e. the blank line is deleted
And another example: if I enter my first curly bracket at the end of an if command's closing right bracket, a second closing curly brace is entered, which does not happen in 1.8.19. Using ctrl+t does not correct that unwanted addition, yet in 1.8.19 it always places curly braces on their own otherwise empty lines.
Thanks for the clarification. This "Auto Closing Brackets" feature that automatically adds the closing brace while you write is completely separate from the "Auto Format" feature. For those of us who don't find it to be useful, the "Auto Closing Brackets" feature can be disabled via Arduino IDE's advanced settings. I'll provide instructions you can follow to do that:
Press the Ctrl+Shift+P keyboard shortcut (Command+Shift+P for macOS users) to open the "Command Palette".
A menu will appear on the editor toolbar:
Select the "Preferences: Open Settings (UI)" command from the menu. ⓘ You can scroll down through the list of commands to find it, or type the command name in the field.
A "Settings" tab will open in the Arduino IDE main panel.
Type editor.autoClosing in the "Search Settings" field of the "Settings" tab.
Select "never" from the menu under the "Editor: Auto Closing Brackets" setting.
You may wish to also review the related settings "Editor: Auto Closing Comments" and "Editor: Auto Closing Quotes" settings you will see listed there, as if you don't like auto-closing of brackets, you might also not like the equivalent behavior for comments and quotes.
Thanks, got it. That's a distinction between IDE 1 and 2 that I'd missed until now. So I will ignore clang and look only at formatter.conf to control the behaviour of Auto-format in 1.8.19.
Can you advise on this minor quirk please.
/* After typing '/' followed by Enter, at present I automatically get two lines below: one with '' and the next with '*/'
Where can I experiment to edit that feature? For example to get something like this:
/*
Not fussed whether or not I get an automatic '*/'. I proceed typing my comment lines. Without a preceding asterisk. And if lines are long ideally I'd like them wrapped to a specified width.
*/
/*
Not fussed whether or not I get an automatic '*/'. I proceed typing my comment lines. Without a preceding asterisk. And if lines are long, can they be wrapped to a specified width - like this.
*/
Not currently, but this can be made into a new feature. This action currently lives in org.fife.ui.rsyntaxtextarea.AbstractJFlexCTokenMaker . insertBreakInMLC would have to be conditionally called, depending on whether or not this feature is desired.