Author Topic: curly braces and auto indent  (Read 26589 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 Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
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: 5913
  • 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
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.  ;)
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
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.
« 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: 13413
    • Travis build status
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.
(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: 13413
    • Travis build status
(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!]

shar136

  • Guest
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 stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: curly braces and auto indent
« Reply #10 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.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline jdx

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