kana / vim-textobj-function

Vim plugin: Text objects for functions
http://www.vim.org/scripts/script.php?script_id=2619
141 stars 34 forks source link

Use % instead of [[ for finding the opening brace #7

Closed dkasak closed 11 years ago

dkasak commented 11 years ago

[[ will only match opening braces that are located in the first column which makes af and if work incorrectly with other brace positioning styles. This commit switches to % instead which will always find the matching brace.

This seems to pass your current tests (it took some time to install the whole test toolchain successfully :D). I didn't want to write any new tests since I'm still not very familiar with the test toolchain.

kana commented 11 years ago

I don't believe the change is right. How about the following code?

int foo(void)
{
    while (true)
    {
        foo();  /* the cursor is here. */
    }
}
kana commented 11 years ago

And I documented about the expected brace style. In other words, I don't want to support other styles at the moment. Additionally, your pull request doesn't update the document.

dkasak commented 11 years ago

Your example works as expected (i.e. af refers to the whole function, including the prototype line and if refers to the body of the function, excluding the braces). Why do you think it's wrong?

I could update the pull request to change the document. Of course, if you really feel strongly about not supporting other brace styles, I'll just use my own fork.

kana commented 11 years ago

Another example:


int foo(void)
{
    while (1)
    {
        // {{{  the cursor is here
    }
}
dkasak commented 11 years ago

Actually, this is where it breaks (it doesn't get the return type):

int 
foo(int a, 
    int b) {
    bar; /* cursor here */
}

Of course, the old code is also somewhat broken in this case, since in signatures where the return type is on the same line as the prototype it eats up an additional newline above the prototype, whereas in signatures such as this one, it doesn't. Also, it breaks on multiline signatures where there is whitespace right of the ), but I think that already falls under this.