Saturday, October 29, 2022

Re: How to autosave files when terminal is closed

> On Sat, 29 Oct 2022 00:03:17 +0100, Bram Moolenaar wrote:
> >
> > > On Fri, 28 Oct 2022 22:23:31 +0100, Bram Moolenaar wrote:
> > > >
> > > > > "au VimLeavePre * w" only works when I exit vim with something
> > > > > like ":q!" but not if I close my terminal window.
> > > > >
> > > > > Error detected while processing VimLeavePre Autocommands for
> > > > > "*": E749: Empty buffer
> > > > >
> > > > > VimLeave[Pre] is being called, but the buffer is not saved,
> > > > > probably because it's closed before that event is triggered. Is
> > > > > there another event that gets triggered during the closing
> > > > > sequence that will allow me to autosave, or another way to do
> > > > > this?
> > > >
> > > > Do you already have the 'autowriteall' option set?
> > >
> > > I think that only affects closing via :quit and the like. Closing my
> > > xterm apparently doesn't follow that same exit pathway.
> >
> > It is supposed to, but perhaps the catching of signals is not properly
> > setup. Not sure how to try it out other than closing the xterm
> > normally. If you "kill -9" the xterm it might not work. Closing the
> > window manager should also work OK. At least this mechanism is used
> > to avoid leaving swap files laying around, and that works quite well,
> > thus 'autowriteall' should also work. But I don't think there is a
> > test for it.
>
> Yea, I guess signal catching isn't properly setup. It seems that my wm
> is sending vim a SIGHUP when it closes the xterm window:
>
> Vim: Caught deadly signal HUP
> Vim: preserving files...
> Vim: Finished.
>
> Manually killing vim with "kill (-1|-3|-15)" does not trigger that nice
> autowriteall (awa) feature, even though vim's output says "preserving
> files..."

I suppose TERM and HUP are handled differently. But that is logical,
I'm not sure we should handle them the same way. 'autowriteall' is
boolean, not sure what would be a good way to make another choice of how
to handle TERM. Well, maybe we can just change it, for most users they
will do the same thing anyway, just come from different causes (that you
don't have control over).

--
FIRST VILLAGER: We have found a witch. May we burn her?
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

--
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20221029120439.0053B1C0739%40moolenaar.net.

No comments:

Post a Comment