Re: gvim when x server is shut down

2006-06-19 Thread Bram Moolenaar

Dennis Nezic wrote:

> > > when i exit my wm (e16), since it doesn't (and shouldn't) close any
> > > other programs, gvim is stuck without an x server, and doesn't
> > > handle this loss gracefully. effectively, it's as if it was kill
> > > -9'ed ... and thus leaves temporary files behind, which i later
> > > have to labouriously clean up.
> > > 
> > > can it not do something better  like simply close down if no
> > > changes were made to the file (and close any temp files). and, i
> > > guess, leave the temp files behind if changes were made (as it
> > > currently does in all cases :\).
> > 
> > Vim normally handles a shutdown of the window manager gracefully.
> > There is a protocol for this and Vim implements it.  This may result
> > in the window manager not exiting when Vim has modified files.
> > 
> > If you forcefully kill the window manager or the X server you will
> > get a hanging gvim (and possibly other programs).  That's your own
> > fault then.
> > 
> > If you shut down the window manager properly but Vim still hangs
> > somehow, perhaps the window manager doesn't work properly.  You could
> > try another one.
> 
> 
> The Rasterman seems to disagree. he responds as follows:
> 
> 
> > On Mon, 19 Jun 2006 10:53:32 +0900,
> > Carsten Haitzler (The Rasterman) <[EMAIL PROTECTED]> wrote:
> >
> > [...] there is no "shutdown protocol" for a wm - it doesn't
> > exist in x. read the icccm. there is a protocol a wm can use to
> > request an application to delete its window (and often apps will take
> > this as a hint and take their sweet time about it - sometimes pop up
> > "are you sure you want to exit?" dialogs etc.) but there is no
> > protocol to say "go shut down and cleanup ASAP and don't ask 'are you
> > sure?' etc.". if he is referring to a shutdown/save protocol in a
> > SESSION MANAGER (using libICE etc. etc.) THEN sure - there is one.
> > but not for window managers that don't pretend to be a session
> > manager too. my reply to enlightenment-users still stands. an app can
> > trap loss of x connection and still shut down gracefully (make it an
> > expedited shutdown with no "are you sure" dialogs - simply save and
> > clean up as fast as possible). e17 does just that itself as did e16.
> > they both handle loss of an x display themselves gracefully.
> > 
> > i bet you vim isn't setting its own handler for x io errors (which is
> > the handler called in this case, the default in xlib just calls exit
> > (), unless you set your own). fact is - gvim should also handle the
> > case where you ctrl+alt +backspace to kill x - and clean up, if it
> > can (which it can). the only case where gvim could not manage a
> > cleanup on shutdown is on a kill -9 as a process is killed off with
> > no choice in the matter.
> 
> he seems to have a good point. ?

How can you have a window manager without a session manager?  There must
be a session manager, otherwise the window manager can't gracefully
shutdown/logout.

Trapping X errors is very tricky, because it changes what library
functions do.  I have had lots of problems with it.  You can't simply
catch all X errors and have Vim exit, it would exit on simple errors.

Trapping the error that the X server has exited is like trapping the
error that the system crashes.  It's too late to do a graceful exit, you
can't ask the user what to do with changed text.  It will cause swap
files being left behind, thus the user will have to do crash recovery
afterwards.  It's only slightly better than "kill -9".

Vim does trap signals that makes it exit and tries to clean up properly.
I don't know what is actually happening in the situation that your X
server exists.  Doesn't Vim get a SIGHUP?  If you know what is going on
perhaps you can write a patch for this.  Be sure to test it on various
systems, not every X server works the same way, especially for these
unusual situations.

-- 
ARTHUR:A scratch?  Your arm's off!
BLACK KNIGHT:  No, it isn't.
ARTHUR:Well, what's that then?
BLACK KNIGHT:  I've had worse.
  The Quest for the Holy Grail (Monty Python)

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


Re: gvim when x server is shut down

2006-06-18 Thread Dennis Nezic
> On Sun, 18 Jun 2006 16:16:01 +0200,
> Bram Moolenaar <[EMAIL PROTECTED]> wrote:
>
> 
> Dennis Nezic wrote:
> 
> > when i exit my wm (e16), since it doesn't (and shouldn't) close any
> > other programs, gvim is stuck without an x server, and doesn't
> > handle this loss gracefully. effectively, it's as if it was kill
> > -9'ed ... and thus leaves temporary files behind, which i later
> > have to labouriously clean up.
> > 
> > can it not do something better  like simply close down if no
> > changes were made to the file (and close any temp files). and, i
> > guess, leave the temp files behind if changes were made (as it
> > currently does in all cases :\).
> 
> Vim normally handles a shutdown of the window manager gracefully.
> There is a protocol for this and Vim implements it.  This may result
> in the window manager not exiting when Vim has modified files.
> 
> If you forcefully kill the window manager or the X server you will
> get a hanging gvim (and possibly other programs).  That's your own
> fault then.
> 
> If you shut down the window manager properly but Vim still hangs
> somehow, perhaps the window manager doesn't work properly.  You could
> try another one.


