Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: lewashby on February 05, 2015, 09:29:51 pm

Title: curly braces and auto indent
Post by: lewashby on February 05, 2015, 09:29:51 pm
I'm tying to decide between codeblocks, Eclipse, and Geany. When using codeblocks after I type the fist curly brace '{' codeblocks creates another one for me but leaves them both on the same line. After placing the cursor between the two braces '{}' and hitting Enter it drops the second curly brace '}' to the next line but fails to auto indent my cursor position to one tab between the position of the two curly braces. I have looked at the settings  under -> Source formatter -> Style, Indentation, & Formatting. -> General settings, -> and Code completion. Each time I think I have found the right setting and make the appropriate changes I see no affect after returning to codeblocks.

Example

int main()
{} // after pressing enter between these two I should get what's below

int main()
{
    //cursor here
}
Title: Re: curly braces and auto indent
Post by: Jenna on February 05, 2015, 10:05:30 pm
Play with the settings in "Settings -> Editor -> General settings -> Editor settings -> Indent options".
I have checked all of them, except the last one ("Select brace completion").
Title: Re: curly braces and auto indent
Post by: lewashby on February 07, 2015, 06:19:26 am
I'm still not getting a good result. Have to manually press ENTER twice between the {} curly brackets and then bring the cursor up and hit TAB.
Title: Re: curly braces and auto indent
Post by: ollydbg on February 07, 2015, 07:27:08 am
I'm still not getting a good result. Have to manually press ENTER twice between the {} curly brackets and then bring the cursor up and hit TAB.
I can't reproduce this issue. Do you check the options Jens' said?
Play with the settings in "Settings -> Editor -> General settings -> Editor settings -> Indent options".
I have checked all of them, except the last one ("Select brace completion").

In my C::B.
I first enter this.
Code
int main()
Then I hit enter, I get my caret to the second line.
Then, I enter a '{', and the code becomes:
Code
int main()
{
    //* note that the caret was automatically placed here
}
So, I don't need to press Enter again.  ;)
Title: Re: curly braces and auto indent
Post by: nightlight on February 07, 2015, 07:56:22 am
I have used CB 10.5 until upgrading to the latest 13.12 version and my indents in Whitesmith mode are broken too.
This is how the sample is supposed to look like:
Code
int Foo(bool isBar)
  {
  if (isBar)
    {
    bar();
    return 1;
    }
  else
    {
    return 0;
    }
  }

In the old CB, as soon as I typed Enter after if (isBar) the open brace was inserted at indent +2, the closing brace would be appear aligned 2 lines below it, with empty line & cursor ready right below the open brace (at same column) for the block in between.

In the new version, typing the same way, the code ends up looking like this, as if forcing some other source formatting style (with braces not aligned with the block between them), not Whitesmith:

Code
int Foo(bool isBar)
{
  if (isBar)
  {
     bar();
     return 1;
  }
  else
  {
     return 0;
  }
}

In the general settings for indentation I have checked on: Autoindent, Smart Indent, Brace Completion, Backspace unindents, Brace Smart Indent, Selection brace completion.
Title: Re: curly braces and auto indent
Post by: nightlight on February 09, 2015, 11:11:15 am
Unfortunately, due to the broken smart indentation for Whitesmith style as described in the previous post, I reverted back to C::B 10.05 version. When I get some time, I will look into C::B sources and fix the bug if it is still there by then.
Title: Re: curly braces and auto indent
Post by: oBFusCATed on February 09, 2015, 11:39:40 am
Please report it in the sf.net issues page, so it won't be forgotten.
Here it will be.
Title: Re: curly braces and auto indent
Post by: lewashby on March 12, 2015, 04:48:14 am
I'm using Code::Blocks v 13.12 and my 'Bracket Style' is set to 'Allman (ANSI)' under _ Settings -> Editor -> Source formatter -> TAB-Style.
Also under _ Settings -> Editor -> General settings -> TAB-Editor settings I have most of the options checked, Auto indent, Smart indent, Brace completion, etc...
oBFusCATed , what's the website where I can report this problem again? Thanks.


Rehash of my problem

if I type 'int main() + [Return]' then type '{'
I get this

int main()
{} // does not automatically drop the second curly brace '}' down two lines and insert a TAB or 4 spaces between the two curly braces and place the cursor there, I have to do it all manually.

I then have to place the cursor between the two curly braces '{}' and press [Return] twice, press [Arrow Up], and then press TAB.
Title: Re: curly braces and auto indent
Post by: oBFusCATed on March 12, 2015, 09:54:03 am
https://sourceforge.net/p/codeblocks/tickets/
Title: Re: curly braces and auto indent
Post by: shar136 on February 28, 2017, 09:26:25 pm
I have been experiencing the same problem, and logged it here https://sourceforge.net/p/codeblocks/tickets/472/ (https://sourceforge.net/p/codeblocks/tickets/472/).

Let us hope someone fixes it, since it used to work.
Title: Re: curly braces and auto indent
Post by: stahta01 on December 23, 2022, 08:29:41 am
Indentation is not a requirement of most programming languages, where it is used as a secondary notation. Instead, indentation helps to better convey program structure to readers. In particular, it is used to clarify the relationship between control flow constructs, such as conditions or loops, and the code contained within and outside them.

I have reported your posts as spam! I suggest you stop spamming.

Or if you are not a spammer find out why your posts with quotes of others all have spam links added to them.

Tim S.
Title: Re: curly braces and auto indent
Post by: jdx on December 23, 2022, 08:37:27 am
The spambot operator tried to be smart and started to append spamlinks to quoted posts of legit users.  ;D Anyway, I have been observing them for a few days. Different accounts, pretty much the same spamlinks. An URL blacklist is needed.