Skip to content

Commit 32dc81a

Browse files
Added tutorial
1 parent 877bb58 commit 32dc81a

File tree

1 file changed

+215
-0
lines changed
  • content/software/ide-v2/tutorials/ide-v2-customize-auto-formatter

1 file changed

+215
-0
lines changed
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
---
2+
title: 'Customizing the Auto Formatter'
3+
difficulty: easy
4+
description: 'Learn how '
5+
tags:
6+
- Auto Formatter
7+
- Tools
8+
author: 'Benjamin Dannegård'
9+
---
10+
11+
Pressing CTRL + T on Windows or CMD + T on MacOS when writing a sketch in the Arduino IDE 2.0 will automatically format the sketch. And it is possible to change the behaviour of this command. In this article we will go through how you can change the behaviour of this command.
12+
13+
You can easily download the editor from the [Arduino Software page](https://www.arduino.cc/en/software#experimental-software).
14+
15+
You can also follow the [downloading and installing the Arduino IDE 2.0](/en/Tutorial/getting-started-with-ide-v2/ide-v2-downloading-and-installing) tutorial for more detailed guide on how to install the editor.
16+
17+
## Requirements
18+
19+
- Arduino IDE 2.0 installed.
20+
21+
## Setting Custom Configuration
22+
23+
It is possible to define your own custom configuration in two different ways. The custom configuration of the auto formatter can be set on a global level to cover all sketches opened in the editor, or you can set the configuration to be specific to a sketch.
24+
25+
### Global scope
26+
If you add a `.clang-format` configuration file to either of the following locations, the Arduino IDE 2.0 will always use it instead of the Arduino default configuration.
27+
28+
If you are using Windows place the file in:
29+
```
30+
C:\Users\<username>\.arduinoIDE\
31+
```
32+
Or
33+
```
34+
C:\Users\<username>\AppData\Local\Arduino15\
35+
```
36+
37+
If you are using Linux place the file in:
38+
```
39+
~/.arduinoIDE/
40+
```
41+
Or
42+
```
43+
~/.arduino15/
44+
```
45+
46+
If you are using macOS place the file in:
47+
```
48+
~/.arduinoIDE
49+
```
50+
Or
51+
```
52+
~/Library/Arduino15/
53+
```
54+
55+
### Sketch scope
56+
If you add a `.clang-format` configuration file to the root of a sketch, the Arduino IDE will use that configuration when formatting that sketch. This file has precedence over a global formatter configuration file.
57+
58+
## Default Formatting File
59+
60+
Here you can find the default formatting file used in the Arduino IDE 2.0. If you wish to customize how your auto formatting acts in the IDE then starting with this file is a good idea.
61+
62+
```cpp
63+
---
64+
Language: Cpp
65+
# LLVM is the default style setting, used when a configuration option is not set here
66+
BasedOnStyle: LLVM
67+
AccessModifierOffset: -2
68+
AlignAfterOpenBracket: Align
69+
AlignConsecutiveAssignments: false
70+
AlignConsecuti
71+
AlignConsecutiveDeclarations: false
72+
AlignConsecutiveMacros: false
73+
AlignEscapedNewlines: DontAlign
74+
AlignOperands: Align
75+
AlignTrailingComments: true
76+
AllowAllArgumentsOnNextLine: true
77+
AllowAllConstructorInitializersOnNextLine: true
78+
AllowAllParametersOfDeclarationOnNextLine: true
79+
AllowShortBlocksOnASingleLine: Always
80+
AllowShortCaseLabelsOnASingleLine: true
81+
AllowShortEnumsOnASingleLine: true
82+
AllowShortFunctionsOnASingleLine: Empty
83+
AllowShortIfStatementsOnASingleLine: Always
84+
AllowShortLambdasOnASingleLine: Empty
85+
AllowShortLoopsOnASingleLine: true
86+
AlwaysBreakAfterDefinitionReturnType: None
87+
AlwaysBreakAfterReturnType: None
88+
AlwaysBreakBeforeMultilineStrings: false
89+
AlwaysBreakTemplateDeclarations: No
90+
BinPackArguments: true
91+
BinPackParameters: true
92+
# Only used when "BreakBeforeBraces" set to "Custom"
93+
BraceWrapping:
94+
AfterCaseLabel: false
95+
AfterClass: false
96+
AfterControlStatement: Never
97+
AfterEnum: false
98+
AfterFunction: false
99+
AfterNamespace: false
100+
#AfterObjCDeclaration:
101+
AfterStruct: false
102+
AfterUnion: false
103+
AfterExternBlock: false
104+
BeforeCatch: false
105+
BeforeElse: false
106+
BeforeLambdaBody: false
107+
BeforeWhile: false
108+
IndentBraces: false
109+
SplitEmptyFunction: false
110+
SplitEmptyRecord: false
111+
SplitEmptyNamespace: false
112+
# Java-specific
113+
#BreakAfterJavaFieldAnnotations:
114+
BreakBeforeBinaryOperators: NonAssignment
115+
BreakBeforeBraces: Attach
116+
BreakBeforeTernaryOperators: true
117+
BreakConstructorInitializers: BeforeColon
118+
BreakInheritanceList: BeforeColon
119+
BreakStringLiterals: false
120+
ColumnLimit: 0
121+
# "" matches none
122+
CommentPragmas: ""
123+
CompactNamespaces: false
124+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
125+
ConstructorInitializerIndentWidth: 2
126+
ContinuationIndentWidth: 2
127+
Cpp11BracedListStyle: false
128+
DeriveLineEnding: true
129+
DerivePointerAlignment: true
130+
DisableFormat: false
131+
# Docs say "Do not use this in config files". The default (LLVM 11.0.1) is "false".
132+
#ExperimentalAutoDetectBinPacking:
133+
FixNamespaceComments: false
134+
ForEachMacros: []
135+
IncludeBlocks: Preserve
136+
IncludeCategories: []
137+
# "" matches none
138+
IncludeIsMainRegex: ""
139+
IncludeIsMainSourceRegex: ""
140+
IndentCaseBlocks: true
141+
IndentCaseLabels: true
142+
IndentExternBlock: Indent
143+
IndentGotoLabels: false
144+
IndentPPDirectives: None
145+
IndentWidth: 2
146+
IndentWrappedFunctionNames: false
147+
InsertTrailingCommas: None
148+
# Java-specific
149+
#JavaImportGroups:
150+
# JavaScript-specific
151+
#JavaScriptQuotes:
152+
#JavaScriptWrapImports
153+
KeepEmptyLinesAtTheStartOfBlocks: true
154+
MacroBlockBegin: ""
155+
MacroBlockEnd: ""
156+
# Set to a large number to effectively disable
157+
MaxEmptyLinesToKeep: 100000
158+
NamespaceIndentation: None
159+
NamespaceMacros: []
160+
# Objective C-specific
161+
#ObjCBinPackProtocolList:
162+
#ObjCBlockIndentWidth:
163+
#ObjCBreakBeforeNestedBlockParam:
164+
#ObjCSpaceAfterProperty:
165+
#ObjCSpaceBeforeProtocolList
166+
PenaltyBreakAssignment: 1
167+
PenaltyBreakBeforeFirstCallParameter: 1
168+
PenaltyBreakComment: 1
169+
PenaltyBreakFirstLessLess: 1
170+
PenaltyBreakString: 1
171+
PenaltyBreakTemplateDeclaration: 1
172+
PenaltyExcessCharacter: 1
173+
PenaltyReturnTypeOnItsOwnLine: 1
174+
# Used as a fallback if alignment style can't be detected from code (DerivePointerAlignment: true)
175+
PointerAlignment: Right
176+
RawStringFormats: []
177+
ReflowComments: false
178+
SortIncludes: false
179+
SortUsingDeclarations: false
180+
SpaceAfterCStyleCast: false
181+
SpaceAfterLogicalNot: false
182+
SpaceAfterTemplateKeyword: false
183+
SpaceBeforeAssignmentOperators: true
184+
SpaceBeforeCpp11BracedList: false
185+
SpaceBeforeCtorInitializerColon: true
186+
SpaceBeforeInheritanceColon: true
187+
SpaceBeforeParens: ControlStatements
188+
SpaceBeforeRangeBasedForLoopColon: true
189+
SpaceBeforeSquareBrackets: false
190+
SpaceInEmptyBlock: false
191+
SpaceInEmptyParentheses: false
192+
SpacesBeforeTrailingComments: 2
193+
SpacesInAngles: false
194+
SpacesInCStyleCastParentheses: false
195+
SpacesInConditionalStatement: false
196+
SpacesInContainerLiterals: false
197+
SpacesInParentheses: false
198+
SpacesInSquareBrackets: false
199+
Standard: Auto
200+
StatementMacros: []
201+
TabWidth: 2
202+
TypenameMacros: []
203+
# Default to LF if line endings can't be detected from the content (DeriveLineEnding).
204+
UseCRLF: false
205+
UseTab: Never
206+
WhitespaceSensitiveMacros: []
207+
```
208+
209+
## Conclusion
210+
211+
In this tutorial we went through how to customize the behaviour of the CTRL + T / CMD + T auto formatter command in the Arduino IDE 2.0. This article also shows the different scopes for the auto formatter configuration.
212+
213+
### More Tutorials
214+
215+
You can find more tutorials in the [Arduino IDE 2 documentation page](/software/ide-v2/).

0 commit comments

Comments
 (0)