Auto format settings not inherited?

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: []

Do you perhaps mean @UKHeliBob ?

:grinning:

Hi @Terrypin

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:

  • The form before formatting
  • The form after formatting
  • The form you expected it to take after formatting

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.

IDE 1.x does not use Clang to define the Auto Format. If you have customised the settings in 1.x then they will not be carried forward to 2.x

Do you mean the second closing brace is entered while you are typing, or when you perform an "Auto Format" operation?

The former. As soon as I type ‘{‘ the ‘}’ is added next to it.

I’ve set aside IDE work for a while but will pursue futher asap.

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:

  1. 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:
  2. 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.
  3. Type editor.autoClosing in the "Search Settings" field of the "Settings" tab.
  4. Select "never" from the menu under the "Editor: Auto Closing Brackets" setting.
  5. 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.
  6. Close the Preferences tab by clicking its X icon.

Thanks, understood.

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.
*/

Is the quirk happening in 1.x or 2.x ?

There is a related bug report here:

Unfortunately I think it would be quite complicated to do so:

https://github.com/bobbylight/RSyntaxTextArea/issues/151#issue-113839934

Is there a way to turn this completion off?

https://github.com/bobbylight/RSyntaxTextArea/issues/151#issuecomment-223858232

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.

So you would need to edit the source code of the RSyntaxTextArea Java component that is used for the Arduino IDE 1.x editor, then build Arduino IDE from source, using that modified component.

1.8.19

Thanks, but in that case, I guess I’ll just live with what I’ve got!

The bug will presumably never be fixed because development has stopped on IDE 1.x