Menu

#119 automatic generation of close curly brace

Next_Release
open
nobody
None
Bug_Report
2016-01-30
2014-12-22
beauxq
No

I type my code like this:

if (foo() == 42)
    bar();

cout << something_else << endl;

Then I think, Oh wait, there's something else I want to do if foo returns 42...

so I need a curly brace...

I put my cursor at the end of the "if" line, press enter, press backspace to de-indent, that's where my curly brace goes...

Code::Blocks gives me this:

if (foo() == 42)
{

}
    bar();

cout << something_else << endl;

This is the thing I find most annoying about coding in Code::Blocks.
(I don't know whether other IDEs do this or something else.)

It seems like it should be able to see that this is what I want:

if (foo() == 42)
{

    bar();
}

cout << something_else << endl;

If the number of lines, below the insertion of a curly brace, that are indented compared to what is above the insertion of the curly brace, is 1, then put the automatically generated close brace after that 1 line.

Discussion

  • Teodor Petrov

    Teodor Petrov - 2014-12-22

    This is the main reason, I don't use this feature. It is pretty annoying when editing existing code.

    A workaround you can use is to go to the closing curly brace and use alt-down arrow to move the line where it belongs.

     
  • ollydbg

    ollydbg - 2014-12-23

    I also think it is a very annoying bug.

     
  • Alpha

    Alpha - 2015-01-30

    This is sort of a feature to deal with this case. Enable "Selection brace completion" in general settings. Select anything (does not matter what) on the line with bar().

    if (foo() == 42)
        bar();
    

    Type "{". Now you have:

    if (foo() == 42)
        {
            bar();
        }
    

    Not exactly what we want :/ ... but I think the extra level of indentation (select it all and shift-tab it away) is due to another piece of auto-indent code that was written without testing this feature.

     
  • Morten MacFly

    Morten MacFly - 2015-02-07
    • Type: --> Undefined
     
  • Alpha

    Alpha - 2015-02-08
    • Type: Undefined --> Bug_Report
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.