expand tab spaces from 2 to 3

hello,
to expand tab spaces from 2 to 3 I changed in preferences.txt the line
editor.tabs.size=3
but it''s still 2 spaces for auto-intend and when pressing ctrl+T
what am I missing?
(IDE closed before changing, then restarted the IDE; IDE 1.8.9)

There is a separate setting that controls the auto format tab size. The auto formatter is configured by the file {Arduino IDE installation folder}/lib/formatter.conf. The property is indent=spaces=.

My recommendation is to copy formatter.conf to the Arduino IDE's data folder before modifying it. You can find the location of this folder by doing this:

  1. Select File > Preferences from the Arduino IDE's menus.
  2. Check the path shown on the line following "More preferences can be edited directly in the file".

The reason for storing your modified formatter.conf in that folder is so that your changes will persist through updates of the Arduino IDE, which erase all the files from the Arduino IDE installation folder. The Arduino IDE gives preference to the formatter.conf file that is found in the data folder over the one in the Arduino IDE installation folder.

You need to restart the Arduino IDE before changes to formatter.conf will take effect.

For more information on the auto formatter configuration options:

1 Like

By the way, a feature request has been made to unify the editor and formatter's tab size preferences:

That all said, I would counsel against changing this. 2 spaces is a very common convention. 4 spaces is less common, but still widely used. 3 is very rare. Unless you have a compelling reason to use an unusual indentation convention, don't - it will annoy people reusing your code (if you share it) and I have seen editing tools that only allow 2 or 4 spaces for indentation

I do like that the Arduino IDE's auto format tool establishes a code formatting standard for the Arduino community. I use the same standard in my library code as well as my sketches. For that reason, I don't modify the stock configuration, even though there might be a couple things I would have done differently if it were up to me to make the choice. The auto format tool does offer additional configuration options to further enforce a consistent code formatting style, without changing the existing conventions, and I do use some of those options. I have based their settings on the style established by Arduino's example sketch formatting script's configuration, as well as the prevailing styles in the official Arduino code:

I actually do kind of like the idea of 3 space indents. I'm happy with 2 space indents, but I could see how someone with poor eyesight could find it not quite obvious enough. But 4 spaces is too much (and the 8 space people are nuts!). So 3 spaces is a happy medium, but also completely non-standard.

thank you, with the formatter.conf setting now it works fine.

You're welcome. I'm glad to hear it's working now. Enjoy!
Per

This one has confused me right along.

Pert explains it well enough, but just exactly where does the copy of formatter.conf go?
Does it go in "C:\Users\My name\AppData\Local\Arduino15" so it's at the same hierarchy level as preferences.txt?
Locating the file there has no effect?
So formatter.conf works from the Arduino 15/lib folder?
So, I edit formatter.conf in my favourite text editor and change indent spaces from 2 to 4?
I then place the edited copy of the formatter.conf file back in x86 programs/Arduino/lib?
I should have the original copy in Arduino 15 where it does nothing, and the edited copy in the x86 programs/Arduino/lib?
Then hopefully, when I restart the IDE, my auto formatter now tabs at 4 spaces instead of 2.
And yes, my eyesight is pretty poor as well.

That's the most common location. However, there are some cases (when using the Microsoft Store version, or with the IDE in portable mode) that the Arduino15 folder is not used by the Arduino IDE. You can verify the correct location by selecting File > Preferences from the Arduino IDE's menus and then looking at the path for preferences.txt shown on the line following More preferences can be edited directly in the file.

Correct.

One thing to note is that this file only affects the configuration of the formatter tool used by the Arduino IDE's Tools > Auto Format feature. It has no affect on the indent size you get when pressing the Tab key. That is controlled by the editor.tabs.size property in preferences.txt.

Also make sure to close the Arduino IDE before editing preferences.txt, and also to make sure to restart it after modifying formatter.conf.

You can do that if you like, but you'll need to redo it every time you update to a new version of the Arduino IDE. This is the primary benefit of putting the customized file in the Arduino15 folder.

Thanks Pert.

You can probably guess that
a) I'm very wary of changing anything I don't understand, and
b) programming is not my day job

The new look forum came as a bit of a culture shock and I actually quite like the simplicity of the old forum, but I'm sure there must have been some good reasons for changing it.

Cheers

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.