From: Eli Zaretskii Date: Tue, 23 May 2023 14:44:23 +0000 (+0300) Subject: Fix 'use-dialog-box-p' and friends X-Git-Tag: emacs-29.0.92~107 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5aadb87d6f6;p=emacs.git Fix 'use-dialog-box-p' and friends * lisp/subr.el (use-dialog-box-p): Use dialog boxes also when invoked from some window-system gesture. (Bug#63655) (y-or-n-p): Fix the description in the doc string of conditions under which a dialog box will be used. * src/fns.c (Fyes_or_no_p): Use the same condition for dialog boxes as in 'use-dialog-box-p'. Fix the description in the doc string of conditions under which a dialog box will be used. * doc/lispref/minibuf.texi (Multiple Queries, Yes-or-No Queries): Fix the description of conditions under which a dialog box will be used. --- diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index a4916ecda30..9a386ff310d 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi @@ -2174,13 +2174,14 @@ will not have serious consequences. @code{yes-or-no-p} is suitable for more momentous questions, since it requires three or four characters to answer. - If either of these functions is called in a command that was invoked -using the mouse---more precisely, if @code{last-nonmenu-event} -(@pxref{Command Loop Info}) is either @code{nil} or a list---then it -uses a dialog box or pop-up menu to ask the question. Otherwise, it -uses keyboard input. You can force use either of the mouse or of keyboard -input by binding @code{last-nonmenu-event} to a suitable value around -the call. + If either of these functions is called in a command that was +invoked using the mouse or some other window-system gesture, or in a +command invoked via a menu, then they use a dialog box or pop-up menu +to ask the question if dialog boxes are supported. Otherwise, they +use keyboard input. You can force use either of the mouse or of +keyboard input by binding @code{last-nonmenu-event} to a suitable +value around the call---bind it to @code{t} to force keyboard +interaction, and to a list to force dialog boxes. Both @code{yes-or-no-p} and @code{y-or-n-p} use the minibuffer. @@ -2378,13 +2379,14 @@ Normally, @code{map-y-or-n-p} binds @code{cursor-in-echo-area} while prompting. But if @var{no-cursor-in-echo-area} is non-@code{nil}, it does not do that. -If @code{map-y-or-n-p} is called in a command that was invoked using the -mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command -Loop Info}) is either @code{nil} or a list---then it uses a dialog box -or pop-up menu to ask the question. In this case, it does not use -keyboard input or the echo area. You can force use either of the mouse or -of keyboard input by binding @code{last-nonmenu-event} to a suitable -value around the call. +If @code{map-y-or-n-p} is called in a command that was invoked using +the mouse or some other window-system gesture, or a command invoked +via a menu, then it uses a dialog box or pop-up menu to ask the +question if dialog boxes are supported. In this case, it does not use +keyboard input or the echo area. You can force use either of the +mouse or of keyboard input by binding @code{last-nonmenu-event} to a +suitable value around the call---bind it to @code{t} to force keyboard +interaction, and to a list to force dialog boxes. The return value of @code{map-y-or-n-p} is the number of objects acted on. @end defun diff --git a/lisp/subr.el b/lisp/subr.el index 52227b5261c..950902039b1 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3544,6 +3544,8 @@ confusing to some users.") "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)) @@ -3574,8 +3576,9 @@ If the user enters `recenter', `scroll-up', or `scroll-down' responses, perform the requested window recentering or scrolling and ask again. -Under a windowing system a dialog box will be used if `last-nonmenu-event' -is nil and `use-dialog-box' is non-nil. +If dialog boxes are supported, this function will use a dialog box +if `use-dialog-box' is non-nil and the last input event was produced +by a mouse, or by some window-system gesture, or via a menu. By default, this function uses the minibuffer to read the key. If `y-or-n-p-use-read-key' is non-nil, `read-key' is used diff --git a/src/fns.c b/src/fns.c index e8cd6211d6d..2ed62d6e8c6 100644 --- a/src/fns.c +++ b/src/fns.c @@ -3185,16 +3185,21 @@ has been confirmed. If the `use-short-answers' variable is non-nil, instead of asking for \"yes\" or \"no\", this function will ask for \"y\" or \"n\". -If dialog boxes are supported, a dialog box will be used -if `last-nonmenu-event' is nil, and `use-dialog-box' is non-nil. */) +If dialog boxes are supported, this function will use a dialog box +if `use-dialog-box' is non-nil and the last input event was produced +by a mouse, or by some window-system gesture, or via a menu. */) (Lisp_Object prompt) { - Lisp_Object ans; + Lisp_Object ans, val; 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)) + || (val = find_symbol_value (Qfrom__tty_menu_p), + (!NILP (val) && !EQ (val, Qunbound)))) + && use_dialog_box) { Lisp_Object pane, menu, obj; redisplay_preserve_echo_area (4); @@ -6358,4 +6363,5 @@ The same variable also affects the function `read-answer'. */); defsubr (&Sbuffer_line_statistics); DEFSYM (Qreal_this_command, "real-this-command"); + DEFSYM (Qfrom__tty_menu_p, "from--tty-menu-p"); }