The Rasterman seems to disagree. he responds as follows:


> On Mon, 19 Jun 2006 10:53:32 +0900,
> Carsten Haitzler (The Rasterman) <[EMAIL PROTECTED]> wrote:
>
> [...] there is no "shutdown protocol" for a wm - it doesn't
> exist in x. read the icccm. there is a protocol a wm can use to
> request an application to delete its window (and often apps will take
> this as a hint and take their sweet time about it - sometimes pop up
> "are you sure you want to exit?" dialogs etc.) but there is no
> protocol to say "go shut down and cleanup ASAP and don't ask 'are you
> sure?' etc.". if he is referring to a shutdown/save protocol in a
> SESSION MANAGER (using libICE etc. etc.) THEN sure - there is one.
> but not for window managers that don't pretend to be a session
> manager too. my reply to enlightenment-users still stands. an app can
> trap loss of x connection and still shut down gracefully (make it an
> expedited shutdown with no "are you sure" dialogs - simply save and
> clean up as fast as possible). e17 does just that itself as did e16.
> they both handle loss of an x display themselves gracefully.
> 
> i bet you vim isn't setting its own handler for x io errors (which is
> the handler called in this case, the default in xlib just calls exit
> (), unless you set your own). fact is - gvim should also handle the
> case where you ctrl+alt +backspace to kill x - and clean up, if it
> can (which it can). the only case where gvim could not manage a
> cleanup on shutdown is on a kill -9 as a process is killed off with
> no choice in the matter.

he seems to have a good point. ?


Re: gvim when x server is shut down

2006-06-18 Thread Bram Moolenaar

Dennis Nezic wrote:

> when i exit my wm (e16), since it doesn't (and shouldn't) close any
> other programs, gvim is stuck without an x server, and doesn't handle
> this loss gracefully. effectively, it's as if it was kill -9'ed ... and
> thus leaves temporary files behind, which i later have to labouriously
> clean up.
> 
> can it not do something better  like simply close down if no
> changes were made to the file (and close any temp files). and, i guess,
> leave the temp files behind if changes were made (as it currently does
> in all cases :\).

Vim normally handles a shutdown of the window manager gracefully.  There
is a protocol for this and Vim implements it.  This may result in the
window manager not exiting when Vim has modified files.

If you forcefully kill the window manager or the X server you will get a
hanging gvim (and possibly other programs).  That's your own fault then.

If you shut down the window manager properly but Vim still hangs
somehow, perhaps the window manager doesn't work properly.  You could
try another one.

-- 
Q: How does a UNIX Guru do Sex ?
A: unzip;strip;touch;finger;mount;fsck;more;yes;umount;sleep

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


Re: gvim when x server is shut down

2006-05-17 Thread Dennis Nezic
> On Wed, 17 May 2006 10:21:41 -0500,
> "Aaron Griffin" <[EMAIL PROTECTED]> wrote:
>
> On 5/17/06, Dennis Nezic <[EMAIL PROTECTED]> wrote:
> > > On Tue, 16 May 2006 22:28:54 -0700 (PDT),
> > > Gerald Lai <[EMAIL PROTECTED]> wrote:
> > > You could try something like
> > >
> > >   :au VimLeave * if v:dying | quitall! | endif
> >
> > actually, vim does do what i expect it to do ... even without the
> > VimLeave autocmd ... gvim doesn't :\. i wonder if there is any event
> > that might work with gvim.
> 
> VimLeave works with gvim as well.  Did you try the above suggestion?

i did, without success. it seems that gvim doesn't get a chance to even
handle that event when the x server shuts down.


Re: gvim when x server is shut down

2006-05-17 Thread A.J.Mechelynck

Dennis Nezic wrote:

On Wed, 17 May 2006 19:56:29 +0200,
"A.J.Mechelynck" <[EMAIL PROTECTED]> wrote:


[...]

Gvim needs a keyboard device and a display device. IIUC, on Unix

these are handled through X11. Now if X11 pops out, gvim suddenly
finds itself with no keyboard or display. Morality: Don't close X11
as long as there are programs which use it, unless those same
programs will be "properly" closed by the same action.



yeah .. that is the current "workaround". but it's laborious :). i
think it'd be much better if gvim could interpret lack of x as a close
signal.

  

[...]

Maybe under a different window manager it would work differently? I 
don't think I have the same problem as you do... now which wm am I 
using? I believe it's the one which comes with kde.


