Changing preferences.txt to 4-space tabs, how to AutoFormat existing code?
The auto formatter (astyle) uses a separate configuration to the editor (crazy, I know, but that's the Arduino mentality for you...).

It uses a separate configuration, which is in the lib folder of your Arduino program, called formatter.conf.


Copy that file to the same location as preferences.txt so it doesn't get overwritten when you upgrade the IDE.
Edit the file and change indent=spaces=2 to indent=spaces=4


The auto format should now be the same as the editor format.