-
-
Notifications
You must be signed in to change notification settings - Fork 440
[MKC-496]Benjamindannegard/ide 2.0 auto formatter tutorial #317
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
Merged
BenjaminDannegard
merged 11 commits into
main
from
benjamindannegard/IDE-2-formatter-tutorial
Jul 19, 2022
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
32dc81a
Added tutorial
BenjaminDannegard c5b68b1
Added image
BenjaminDannegard 503650f
Small fix
BenjaminDannegard 4cc8d93
Update content/software/ide-v2/tutorials/ide-v2-customize-auto-format…
BenjaminDannegard f8ca773
Update content/software/ide-v2/tutorials/ide-v2-customize-auto-format…
BenjaminDannegard 8ad7d71
Update content/software/ide-v2/tutorials/ide-v2-customize-auto-format…
BenjaminDannegard b43294a
Update content/software/ide-v2/tutorials/ide-v2-customize-auto-format…
BenjaminDannegard 3b315c9
Changed file format
BenjaminDannegard bee9dbc
Changed according to review
BenjaminDannegard 5969464
Small fix
BenjaminDannegard 7914282
Removed duplicated section
BenjaminDannegard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+233 KB
...ide-v2/tutorials/ide-v2-customize-auto-formatter/assets/format-file-at-root.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
219 changes: 219 additions & 0 deletions
219
content/software/ide-v2/tutorials/ide-v2-customize-auto-formatter/content.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
--- | ||
title: 'Customizing the Auto Formatter Feature' | ||
difficulty: easy | ||
description: 'Learn how to configure the auto formatter feature' | ||
tags: | ||
- Auto Formatter | ||
- Tools | ||
author: 'Benjamin Dannegård, Per Tillisch' | ||
--- | ||
|
||
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. It is possible to change the behaviour of this command. In this tutorial we will go through how you can change the behaviour of this command. | ||
|
||
You can easily download the editor from the [Arduino Software page](https://www.arduino.cc/en/software#experimental-software). | ||
|
||
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. | ||
|
||
## Requirements | ||
|
||
- Arduino IDE 2.0 installed. | ||
|
||
## Setting the Custom Configuration | ||
|
||
It is possible to define your own custom configuration of the auto formatter feature 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. | ||
|
||
BenjaminDannegard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
### Global scope | ||
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. | ||
|
||
If you are using Windows place the file in: | ||
``` | ||
C:\Users\<username>\.arduinoIDE\ | ||
``` | ||
Or | ||
``` | ||
C:\Users\<username>\AppData\Local\Arduino15\ | ||
``` | ||
|
||
If you are using Linux place the file in: | ||
``` | ||
~/.arduinoIDE/ | ||
``` | ||
Or | ||
``` | ||
~/.arduino15/ | ||
``` | ||
|
||
If you are using macOS place the file in: | ||
``` | ||
~/.arduinoIDE | ||
``` | ||
Or | ||
``` | ||
~/Library/Arduino15/ | ||
``` | ||
|
||
### Sketch scope | ||
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. | ||
|
||
 | ||
BenjaminDannegard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Default Formatting File | ||
|
||
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. | ||
|
||
***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.*** | ||
|
||
```cpp | ||
--- | ||
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 | ||
AlignConsecuti | ||
BenjaminDannegard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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: [] | ||
``` | ||
|
||
## Conclusion | ||
|
||
In this tutorial we went through how to customize the behavior of the `CTRL + T / CMD + T` auto formatter command in the Arduino IDE 2.0. This tutorial also shows the different scopes that are available for the auto formatter configuration. | ||
BenjaminDannegard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### More Tutorials | ||
|
||
You can find more tutorials in the [Arduino IDE 2 documentation page](/software/ide-v2/). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.