Wednesday, October 30, 2013

Re: Why is this VimLeave autocommand causing 'E749: empty buffer' ?

On Mi, 30 Okt 2013, Gary Johnson wrote:

> On 2013-10-30, Thiago de Arruda wrote:
> > I'm trying to setup vim to save all files when it receives
> > SIGTERM, here's the relevant vim command:
> >
> > au VimLeave * if v:dying | wa | endif
> >
> > This should write all buffers when vim exits. From another
> > terminal if I kill vim with a modified buffer I get the following
> > error:
> >
> > Vim: Caught deadly signal TERM
> > Vim: preserving files...
> > Error detected while processing VimLeave Auto commands for "*":Vim: Finished.
> >
> > E749: empty buffer
> >
> > If I kill vim without modifying any buffers it doesn't report any
> > error.
> >
> > Does anyone knows why this is happening or how to fix it(or
> > another workaround for my problem: saving all files when vim
> > receives SIGTERM)
>
> I don't know the answer. My guess is that Vim has in some sense
> deleted all its buffers by the time it processes the VimLeave event
> so that there are no buffers to write. If you haven't modified any
> buffers, Vim does not attempt to write any, so you don't encounter
> the error.

correct.
> ":help E749" is extremely unhelpful. I learned a little by
> searching the source code for "E749" and then for the variable that
> contains that string, e_emptybuf.
>
> The text around ":help VimLeave" suggests that VimLeavePre might
> work better for this.

No it won't. Vim calls deathtrap() function, which closes all buffers,
and then calls getout(), in which all autocommands are processed
(BufWinLeave, BufUnLoad, VimLeavePre and finally VimLeave). But by that
time, you can't safe any buffers anymore.

By the time, Vim handles the deadly signal, it won't call unsafe
functions anymore (e.g. allocate memory) so I doubt it will be possible
to achieve what you want.

Best,
Christian
--
> Betriebssystem ... : MS-DOS
Falsche Angabe. Hier dürfen nur Betriebsysteme eingetragen werden.
-- Nora E. Etukudo

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: