Bram Moolenaar wrote:
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.


If I add "sleep 2" at the end of the function, then try ":set lines+=5" by hand, then the Vim screen is expanded and totally blanked out, then after a wait of several seconds it is shrunk by 4 lines and redrawn. ???-( I don't see four downsizings separated by two-second waits. ('lazyredraw' is OFF.)

Where exactly is the VimResized event detected? If when entering the wait-for-key loop, then wouldn't it defeat the principle that "autocommands don't nest"? But then why always 4 times (of which 3 supposedly nested), not 1 and not 10 or 11 (sine 10 is the nesting maximum)? And why does adding a "sleep" line at the end of the function not even change the number of repeats?


Best regards,
Tony.
--
It is something to be able to paint a particular picture, or to carve a
statue, and so to make a few objects beautiful; but it is far more
glorious to carve and paint the very atmosphere and medium through
which we look, which morally we can do.  To affect the quality of the
day, that is the highest of arts.
                -- Henry David Thoreau, "Where I Live"

Reply via email to