In CodeBlocks clixk Settings, Editor. Use these settings:
Editor, General Settings, TAB options:
- Uncheck TAB character
- Check TAB indent
- TAB size in spaces: 3
Indent options:
- Check auto indent
- Check smart indent
- Check brace completion
- Check brace smart indent
Source formatter:
Bracket style: Whitesmith
Indendation, Indentation size: 3
(All brackets, indentation, formatting, padding options appear to be unchecked)
On the "Style" page, click preview. Note how you see:
int Foo (bool isBar)
{
if (isBar)
{
Perfect. Now add a new C++ file or any other file, does not matter. Start typing the above text example code text. You get this:
int Foo (bool isBar)
{
if (isBar)
{
Note how the brackets are not indented as much as they should be.
Which is wrong and not what the preview shows. I have tried various options to get this to work, no luck. I did find Google references to other people complaining about it as well.
You can click Plugins, Source code formatter and it will fix it for you, but after the fact. And then, no matter what you set in the editor general settings, it just cant detect what you are doing. You can have:
int Foo()
{
int (x) //Now type { and it wont indent for you
}
So brace smart indent also does not figure it out.
I should mention that this web site unfortuantely removes the leading spaces on any line. But on the style preview you can see the style we want, and can find now way to set it in the editor.
Hi, you should use the markdown language, especially the code tag(you can see it in the editor's toolbar), see below:
Last edit: ollydbg 2017-02-15
Just to be clear (since I cant edit the original issue text), I am trying to get the auto indenting to do this:
But it wants to do this, if you type: if (x)<enter>{
Cant get that bracket that follows the "if" to indent no matter what settings you check.
Last edit: Sharlene 2017-02-28
If you read here, you will see this is something that used to work that got broken that is frustrating other users as well.
Which is the last version that works? What version are you using?
Last edit: Teodor Petrov 2017-03-01
This got broken somewhere between 10.5 and 13.12. The link above where others report this problem says "I have used CB 10.5 until upgrading to the latest 13.12 version and my indents in Whitesmith mode are broken too."
I have a similar problem with Code::Blocks 17.12 on Windows 10 Version 1709. I followed the steps that Sharlene outlined and could not get indentation that followed the preview in Code::Block's settings. I instead had to manully place my brackets in the spaces that I wanted them to be in. It may be worthwhile to look further in the "Source Formatter" and "General Settings" sections of the Editor Settings to see if there are any more relevant options that would enable the expected type of indentation to be used.