Xavier de Gaye wrote:
> On 02/20/2015 12:29 PM, Xavier de Gaye wrote:
> > Run the following script named nwindows.vim and call Nwindows() with an
> argument of 0 or 1:
> > gvim -u NONE -S nwindows.vim
> > :call Nwindows(1) ---> BufWinLeave events (there should be no
> BufWinLeave event): 1
> > :call Nwindows(0) ---> BufWinLeave events (there should be no
> BufWinLeave event): 0
> >
> > The following patch fixes the problem by not ignoring the result of the
> actions of EVENT_BUFNEW and EVENT_BUFADD autocommands in buflist_new() when
> called by do_ecmd().
> > This patch may have side effects, but may be useful in describing what is
> causing the problem.
> > The comment "/* buf->b_nwindows = 0; why was this here? */" in buffer.c is
> very old ('hg blame' says before 2004).
> >
> > ============== nwindows.vim ==============
> > " Split the window in the BufAdd event when 'autocmd_split' is true.
> > function Nwindows(autocmd_split)
> > augroup nwindows
> > " Count the number of BufWinLeave events.
> > autocmd BufWinLeave foobar let g:nwindows = g:nwindows + 1
> > if a:autocmd_split
> > autocmd BufAdd foobar wincmd s
> > endif
> > augroup END
> >
> > let g:nwindows = 0
> > edit foobar
> > if ! a:autocmd_split
> > wincmd s
> > endif
> > edit foo
> > echo "BufWinLeave events (there should be no BufWinLeave event): " .
> g:nwindows
> > call input("Press the <Enter> key to continue.")
> > qa
> > endfunction
> >
> > ============== patch ==============
> > diff --git a/src/buffer.c b/src/buffer.c
> > --- a/src/buffer.c
> > +++ b/src/buffer.c
> > @@ -1794,7 +1794,7 @@
> > if (aborting()) /* autocmds may abort script processing */
> > return NULL;
> > #endif
> > - /* buf->b_nwindows = 0; why was this here? */
> > + buf->b_nwindows = 0;
> > free_buffer_stuff(buf, FALSE); /* delete local variables et al.
> */
> >
> > /* Init the options. */
> > diff --git a/src/ex_cmds.c b/src/ex_cmds.c
> > --- a/src/ex_cmds.c
> > +++ b/src/ex_cmds.c
> > @@ -3373,10 +3373,7 @@
> > if (buf == NULL)
> > goto theend;
> > if (buf->b_ml.ml_mfp == NULL) /* no memfile yet */
> > - {
> > oldbuf = FALSE;
> > - buf->b_nwindows = 0;
> > - }
> > else /* existing memfile */
> > {
> > oldbuf = TRUE;
> >
> > ==========================================
>
>
> The problem is that Vim ignores the fact that an autocommand applied by a
> BufAdd event may create/use more than one window for this buffer.
It looks like your solution fails if you split twice in BufAdd. The
buf->b_nwindows counter should not be reset to zero, because we lose
information. Instead, we can leave out incrementing it when buf ==
curbuf.
--
The software said it requires Windows 95 or better, so I installed Linux.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.