I also found this unpleasant bug in the new AVRStudio 5. I could not find a way to make the default VS code formatting to work, so I made it with o workaround.
Here is how I did it, may be it will be helpful for anybody else:
For formatting the source code I used an external command line and freeware tool
AStyle (
http://astyle.sourceforge.net/ ), which has a lot of options.
In AVRStudio go to:
Tools > External Tools.
In the new window click Add button and fill up the fields like this:
Title: AStyle (or whatever you like)
Command: the path to the .exe file of the tool, in my case D:\Tools\AStyle\bin\AStyle.exe
Arguments: Arguments for the tool according to the formatting style you like (check documentation), in my case: -y --indent=spaces=2 --style=ansi --errors-to-stdout --suffix=none $(ItemDir)$(ItemFileName)$(ItemExt)
(Last 3 parameters represent full path to source file you are currently editing in VS.)
Use output window: checked
Treat output as Unicode: unchecked
Prompt for arguments: unchecked
Now click Apply and Ok. Now the new tool can be used from Tools > AStyle command in AVRStudio 5.
To make life easier, you can add a keyboard shortcut for this:
Go to Tools > Options
In the new window go to Environment > Keyboard
Now choose command Tools.ExternalCommand1 (or other if you have more external tools set) and assign a new shortcut (I used CTRL+SHIFT+ALT+F)
Now when you want to use the code beautifier:
1. Save the file (because the tools will overwrite the latest version of the file saved on the hard drive and not the currently unsaved version in AVRStudio5).
2. Apply the tool, using the command or the keyboard shortcut.
3. A popup appears saying that: 'This file has been modified outside of the source editor. Do you want to reload it?' Click Yes, and enjoy the nicely formatted source code.
4. In the standard output window you can see messages from the tool when you use it.
Hopefully this will be useful to anybody.
If there is any other way to use the code style formatting options in AVRStudio5, please share your knowledge!