Tony Mechelynck wrote:

> Marius Roets wrote:
> > Hi everybody,
> > Can somebody explain the following behaviour to me. In my .vimrc I put
> > the following:
> > " ------START ----------
> > function ResizeEvent()
> >   let &lines = &lines - 1
> >   execute '!echo "resizing "'.&lines . ' >> test.txt'
> > endfunction
> > 
> > autocmd VimResized * call ResizeEvent()
> > " -------- END -----------
> > Now for every resize event, I get 4 lines in test.txt. The result is
> > that I end up with 'lines' being decreased 4 times, instead of just
> > once.
> > 
> > Thanks
> > Marius
> > 
> 
> Strange: normally autocommands don't nest, which would mean that using ":let 
> &lines = &lines - 1" (or ":set lines-=1") inside an autocommand (for 
> VimResized) shouldn't trigger VimResized again.
> 
> I confirm this strange behaviour: after sourcing a script containing
> 
> function ResizeEvent()
>       set lines-=1
>       redir >> ~/resize.log
>       silent echo "lines:" &lines
>       redir END
> endfunction
> au! VimResized * call ResizeEvent()
> 
> then invoking (once) ":call ResizeEvent()" at the gvim command-line, I get 
> the 
> following in ~/resize.log (which previously didn't exist):
> 
> <quote>
> 
> lines: 35
> lines: 34
> lines: 33
> lines: 33
> lines: 32
> </quote>

What probably happens is that the resizing, or the event triggered by
it, is noticed after the function returns.  Thus the first resize
triggers the function, 'lines' is decreased, the function returns and
then the event is triggered again.

-- 
The psychic said, "God bless you."  I said, "I didn't sneeze."  She
looked deep into my eyes and said, "You will, eventually."  And, damn
if she wasn't right.  Two days later, I sneezed.  --Ellen Degeneres

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

Reply via email to