Bug: Inconsistent result with searchpair()?

54 views
Skip to first unread message

David Fishburn

unread,
Sep 23, 2015, 10:11:31 AM9/23/15
to vim_use
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

Christian Brabandt

unread,
Sep 23, 2015, 12:24:57 PM9/23/15
to vim_use
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

David Fishburn

unread,
Sep 23, 2015, 2:02:47 PM9/23/15
to vim_use
On Wed, Sep 23, 2015 at 12:24 PM, Christian Brabandt <cbl...@256bit.org> wrote:

On Mi, 23 Sep 2015, David Fishburn wrote:

>
> 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-@- (
>
...
 
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?

Thanks for the response Christian.

I had run  :echo synID(line("."),col("."),1) at each position and it always comes back as 0, which is correct, there are no syntax elements on the ()s.

But given you comment, if I run:
:syntax off

I do not get the error.

:syntax on
:syntax sync fromstart

Get the error again.

If I choose a different ftplugin (:setlocal ft=javascript) I do not get the error.

Vim's SQL support allows you to set different SQL dialects using :SQLSetType, using <TAB> allows completion through the different types.

:SWhen I choose :SQLSetType plsql.vim instead of :SQLSetType sqlanywhere.vim, the problem also goes away.

I am the author the sqlanywhere.vim syntax file, so it appears I have either done something wrong, or added some additional things in this file that leads to the issue.


Not exactly sure where to start looking to find out what might be the issue here, as :echo synID(line("."),col("."),1) shows there are no syntax elements on these characters.  But I can try to binary commenting of the syntax script to see if I can narrow it down.

David





David Fishburn

unread,
Sep 23, 2015, 4:11:01 PM9/23/15
to vim_use
...
When I choose :SQLSetType plsql.vim instead of :SQLSetType sqlanywhere.vim, the problem also goes away.


 I take that back, if I use a more complex query with more ()s in it, using the runtime\syntax\plsql.vim, the same error is reported, just a little later on. So it seems that the internals for syntax elements is getting messed up some how.

I have tried this with 7.4.0 (no patches) and it suffers from the same issue).

Christian, do you think it is worth putting together a reproducible that should work with basic Vim?

Thanks,
David


Christian Brabandt

unread,
Sep 24, 2015, 1:23:06 AM9/24/15
to vim_use
Hi David!

On Mi, 23 Sep 2015, David Fishburn wrote:

> Christian, do you think it is worth putting together a reproducible
> that should work with basic Vim?

Sure, If you get a reproducible test, I'll look into it.


Best,
Christian
--
"Vollkommenheit ist die Norm des Himmels; Vollkommenes wollen,
die Norm des Menschen."
-- Goethe, Maximen und Reflektionen, Nr. 525

David Fishburn

unread,
Sep 25, 2015, 2:21:03 PM9/25/15
to vim_use
On Thu, Sep 24, 2015 at 1:22 AM, Christian Brabandt <cbl...@256bit.org> wrote:
Hi David!

On Mi, 23 Sep 2015, David Fishburn wrote:

> Christian, do you think it is worth putting together a reproducible
> that should work with basic Vim?

Sure, If you get a reproducible test, I'll look into it.


So I have narrowed things down, looking for suggestions.

syntax_searchpair_vimrc
***
set nocompatible
set selectmode=
behave xterm
syntax on
filetype indent on

***

I start Vim with:
c:\opensrc\vim\src\gvim.exe -u syntax_searchpair_vimrc -U syntax_searchpair_vimrc --noplugins +"source c:\vim\vimfiles\plugin\sqlutilities.vim" +"source c:\vim\vimfiles\autoload\sqlutilities.vim" +"source C:\Vim\test\sqlutilities\searchpair_function.vim" searchpair.sql

Visually select first 2 lines of file:

'<,'>call SQLUFormatter
 

This is where things get a little complicated.
I had it reproduced with a function (not my plugin) but then it stopped failing and I had to go back to the binary commenting out of code.
If I use the function it works, but when I use my plugin now, it fails.

It is like enough stuff has to get loaded in memory before I get the issue.

So besides my 2 files for my plugin everything else is coming from vim74\runtime.

Is this good enough for you Christian?

Thanks,
David



Christian Brabandt

unread,
Sep 26, 2015, 4:22:57 PM9/26/15
to vim_use
Hi David!

On Fr, 25 Sep 2015, David Fishburn wrote:

>
>
> On Thu, Sep 24, 2015 at 1:22 AM, Christian Brabandt <cbl...@256bit.org> wrote:
>
> Hi David!
>
> On Mi, 23 Sep 2015, David Fishburn wrote:
>
> > Christian, do you think it is worth putting together a reproducible
> > that should work with basic Vim?
>
> Sure, If you get a reproducible test, I'll look into it.
>
>
>
> So I have narrowed things down, looking for suggestions.
>
> syntax_searchpair_vimrc
> ***
> set nocompatible
> set selectmode=
> behave xterm
> syntax on
> filetype indent on
>
> ***
>
> I start Vim with:
> c:\opensrc\vim\src\gvim.exe -u syntax_searchpair_vimrc -U
> syntax_searchpair_vimrc --noplugins +"source c:\vim\vimfiles\plugin\
> sqlutilities.vim" +"source c:\vim\vimfiles\autoload\sqlutilities.vim" +"source
> C:\Vim\test\sqlutilities\searchpair_function.vim" searchpair.sql

Looks like sqlutilities.vim is not distributed with vim:
#v+
chrisbra@debian ~/code/vim/runtime (hg)-[default]- % find . -type f
-name "*.vim" |grep sql
./ftplugin/sql.vim
./syntax/sqlhana.vim
./syntax/sqlforms.vim
./syntax/plsql.vim
./syntax/sqlj.vim
./syntax/mysql.vim
./syntax/sqlanywhere.vim
./syntax/sql.vim
./syntax/sqloracle.vim
./syntax/esqlc.vim
./syntax/msql.vim
./syntax/sqlinformix.vim
./indent/sqlanywhere.vim
./indent/sql.vim
./autoload/sqlcomplete.vim
0 12592 chrisbra@debian ~/code/vim/runtime (hg)-[default]- %
#v-

So can you please provide the sqlutitilities.vim plugin and
searchpair_function.vim and searchpair.sql files.

Mit freundlichen Grüßen
Christian
--
In der Liebe wird der Ernst der Jungfrau bezaubern; in der Ehe, die
selber ein langer Ernst ist, möchte leichtes Scherzen und Bescherzen
der Welt besser einschlagen.
-- Jean Paul
Reply all
Reply to author
Forward
0 new messages