Wednesday, September 23, 2015

Bug: Inconsistent result with searchpair()?

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.


Here is my version information:


:ver
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Sep 23 2015 09:51:11)
MS-Windows 32-bit GUI version with OLE support
Included patches: 1-873
Compiled by me
Huge version with GUI.  Features included (+) or not (-):
+acl             +cmdline_hist    -directx         +folding         +lispindent      -mzscheme        +quickfix        +syntax          +vertsplit       -xim
+arabic          +cmdline_info    -dnd             -footer          +listcmds        +netbeans_intg   +reltime         +tag_binary      +virtualedit     -xterm_save
+autocmd         +comments        -ebcdic          +gettext/dyn     +localmap        +ole             +rightleft       +tag_old_static  +visual          +xpm_w32
+balloon_eval    +conceal         +emacs_tags      -hangul_input    -lua             +path_extra      -ruby            -tag_any_white   +visualextra
+browse          +cryptv          +eval            +iconv/dyn       +menu            +perl/dyn        +scrollbind      -tcl             +viminfo
++builtin_terms  +cscope          +ex_extra        +insert_expand   +mksession       +persistent_undo +signs           -tgetent         +vreplace
+byte_offset     +cursorbind      +extra_search    +jumplist        +modify_fname    -postscript      +smartindent     -termresponse    +wildignore
+cindent         +cursorshape     +farsi           +keymap          +mouse           +printer         -sniff           +textobjects     +wildmenu
+clientserver    +dialog_con_gui  +file_in_path    +langmap         +mouseshape      +profile         +startuptime     +title           +windows
+clipboard       +diff            +find_in_path    +libcall         +multi_byte      +python/dyn      +statusline      +toolbar         +writebackup
+cmdline_compl   +digraphs        +float           +linebreak       +multi_lang      -python3         -sun_workshop    +user_commands   -xfontset
   system vimrc file: "$VIM\vimrc"
     user vimrc file: "$HOME\_vimrc"
 2nd user vimrc file: "$HOME\vimfiles\vimrc"
 3rd user vimrc file: "$VIM\_vimrc"
      user exrc file: "$HOME\_exrc"
  2nd user exrc file: "$VIM\_exrc"
  system gvimrc file: "$VIM\gvimrc"
    user gvimrc file: "$HOME\_gvimrc"
2nd user gvimrc file: "$HOME\vimfiles\gvimrc"
3rd user gvimrc file: "$VIM\_gvimrc"
    system menu file: "$VIMRUNTIME\menu.vim"
Compilation: cl -c /W3 /nologo  -I. -Iproto -DHAVE_PATHDEF -DWIN32   -DFEAT_CSCOPE -DFEAT_NETBEANS_INTG   -DFEAT_XPM_W32   -DWINVER=0x0400 -D_WIN32_WINNT=0x0400  /Fo.\ObjGOL
Yi386/ /Ox /GL -DNDEBUG  /Zl /MT -DFEAT_OLE -DFEAT_GUI_W32 -DDYNAMIC_ICONV -DDYNAMIC_GETTEXT -DFEAT_PYTHON -DDYNAMIC_PYTHON  -DDYNAMIC_PYTHON_DLL=\"python27.dll\" -DFEAT_PER
L -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DDYNAMIC_PERL -DDYNAMIC_PERL_DLL=\"perl520.dll\" -DFEAT_HUGE /Fd.\ObjGOLYi386/ /Zi
Linking: link /RELEASE /nologo /subsystem:windows /LTCG:STATUS oldnames.lib kernel32.lib advapi32.lib shell32.lib gdi32.lib  comdlg32.lib ole32.lib uuid.lib /machine:i386 gd
i32.lib version.lib   winspool.lib comctl32.lib advapi32.lib shell32.lib  /machine:i386 /nodefaultlib libcmt.lib oleaut32.lib user32.lib      /nodefaultlib:python27.lib
WSock32.lib xpm\x86\lib\libXpm.lib /PDB:gvim.pdb -debug


TIA,
David

--
--
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: