Bug? One endless :while case

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug? One endless :while case

Yue Wu
Hi list,

How to reproduce:

Create a func:

func! Ywtest()
    redraw | let txt = matchstr(input("Foo: "), '^\s*\zs.*')
    while txt == ''
        let txt = matchstr(input("Foo: "), '^\s*\zs')
    endwhile
endfunc

Run it: :call Ywtest()

Then in the first prompt, hit enter to enter a blank string, then func will
prompt again, now input some string, hit enter again, you will find the while
loop will nerver end from now on.

If I remove the matchstr() part, func runs well, what's wrong with it?

--
Regards,
Yue Wu

Key Laboratory of Modern Chinese Medicines
Department of Traditional Chinese Medicine
China Pharmaceutical University
No.24, Tongjia Xiang Street, Nanjing 210009, China

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Bug? One endless :while case

Christian Brabandt
On Fri, August 6, 2010 5:05 am, Yue Wu wrote:

> Create a func:
>
> func! Ywtest()
>     redraw | let txt = matchstr(input("Foo: "), '^\s*\zs.*')
>     while txt == ''
>         let txt = matchstr(input("Foo: "), '^\s*\zs')
>     endwhile
> endfunc
>
> Run it: :call Ywtest()
>
> Then in the first prompt, hit enter to enter a blank string, then func
> will
> prompt again, now input some string, hit enter again, you will find the
> while
> loop will nerver end from now on.
>
> If I remove the matchstr() part, func runs well, what's wrong with it?

Because your pattern always matches and since you are using \zs at the
end of your pattern, matchstr() will always return the empty string.

regards,
Christian

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Bug? One endless :while case

Yue Wu
On Fri, Aug 06, 2010 at 07:50:37AM +0200, Christian Brabandt wrote:

> On Fri, August 6, 2010 5:05 am, Yue Wu wrote:
> > Create a func:
> >
> > func! Ywtest()
> >     redraw | let txt = matchstr(input("Foo: "), '^\s*\zs.*')
> >     while txt == ''
> >         let txt = matchstr(input("Foo: "), '^\s*\zs')
> >     endwhile
> > endfunc
> >
> > Run it: :call Ywtest()
> >
> > Then in the first prompt, hit enter to enter a blank string, then func
> > will
> > prompt again, now input some string, hit enter again, you will find the
> > while
> > loop will nerver end from now on.
> >
> > If I remove the matchstr() part, func runs well, what's wrong with it?
>
> Because your pattern always matches and since you are using \zs at the
> end of your pattern, matchstr() will always return the empty string.
>

Thank you, I forgot '.*' after '\zs' ;p

--
Regards,
Yue Wu

Key Laboratory of Modern Chinese Medicines
Department of Traditional Chinese Medicine
China Pharmaceutical University
No.24, Tongjia Xiang Street, Nanjing 210009, China

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