News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Undesirable feature: multiline brace completion

Started by szczepan, October 13, 2009, 12:37:43 PM

Previous topic - Next topic

szczepan

The editor should not auto-expand auto-completed braces into a multiline block like this:


{
   |
}


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.

_

Kazade

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:

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:

void Something::SomeMethod() {|

Nothing happens until I press enter THEN it does this:

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.

Kalith

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 :
mMovement = Vector(
    0.0f, 0.0f, 0.0f
);


... I write the first line, press enter :
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 :
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 :
someFunction("|");
Press [Del.] or [Backspace] then type a quotation mark, you'll end up with this :
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 :)

oBFusCATed

Quote from: Kalith on October 13, 2009, 07:19:58 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 :
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:

    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!]

Kalith

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.

Kalith


oBFusCATed

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!]

MortenMacFly

Quote from: oBFusCATed on January 13, 2010, 08:53:18 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Kalith

QuoteI 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.

oBFusCATed

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!]

oBFusCATed

(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!]

Kalith