Wednesday, September 23, 2015

Re: Bug: Inconsistent result with searchpair()?

On Mi, 23 Sep 2015, David Fishburn wrote:

> Windows 8.1 Vim 7.4.1-873
>
> In one of my plugins I am seeing inconsistent behaviour with searchpair()
>
> When it runs, it returns 0, when the cursor is in the exact same position and I
> run it a second time, it correctly finds the matching ).
>
> When I run it myself from :echo searchpair() it always works.
> But it fails everytime in my plugin.
>
> See my debug session here which I will annotate.
>
>
> I am about to run this searchpair() function
>     line 38: let indent_to = searchpair( '(', '', ')', 'W', 'synID(line
> ("."),col("."),1)>0' )
>
> So, I check my line, column, current character and show the full line:
> >echo line('.') col('.') getline('.')[col('.')-1] getline('.')
> 3 15 (     SELECT-@- (
>
> So I am on an open (, searchpair() should find the closing )
>
> >n
> line 42: if indent_to == 0 && linenum == line(".") && curcol == col(".")
> >echo line('.') col('.') getline('.')[col('.')-1] getline('.')
> 5 12 ) -@-END CASE) AS 'POTYP', COALESCE( OLTXT.LTXT, '' ) AS LTXT
>
> Good, clearly the cursor has been moved from line:3, col :15 to line:5 col:12
>
> And verify the result from the searchpair() call:
> >echo indent_to
> 5
>
> Continue to the next open ( (which is on the same line)
>
> >c
> Breakpoint in "<SNR>90_SQLU_SplitUnbalParan" line 38
>
> Same deal, before we run this same line again, lets check the current cursor
> position:
>
> line 38: let indent_to = searchpair( '(', '', ')', 'W', 'synID(line("."),col
> ("."),1)>0' )
>
> >echo line('.') col('.') getline('.')[col('.')-1] getline('.')
> 6 26 ( -@-) AS 'POTYP', COALESCE( OLTXT.LTXT, '' ) AS LTXT
>
> So, line 6: col:26 we are on an open ( which is at the end of the COALESCE
> word) and we want to match the closing ), which is right before the word "AS".
>
> >n
>
> Lets check the results:
>
> >echo indent_to
> 0
>
> This is bad, it says there is no match for searchpair().
>
> So, lets check the cursor position again:
>
> >echo line('.') col('.') getline('.')[col('.')-1] getline('.')
> 6 26 ( -@-) AS 'POTYP', COALESCE( OLTXT.LTXT, '' ) AS LTXT
>
> So, the cursor has not moved (and it shouldn't since searchpair() didn't match)
>
> But this time, simply copy and paste the same line it just executed:
>
> >let indent_to = searchpair( '(', '', ')', 'W', 'synID(line("."),col("."),1)>0'
> )
>
> And check the result:
>
> >echo indent_to
> 6
>
> This time it found a match and all I did was run the same line 2x after
> verifying the cursor has not moved.
>
> >echo line('.') col('.') getline('.')[col('.')-1] getline('.')
> 6 43 ) -@-) AS 'POTYP', COALESCE( OLTXT.LTXT, '' ) AS LTXT
>
> Now we can see we have moved to the closing ) at col:43.
>
>
> Anyone have any suggestions on what I might look into to figure this out.

My suspicion is, that syntax highlighting changes slightly and your skip
part catches it. Could you check the synid(line('.'),col('.'),1) for
when it does not move on both parenthesis? Did this perhaps get out of
sync and your (...) is somehow syntax highlighed?

Best,
Christian
--
Mein Lebensmotto ist: Mittagsschläfchen, Masturbation und Müßiggang.
-- Hermes Phettberg

--
--
You received this message from the "vim_use" 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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: