Author Topic: curly braces and auto indent  (Read 8493 times)

Offline lewashby

  • Single posting newcomer
  • *
  • Posts: 3
curly braces and auto indent
« 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
}

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7163
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: curly braces and auto indent
« Reply #1 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").

Offline lewashby

  • Single posting newcomer
  • *
  • Posts: 3
Re: curly braces and auto indent
« Reply #2 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.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 4904
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: curly braces and auto indent
« Reply #3 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: [Select]
int main()
Then I hit enter, I get my caret to the second line.
Then, I enter a '{', and the code becomes:
Code: [Select]
int main()
{
    //* note that the caret was automatically placed here
}
So, I don't need to press Enter again.  ;)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline nightlight

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: curly braces and auto indent
« Reply #4 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: [Select]
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: [Select]
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.
« Last Edit: February 07, 2015, 07:58:25 am by nightlight »

Offline nightlight

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: curly braces and auto indent
« Reply #5 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10019
Re: curly braces and auto indent
« Reply #6 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.
<debugger plugin maintainer>
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline lewashby

  • Single posting newcomer
  • *
  • Posts: 3
Re: curly braces and auto indent
« Reply #7 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10019
<debugger plugin maintainer>
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline shar136

  • Single posting newcomer
  • *
  • Posts: 1
Re: curly braces and auto indent
« Reply #9 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/.

Let us hope someone fixes it, since it used to work.

Offline StevieCoder

  • Single posting newcomer
  • *
  • Posts: 1
Re: curly braces and auto indent
« Reply #10 on: March 24, 2017, 04:27:02 pm »
Hi
Yes you have to change it in settings, I can't remember where, but I know that you can change it. I prefer Eclipse and I'm using it for a long time I can say ever since:-)
« Last Edit: May 02, 2017, 12:55:26 pm by StevieCoder »
Stevie Robson