Author Topic: Undesirable feature: multiline brace completion  (Read 11960 times)

Offline szczepan

  • Multiple posting newcomer
  • *
  • Posts: 42
Undesirable feature: multiline brace completion
« on: October 13, 2009, 12:37:43 pm »
The editor should not auto-expand auto-completed braces into a multiline block like this:

Code
{
    |
}

There are many situations in coding where single line blocks are needed - simple one-liner accessors, array-of-structs initializers etc. Just imagine having to undo the brace completion's auto-formatting for each line of this:

SKeyMap kmap[]= {

        { EKA_MOVE_FORWARD, KEY_UP },
        { EKA_MOVE_BACKWARD, KEY_DOWN },
        { EKA_STRAFE_LEFT, KEY_LEFT },
        { EKA_STRAFE_RIGHT, KEY_RIGHT } /* , */

        // ... in a real app, dozens more keymappings would follow...
    };

There is a simple and widely implemented solution that performs satisfactorily both for one-line and multiline blocks:

  • on '{' typed, only complete with '}' behind the caret, don't format
  • on CR typed while the caret is between adjacent '{' and '}' (possibly allowing single line whitespace), do the nice formatting.

Type '{'. Want the block in a single line? Just continue typing. Want indented multiline block? Press Enter. That's how MonoDevelop does it, and it rocks.

An alternative would be to register the whole sequence comprising the multiline formatting (but not completing the brace) as a single Undo step. Type '{'. Want indented multiline block? Just continue typing. Want the block in a single line? Press Ctrl+Z.

_
« Last Edit: October 13, 2009, 12:45:07 pm by szczepan »

Offline Kazade

  • Multiple posting newcomer
  • *
  • Posts: 73
Re: Undesirable feature: multiline brace completion
« Reply #1 on: October 13, 2009, 04:19:27 pm »
Just wanted to add my +1 to this. The new brace completion is really irritating. I like the behaviour that Netbeans has (this might be the same as you explained, I'm not sure.

If I type this:

Code
void Something::SomeMethod(| 

The closing bracket should appear after the caret. But, if I then type a closing bracket, the closing brackets shouldn't double up, but instead my closing bracket should overwrite the auto-completed one.

If I then type a brace:

Code
void Something::SomeMethod() {| 

Nothing happens until I press enter THEN it does this:

Code
void Something::SomeMethod() {
    |
}

This is obviously my coding style, but if you prefer your braces lined up the same thing should happen. The second brace should only appear when Enter is pressed. Leaving the caret indented.

Offline Kalith

  • Multiple posting newcomer
  • *
  • Posts: 67
Re: Undesirable feature: multiline brace completion
« Reply #2 on: October 13, 2009, 07:19:58 pm »
I think this is a very interesting feature, but I also think it should be heavily customizable for multiple reasons. Different coding styles, different habits...

For example, I'm actually not bothered by this brace autocompletion system, but the new line alignment (from the latest nightly) just doesn't fit my coding habits. If I want to type this :
Code
mMovement = Vector(
    0.0f, 0.0f, 0.0f
);

... I write the first line, press enter :
Code
mMovement = Vector(
                   |)
... and I have to remove all the spaces.

I'm also not pleased by the way bracket completion works. If the caret is placed before a ')' and you try to write another, it always "replaces" the one that is already here. This is annoying in this kind of situation :
Code
someFunction(someOtherFunction(|));
If you accidentally press [Del.] (happens to me all the time, really...) and want to type the ')' back, you either have to type it twice, or move the caret after the last ')' then type it once (it's a two key process anyway, and it gets even worse when there are many brackets).
Same goes for quotation marks :
Code
someFunction("|");
Press [Del.] or [Backspace] then type a quotation mark, you'll end up with this :
Code
somefunction(""|");
I don't know what could be done to solve this, maybe track for unclosed brackets / q. marks ?

Anyway thanks for the work you're putting on this, C::B really is my favorite IDE :)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Undesirable feature: multiline brace completion
« Reply #3 on: October 13, 2009, 07:27:12 pm »
...
For example, I'm actually not bothered by this brace autocompletion system, but the new line alignment (from the latest nightly) just doesn't fit my coding habits. If I want to type this :
Code
mMovement = Vector(
    0.0f, 0.0f, 0.0f
);
...
This comes from the brace indentation patch I've submitted. And if you really want it, I can make a patch that allows the user to disable it.
The idea of the patch is to allow you to write:
Code
    my_func(param1, param2, param3,
                  param4, param5, param6);

Best regards.
(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 Kalith

  • Multiple posting newcomer
  • *
  • Posts: 67
Re: Undesirable feature: multiline brace completion
« Reply #4 on: October 13, 2009, 08:55:56 pm »
I understand the need, and actually find it useful in some situations, but in my case it's doing more harm than good.
Anyway, I'd be very happy if this was to become configurable !
Thanks for your time.

Offline Kalith

  • Multiple posting newcomer
  • *
  • Posts: 67
Re: Undesirable feature: multiline brace completion
« Reply #5 on: January 13, 2010, 08:20:14 pm »
Any news on this patch :) ?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Undesirable feature: multiline brace completion
« Reply #6 on: January 13, 2010, 08:53:18 pm »
I've it on the TODO, but it is very low.

devs: where to put the check box? Settings -> Editor -> General -> Indent options? And how should be called?
(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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Undesirable feature: multiline brace completion
« Reply #7 on: January 13, 2010, 09:25:12 pm »
devs: where to put the check box? Settings -> Editor -> General -> Indent options? And how should be called?
Generally yes, but I think this section really needs some clean up. There are way too many options which should be separated on two tabs for example. However, how to split is another question. ;-)

For now try to find some space...

Notice that under this settings in the section "indent option" there is already a brace completion checkbox btw... I wonder if you need to implement anything at all... ;-)
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 Kalith

  • Multiple posting newcomer
  • *
  • Posts: 67
Re: Undesirable feature: multiline brace completion
« Reply #8 on: January 13, 2010, 09:38:29 pm »
Quote
I wonder if you need to implement anything at all... ;)
Actually yes, it's not about brace completion, but some part of the "smart indent" that I'd like to disable.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Undesirable feature: multiline brace completion
« Reply #9 on: January 13, 2010, 10:57:08 pm »
Brace completion is another matter.... and I want to have a check, so I keep it off.
Maybe we need advanced button and some pre set options/profiles.

I'll try to find some space tomorrow.
(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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Undesirable feature: multiline brace completion
« Reply #10 on: February 11, 2010, 09:33:34 pm »
(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 Kalith

  • Multiple posting newcomer
  • *
  • Posts: 67
Re: Undesirable feature: multiline brace completion
« Reply #11 on: February 28, 2010, 02:05:37 pm »
Thank you very much !