Subject: bug#58909: 29.0.50; [WIP PATCH] Deleting the last frame of an emacsclient doesn't ask to save

From: Eli Zaretskii <[email-masked]>
Date: Wed, 02 Nov 2022 19:11:57 +0200

> Date: Wed, 2 Nov 2022 09:36:52 -0700
> Cc: [email-masked]
> From: Jim Porter <[email-masked]>
> 
> > Sorry, but I still don't like this.  We currently call this hook via
> > safe_call because we don't want to let the hook prevent the deletion
> > of the frame.
> > 
> > I prefer to solve this in server.el, not in lower-level primitives.
> 
> Hm, ok. That means I'd need to make sure 'C-x 5 0' calls something other 
> than 'delete-frame', so that I could add a prompt to it that can prevent 
> deletion of the frame.

Why?  delete-frame eventually calls a function from server.el, doesn't
it?  We've been through that already.  Why cannot you do this inside
that server.el function?

If that's because you want to support the C-g case, then don't: that
is a separate problem.  You wanted to give the user the opportunity to
save the buffers, and that doesn't require any support for C-g.
Besides, if the user types C-g when presented with the save-buffers
prompt, how do you know that the user intends to abort deletion of the
frame, and not break out of the saving operation?

And finally, even if the user does want to prevent the deletion of the
frame, and fails in doing that, how is that a catastrophe?  Emacs is
still running and the unsaved buffers are still in the session.

I really don't see why we need to jump through any hoops for such a
simple situation.

> 1. If 'delete-frame' is a lower-level primitive, should 'C-x 5 0' call 
> it directly, or should there be a higher-level function for it to call? 
> If we had some higher-level function, then user-level commands could 
> call that, but low-level code could still use 'delete-frame'. This 
> user-level command would then be able to run some hook that can prevent 
> deletion of the frame.
> 
> 2. Since server.el has a minor mode (unsurprisingly named 
> 'server-mode'), maybe one option is to do command remapping. If we remap 
> 'delete-frame' to some new 'server-delete-frame' when 'server-mode' is 
> active, then this should work. See attached for a quick sketch of how 
> this would look.
> 
> What do you think about one of these?

Waaaay too complicated for such a simple problem.  Please, let's just
prompt the user from server-delete-client (and do that under some
opt-in option), and be done with that.