Or else, have you tried killing Vim with SIGTERM rather than SIGKILL? 
The former (but not the latter) can be intercepted by the user program 
as meaning "Closing time, everyone! Please start closing down cleanly!" 
(but I don't know if Vim actually intercepts it or not). (Of course, the 
"proper" way to do it is by closing Vim first, maybe with :xa to save 
everything and exit, and closing X11 afterwards.)



Best regards,
Tony.


Re: gvim when x server is shut down

2006-05-17 Thread A.J.Mechelynck

Dennis Nezic wrote:

On Tue, 16 May 2006 22:28:54 -0700 (PDT),
Gerald Lai <[EMAIL PROTECTED]> wrote:

On Wed, 17 May 2006, Dennis Nezic wrote:



when i exit my wm (e16), since it doesn't (and shouldn't) close any
other programs, gvim is stuck without an x server, and doesn't
handle this loss gracefully. effectively, it's as if it was kill
-9'ed ... and thus leaves temporary files behind, which i later
have to labouriously clean up.

can it not do something better  like simply close down if no
changes were made to the file (and close any temp files). and, i
guess, leave the temp files behind if changes were made (as it
currently does in all cases :\).
  

You could try something like

:au VimLeave * if v:dying | quitall! | endif



actually, vim does do what i expect it to do ... even without the
VimLeave autocmd ... gvim doesn't :\. i wonder if there is any event
that might work with gvim.


  
Gvim needs a keyboard device and a display device. IIUC, on Unix these 
are handled through X11. Now if X11 pops out, gvim suddenly finds itself 
with no keyboard or display. Morality: Don't close X11 as long as there 
are programs which use it, unless those same programs will be "properly" 
closed by the same action.


When you say vim behaves properly, do you mean vim running on /dev/tty 
(which doesn't use X11 at all) or vim running in an xterm or similar 
(where I/O goes through X11, but that is handled by the terminal emulator)?



Best regards,
Tony.


Re: gvim when x server is shut down

2006-05-17 Thread Aaron Griffin

On 5/17/06, Dennis Nezic <[EMAIL PROTECTED]> wrote:

> On Tue, 16 May 2006 22:28:54 -0700 (PDT),
> Gerald Lai <[EMAIL PROTECTED]> wrote:
> You could try something like
>
>   :au VimLeave * if v:dying | quitall! | endif

actually, vim does do what i expect it to do ... even without the
VimLeave autocmd ... gvim doesn't :\. i wonder if there is any event
that might work with gvim.


VimLeave works with gvim as well.  Did you try the above suggestion?


Re: gvim when x server is shut down

2006-05-17 Thread Dennis Nezic
> On Tue, 16 May 2006 22:28:54 -0700 (PDT),
> Gerald Lai <[EMAIL PROTECTED]> wrote:
>
> On Wed, 17 May 2006, Dennis Nezic wrote:
> 
> > when i exit my wm (e16), since it doesn't (and shouldn't) close any
> > other programs, gvim is stuck without an x server, and doesn't
> > handle this loss gracefully. effectively, it's as if it was kill
> > -9'ed ... and thus leaves temporary files behind, which i later
> > have to labouriously clean up.
> >
> > can it not do something better  like simply close down if no
> > changes were made to the file (and close any temp files). and, i
> > guess, leave the temp files behind if changes were made (as it
> > currently does in all cases :\).
> 
> You could try something like
> 
>   :au VimLeave * if v:dying | quitall! | endif

actually, vim does do what i expect it to do ... even without the
VimLeave autocmd ... gvim doesn't :\. i wonder if there is any event
that might work with gvim.


Re: gvim when x server is shut down

2006-05-16 Thread Gerald Lai

On Wed, 17 May 2006, Dennis Nezic wrote:


when i exit my wm (e16), since it doesn't (and shouldn't) close any
other programs, gvim is stuck without an x server, and doesn't handle
this loss gracefully. effectively, it's as if it was kill -9'ed ... and
thus leaves temporary files behind, which i later have to labouriously
clean up.

can it not do something better  like simply close down if no
changes were made to the file (and close any temp files). and, i guess,
leave the temp files behind if changes were made (as it currently does
in all cases :\).


You could try something like

:au VimLeave * if v:dying | quitall! | endif

if it helps. See ":help v:dying".

HTH.
--
Gerald


gvim when x server is shut down

2006-05-16 Thread Dennis Nezic
when i exit my wm (e16), since it doesn't (and shouldn't) close any
other programs, gvim is stuck without an x server, and doesn't handle
this loss gracefully. effectively, it's as if it was kill -9'ed ... and
thus leaves temporary files behind, which i later have to labouriously
clean up.

can it not do something better  like simply close down if no
changes were made to the file (and close any temp files). and, i guess,
leave the temp files behind if changes were made (as it currently does
in all cases :\).