Subject: Re: bug#63655: 29.0.91; Dialog box not displayed upon closing frame

From: Eli Zaretskii <[email-masked]>
Date: Tue, 23 May 2023 16:00:17 +0300

> From: Po Lu <[email-masked]>
> Cc: [email-masked]
> Date: Tue, 23 May 2023 20:07:58 +0800
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> >>   Really exit Emacs? (y or n)
> >
> > confirm-kill-emacs, if non-nil, should be a function.  If I try what
> > you described above, Emacs signals an error when I close the last
> > frame.
> 
> Sorry, I meant to set it to `y-or-n-p'.  I did that from Custom.

Does the patch below give good results?

diff --git a/lisp/subr.el b/lisp/subr.el
index 52227b5..9aa28d9 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3544,6 +3544,8 @@ use-dialog-box-p
   "Return non-nil if the current command should prompt the user via a dialog box."
   (and last-input-event                 ; not during startup
        (or (consp last-nonmenu-event)   ; invoked by a mouse event
+           (and (null last-nonmenu-event)
+                (consp last-input-event))
            from--tty-menu-p)            ; invoked via TTY menu
        use-dialog-box))
 
diff --git a/src/fns.c b/src/fns.c
index e8cd621..e01739c 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -3193,8 +3193,11 @@ DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 1, 0,
 
   CHECK_STRING (prompt);
 
-  if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
-      && use_dialog_box && ! NILP (last_input_event))
+  if (!NILP (last_input_event)
+      && (CONSP (last_nonmenu_event)
+	  || (NILP (last_nonmenu_event) && CONSP (last_input_event))
+	  || !NILP (find_symbol_value (Qfrom__tty_menu_p)))
+      && use_dialog_box)
     {
       Lisp_Object pane, menu, obj;
       redisplay_preserve_echo_area (4);
@@ -6358,4 +6361,5 @@ syms_of_fns (void)
   defsubr (&Sbuffer_line_statistics);
 
   DEFSYM (Qreal_this_command, "real-this-command");
+  DEFSYM (Qfrom__tty_menu_p, "from--tty-menu-p");
 }