Author Topic: Indenting 8 spaces  (Read 10190 times)

Offline korwynkim

  • Single posting newcomer
  • *
  • Posts: 2
Indenting 8 spaces
« on: February 04, 2012, 03:13:28 am »
Hi. Whenever I open a brace and press enter to go to a new line, Code Blocks indents 8 spaces instead of 4. This doesn't happen with functions, only if, while, for etc. If I turn smart indent off, the closing brace won't automatically move to the correct position.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Indenting 8 spaces
« Reply #1 on: February 04, 2012, 10:33:03 am »
Do you have exact reproduction steps?
I've seen this problem, but I think it doesn't happen all the time.
(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 Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Indenting 8 spaces
« Reply #2 on: February 04, 2012, 01:31:42 pm »
I get this behaviour, if I start a while-loop with the opebning brace in the same line as the while-statement and decide later to put it into the next line, by placing the caret in front of the opening barce and pressing enter.
This only happens, if the next line was auto-indented.
Steps to reproduce:
  • I have all indent options enabled,
  • I write while(1),
  • I add an opening brace,
  • a closing brace is automatically added, the caret is between both braces,
  • I press Enter, the closing brace is moved two lines below the while-statement, the caret is placed in the line between and indented automatically 4 spaces (seen from
  • the while keyword and/or the closing brace,
  • I place the caret if front of the opening brace and press Enter,
  • the opening brace is moved to the next line with wrong indentation.

Offline korwynkim

  • Single posting newcomer
  • *
  • Posts: 2
Re: Indenting 8 spaces
« Reply #3 on: February 04, 2012, 04:38:31 pm »
It only seems to happen with control structures. I don't have brace completion enabled. If i put an opening brace on the same line as the control statement and press enter, the caret will be indented 8 spaces on the next line. This only happens the first time. If I go back to the opening brace and press enter, the caret indents correctly.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Indenting 8 spaces
« Reply #4 on: February 04, 2012, 05:12:40 pm »
It's intended behaviour to double-indent the line following an opening brace, if "smart indent" is enabled. The closing brace is unindented once you hit return. This is meant to make typing code easier without you having to remember to indent each line properly. (Works 100% good for me every day, too. Trust me, if it didn't then I'd be puking.)

If you don't like this happening, disable "smart indent".

Of course, having "spaces instead of tabs" enabled is another matter. This is the in my opinion worst possible misconfiguration you can have (and unluckily the default, too). Maybe in 20 or 30 years from now, people will have learned that a tab and 4 space characters are not the same, and that spaces are not for indenting.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Indenting 8 spaces
« Reply #5 on: February 04, 2012, 05:46:01 pm »
Maybe in 20 or 30 years from now, people will have learned that a tab and 4 space characters are not the same, and that spaces are not for indenting.
This really depends on you habits. I for example seriously hate tabs because in every single editor with obscure and always different settings it screws your intended indention. I am just sick of setting the "how to interpret tabs" option in every fucking editor. Then, you show it to your mate and again its screwed because he has different settings, too. So, just use a courier (fixed) font type and spaces work the same on all editors and all platforms.
« Last Edit: February 04, 2012, 05:48:00 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Indenting 8 spaces
« Reply #6 on: February 04, 2012, 06:05:42 pm »
It only seems to happen with control structures. I don't have brace completion enabled. If i put an opening brace on the same line as the control statement and press enter, the caret will be indented 8 spaces on the next line. This only happens the first time. If I go back to the opening brace and press enter, the caret indents correctly.
Yes, this is the behaviour, I'm seeing, too.
Do you mean that C::B indents 8 spaces relative to the beginning of the if/for/while?
(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 rtty21

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Indenting 8 spaces
« Reply #7 on: December 28, 2012, 06:11:44 am »
I am having this problem as well.
I finally got around to upgrading to 12.11 and I was overjoyed that the auto code completion had been tinkered with and the bugs had been worked out.  :)

All was going well until I discovered that the Smart Indent feature now indents twice ( it places two tabs (8 spaces) instead of just one tab (4 spaces) ).
Does anyone know how to make it only indent once instead of indenting twice?
I would really appreciate anyone who could tell me because I really like the feature when it is only indenting once  :)


Thanks for taking the time to read my post :)
Jensen

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Indenting 8 spaces
« Reply #8 on: December 28, 2012, 06:37:17 pm »
rtty21: do know the exact steps to reproduce the problem?
(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 rtty21

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Indenting 8 spaces
« Reply #9 on: December 28, 2012, 09:23:41 pm »
rtty21: do know the exact steps to reproduce the problem?
STEPS:
1. turn on Smart Indent
2. type in an if/while/for/dowhile/switch statement in codeblocks like so:
Code
if( my_variable == 0)

3. then add a left surly bracket:
Code
if( my_variable == 0){

4. then add a newline and your cursor will be where the pipe is here (two indents to the right of the if statement):
Code
if( my_variable == 0){
        |
}

I would like the cursor to be here (one indent to the right of the if statement):
Code
if( my_variable == 0){
    |
}

does anyone know how to configure this in such a manor as to only have Smart Indent indent once for if/while/for/do-while/switch-case statements?
I would be very happy if I could be given a push in the right direction.  :)
I have searched google to no avail. :(

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Indenting 8 spaces
« Reply #10 on: December 28, 2012, 09:26:30 pm »
I have searched google to no avail. :(
You've searched the wrong place... you'd have to search the code for this:)

Do you have brace-completion enabled?
Does it happen every time?
(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 rtty21

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Indenting 8 spaces
« Reply #11 on: December 28, 2012, 09:46:53 pm »
wrong place... you'd have to search the code for this:)

Do you have brace-completion enabled?
Does it happen every time?

I don't really like brace completion.
nevertheless, i tried it.

it fixes the problem with if/switch-case/while/do-while/for statements, but it then screw up smart indentation for function definitions  :(
function definitions will not have any indents when i enable brace-completion. it looks like this:
Code
void my_function(int x, int y){
|
}
where the pipe is where my cursor is placed by default.

Thanks for the suggestion. I guess I would rather manually fix a function each time rather than a control statement each time seeing as how i'll definitely be writing a lot more of the latter.

that being said, it would be nice for this to function as I am describing it. Or, to be a little narcissistic, it would be nice to be able to fully configure this.
« Last Edit: December 28, 2012, 09:54:19 pm by rtty21 »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Indenting 8 spaces
« Reply #12 on: December 28, 2012, 10:19:01 pm »
Do you have brace-completion enabled?
Does it happen every time?

I don't really like brace completion.
nevertheless, i tried it.
You've not answered my questions...
(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 rtty21

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Indenting 8 spaces
« Reply #13 on: December 28, 2012, 10:50:49 pm »
Do you have brace-completion enabled?
Does it happen every time?

I don't really like brace completion.
nevertheless, i tried it.
You've not answered my questions...

oops! It does happen every time consistently.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Indenting 8 spaces
« Reply #14 on: December 28, 2012, 11:06:36 pm »
oops! It does happen every time consistently.
OK, I can reproduce it consistently, too.
(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!]