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

From: Jim Porter <[email-masked]>
Date: Tue, 1 Nov 2022 15:39:29 -0700

On 11/1/2022 9:11 AM, Jim Porter wrote:
> However, I'm not sure how to do this in a complete way without tweaking 
> 'delete-frame-functions'. ...
Attached is a (hopefully) safer version of my change to 'delete-frame'. 
In this patch, a hook can only cancel frame deletion if FORCE is 
non-nil. This way, if there were ever some bug with a hook, you (or some 
code) can still force-delete the frame.

This would probably still need a NEWS entry, but I'm personally less 
worried about this change compared to my previous revision. What do you 
think?

From ea7a6ff541ccfae474f32ffa1dedd3667ede63b7 Mon Sep 17 00:00:00 2001
From: Jim Porter <[email-masked]>
Date: Tue, 1 Nov 2022 15:28:18 -0700
Subject: [PATCH] Let 'delete-frame-functions' quit out of frame deletion if
 FORCE is nil

* src/frame.c (delete_frame): When FORCE is nil, call
'delete-frame-functions' with 'call2' instead of 'safe_call2' to allow
hooks to quit out.
---
 src/frame.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/frame.c b/src/frame.c
index f076a5ba54..9722efa505 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -2037,7 +2037,11 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
       x_clipboard_manager_save_frame (frame);
 #endif
 
-      safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
+      /* If FORCE is nil, allow hooks to quit out of frame deletion.  */
+      if (NILP (force))
+	call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
+      else
+	safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
     }
 
   /* delete_frame_functions may have deleted any frame, including this
-- 
2.25.1