Changing indent in auto format

Can anyone tell me how to change the indent for auto format?

Thanks Terry

maybe this will help
http://astyle.sourceforge.net/astyle.html

I think you can do this in formatter.conf

.

Yes, it's {Arduino IDE installation folder}/lib/formatter.conf:
There are various indentation settings in that file, as documented at the link LarryD posted.
Just edit the file in a text editor, save, then restart the Arduino IDE if it's running. Note that you will need to repeat this process every time you update to a new version of the Arduino IDE.

I found this thread looking for this as well. While the file to modify is correctly identified, the config file had some additional wisdom to convey.

If you wish to change them, don't edit this file.

Instead, copy it in the same folder of file "preferences.txt" and modify the copy. This way, you won't lose your custom formatter settings when upgrading the IDE

If you don't know where file preferences.txt is stored, open the IDE, File -> Preferences and you'll find a link

Sn3akyP3t3:
I found this thread looking for this as well. While the file to modify is correctly identified, the config file had some additional wisdom to convey.

While that warning is valid for the rest of the contents, I’d simply ignore it for the tab setting. That setting in formatter.conf is good for auto format, did you make the change in preferences as well? (how many spaces for tab while editing in IDE)

My "formatter.conf" is in the 'hardware' subdirectory of my sketch folder and seems to work properly.

I would like to increase the Auto-formatter indent from 2 to 4 spaces to make it a bit more readable
Found the formatter.conf file in the Program Files(x86) > Arduino > lib folder.

@johnwasser I couldn't find it in hardware

I edited the indent value from 2 to 4, but Win 10 says I don't have permission to change it etc., etc despite being Administrator on my system, as usual, so it doesn't look as though I can do it there

I've changed the tab setting from 2 to 4 in the preferences file and that's OK

Is the formatter.conf file anywhere else? The Win 10 permission thing suggested going to the Users folder, but no formatter files there. Just searched C:\ and just the one entry for the conf file as above

Is larryd's link relevant to the Arduino formatter?

You add a "formatter.conf" file into your "hardware" folder to override any of the configuration. Here is what I use:

# This configuration file contains a selection of the available options provided by the formatting tool "Artistic Style"
# http://astyle.sourceforge.net/astyle.html
#
# If you wish to change them, don't edit this file.
# Instead, copy it in the same folder of file "preferences.txt" and modify the copy. This way, you won't lose your custom formatter settings when upgrading the IDE
# If you don't know where file preferences.txt is stored, open the IDE, File -> Preferences and you'll find a link


mode=c


# 2 spaces indentation
indent=spaces=2


# Put braces on separate lines
style=break


# also indent macros
indent-preprocessor


# indent classes, switches (and cases), comments starting at column 1
indent-classes
indent-switches
indent-cases
indent-col1-comments


# put a space around operators
pad-oper


# put a space after if/for/while
pad-header


# if you like one-liners, keep them
keep-one-line-statements


remove-comment-prefix

Thanks John - I’ll take a look at it.

Is the astyle.sourceforge etc. file used by Arduino, or is it another way to generate the conf file? That might answer my last question.

The only places I found any other formatter.conf files was one in the nightly build folder and another in an energia folder - energia is a Texas Instruments compiler or IDE based on Wiring and Arduino for some of their development boards.

tigger:
Is the astyle.sourceforge etc. file used by Arduino, or is it another way to generate the conf file? That might answer my last question.

I believe that the Arduino IDE uses the "Artistic Style" (astyle) library documented at:
http://astyle.sourceforge.net/astyle.html
Use the documentation to see what options are available in the formatter.conf file.

Hello John
Here's what I did.
I copied your file from above "formatter.conf" post
I edited it so that indent=spaces=4
I saved it into Arduino>hardware, the same folder (Arduino) as sketches and libraries.
I opened "Blink", back-tabbed everything then tried auto format, still indents 2, not 4
Also put a copy with indent = 4 into the "preferences" folder.
I must be doing something wrong?

Putting it in the hardware folder doesn't work for me either and I have not ever heard of that being possible, except for here. I wish it was possible to store the file there.

As the instructions say, you need to put the file in the same folder as preferences.txt. You can find that folder by clicking the link at the line following File > Preferences > More preferences can be edited directly in the file in the Arduino IDE. You need to restart the IDE before changes to formatter.conf will take effect

I THOUGHT it was working in the 'Arduino/hardware' folder but I could not change tab spacing until I moved 'formatter.conf' to the same folder as the 'preferences.txt' file.

Thanks pert and John
I still haven't got it working but I need to come back to it after the weekend.
I think I'm getting in a pickle with exactly which formatter.conf file goes where i.e. original file or edited file.
Anyway I'll get back to you on this
Cheers

The edited file goes in the same folder as your preferences.txt. There, it will override the one inside the Arduino IDE installation folder.

Got it pert.
I was editing and saving in Notepad so it saved it as a text file .text
Despite years of working with Windows and files, I have never worked with a .conf file
As conf didn't come up as a "save as conf" in the "save as" dialogue, I assumed it couldn't be done, and I am wary of saving if there is a possibility of over-writing an important file.
So what I did, contrary to practice, was to name the file "formatter.conf" then choose save as "all files" in the dialogue.
Only tested it once in Blink, but it looks as though it works OK
GRRRRRR!
Happy bunny now, frustration over.
Point each to you and John for sticking with it

I'm glad to hear it's working now.

I definitely recommend that you install a higher quality text editor program. Notepad is very just not suitable for programming work. Even if you mostly just use the Arduino IDE, you're still going to end up needing to edit other files like formatter.conf with a text editor from time to time. I use Notepad++ but there are tons of other great choices for free, open source text editors and whichever one you chose will work fine.

Another thing I recommend is to configure Windows Explorer to show file name extensions (View > File name extensions (check)), which is turned off by default. That can make a file named formatter.conf.txt look like it's named formatter.conf, which can cause a ton of confusion and frustration.

Thanks pert
I do use Notepad++ and was using it to get around this indenting problem. I just used Notepad here as it came up first. The only reason I wanted to get Arduino to do it was that even if I had been careful in Notepad++ to get rid of leading spaces, as soon as I copied the code over to Arduino IDE, the IDE stuck some leading spaces in which defeated the object. However, it looks as though auto-formatting in the IDE is the way to go, now.
I do also look at extensions in Explorer, but in the activities of trying to get the original issue fixed, but I will take another look at how I've got it set up.