Arduino Auto Formatting Listings
by qthurtle in Circuits > Arduino
2009 Views, 4 Favorites, 0 Comments
Arduino Auto Formatting Listings
The default way that the Arduino programming environment handles braces (curly brackets) has annoyed me for years (see the first image).
I much prefer the braces to be separated out onto their own lines (see the second image). I find this much easier to de-bug. I gather it is called 'Allman' style.
When editing your sketches, pressing CTRL+T will re-format the whole program code beautifully, but (by default) to the style which I don't like.
It is easy to adjust the auto formatter's default actions (not only for the braces, but for a vast range of options).
The process is to find the file called 'formatter.conf', copy it to your local preferences file and make a one-line addition.
Making the Change
Find the 'formatter.conf' in the main Arduino installation folder.
Mine was in the folder called C:/Program Files (x86)/Arduino/lib/
Copy the file (CTRL+C) and paste it into your own local preferences folder.
To find this folder, double-click one of your sketches and then go to File>Preferences and you will see a window similar to that shown here.
Paste the 'formatter.conf' file into your own preferences folder (CTRL+V). (It will be alongside your own 'preferences.txt' file).
Make the Change to the Preferneces
You may have to close your Arduino environment before making the following change to this file?
If you double-click on your newly copied 'formatter.conf' file, you may have to tell your computer to open it in Notepad or similar.
Finally add the line
--style=allman
into the 'formatter.conf' file. I don't think the position really matters??
I added a comment above it.
(Moving the 'formatter.conf' file into your own preferences folder, means that the change will 'stick' even if you update your Arduino installation).
Making Other Changes
I believe that a huge range of default options can be changed by adding similar lines.
The guidelines are here: http://astyle.sourceforge.net/astyle.html