matchem icon indicating copy to clipboard operation
matchem copied to clipboard

Right brace did not paired when cursor at the end of line and the next line was not block

Open xinleibird opened this issue 11 years ago • 2 comments

For example:

...
    public void some() {
        ...
        somebody.do();

        // cursor `|` here when i input a "{", the "}" did not paired.
        for (.....) | 
        blblbl();
        ...
    }
...

it's became:

        ...
        somebody.do();
        for (.....) {
        blblbl();
        ...

but if the next line is block or "}", it's ok, and expand cr is ok too:

        ...
        somebody.do();
        for (.....) {}

    }
        ...
        //or
        ...
        somebody.do();
        for (.....) {}
    }

Sorry @ervandew , matchem is too ingenious so that i can not fix anything....but is there possibly do not match brace more than one line is better? At your disposal :yum:

xinleibird avatar May 06 '14 07:05 xinleibird

This is the intended behavior. The idea here is that it looks like you might be wrapping existing code in a new for block (your for line is directly before the blblbl(); line with no empty lines in between), so matchem errors on the side of not inserting a closing delimiter in ambiguous cases like this since, in my opinion, adding a closing delim when one is not wanted is more annoying than not adding one.

If you want, you can comment out lines 334-338 in plugin/matchem.vim to see how it behaves without that logic. It's when you go to wrap some existing code in an if that you may find the auto inserted } a bit annoying like I do.

ervandew avatar May 06 '14 15:05 ervandew

Ok, i am trying it now, thanks for your answer @ervandew , :laughing:

And i have your idea now. Yes, you are right....it's annoying indeed.....if we can not ensure proper, do nothing always be wise. Like that example, if it's matched and if blblbl() in the if...else, i have to dd and paste it into the braces, it's more trouble.... :disappointed_relieved:

Good job!

xinleibird avatar May 06 '14 16:05 xinleibird