On Thu, Jul 8, 2010 at 12:00 PM, KKde <[email protected]> wrote:
> I have written my own user defined complete function(written
> completely in vim scripting only, no other lang's used). In complete
> function, one part of code finds the line no of opening parenthesis of
> a function.
> I have used the below code to do that.
>
> let line=1
> while ( line != 0)
>            let line = searchpair('(', '', ')', 'bW',
> 'synIDattr(synID(line("."), col("."), 1), "name") =~ "cComment"')
> endwhile
>
> The problem with the above code is searchpair function is very slow.
> It takes 6-7 seconds to match the opening parenthesis (Note: opening
> parenthesis not farther than 10-15 lines).

Why do you have the while loop?  searchpair() returns the line on which
the paired item was found, 0 if it couldn't find a matching pair, or -1
if the skip expression caused an error while being evaluated.

By using the while loop, you're not only discarding any match that you
do find, but you're then causing Vim to search the entire buffer
previous to the cursor position for any other match.  That's likely the
cause for the delay you're seeing.

-- 
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[email protected]>

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui