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.
This commit is contained in:
Eli Zaretskii 2023-05-23 17:44:23 +03:00
parent 0abb79ca09
commit 5aadb87d6f
3 changed files with 32 additions and 21 deletions

View file

@ -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 more momentous questions, since it requires three or four characters to
answer. answer.
If either of these functions is called in a command that was invoked If either of these functions is called in a command that was
using the mouse---more precisely, if @code{last-nonmenu-event} invoked using the mouse or some other window-system gesture, or in a
(@pxref{Command Loop Info}) is either @code{nil} or a list---then it command invoked via a menu, then they use a dialog box or pop-up menu
uses a dialog box or pop-up menu to ask the question. Otherwise, it to ask the question if dialog boxes are supported. Otherwise, they
uses keyboard input. You can force use either of the mouse or of keyboard use keyboard input. You can force use either of the mouse or of
input by binding @code{last-nonmenu-event} to a suitable value around keyboard input by binding @code{last-nonmenu-event} to a suitable
the call. 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. 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 prompting. But if @var{no-cursor-in-echo-area} is non-@code{nil}, it
does not do that. does not do that.
If @code{map-y-or-n-p} is called in a command that was invoked using the If @code{map-y-or-n-p} is called in a command that was invoked using
mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command the mouse or some other window-system gesture, or a command invoked
Loop Info}) is either @code{nil} or a list---then it uses a dialog box via a menu, then it uses a dialog box or pop-up menu to ask the
or pop-up menu to ask the question. In this case, it does not use 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 keyboard input or the echo area. You can force use either of the
of keyboard input by binding @code{last-nonmenu-event} to a suitable mouse or of keyboard input by binding @code{last-nonmenu-event} to a
value around the call. 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. The return value of @code{map-y-or-n-p} is the number of objects acted on.
@end defun @end defun

View file

@ -3544,6 +3544,8 @@ confusing to some users.")
"Return non-nil if the current command should prompt the user via a dialog box." "Return non-nil if the current command should prompt the user via a dialog box."
(and last-input-event ; not during startup (and last-input-event ; not during startup
(or (consp last-nonmenu-event) ; invoked by a mouse event (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 from--tty-menu-p) ; invoked via TTY menu
use-dialog-box)) 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 responses, perform the requested window recentering or scrolling
and ask again. and ask again.
Under a windowing system a dialog box will be used if `last-nonmenu-event' If dialog boxes are supported, this function will use a dialog box
is nil and `use-dialog-box' is non-nil. 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. 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 If `y-or-n-p-use-read-key' is non-nil, `read-key' is used

View file

@ -3185,16 +3185,21 @@ has been confirmed.
If the `use-short-answers' variable is non-nil, instead of asking for If the `use-short-answers' variable is non-nil, instead of asking for
\"yes\" or \"no\", this function will ask for \"y\" or \"n\". \"yes\" or \"no\", this function will ask for \"y\" or \"n\".
If dialog boxes are supported, a dialog box will be used If dialog boxes are supported, this function will use a dialog box
if `last-nonmenu-event' is nil, and `use-dialog-box' is non-nil. */) 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 prompt)
{ {
Lisp_Object ans; Lisp_Object ans, val;
CHECK_STRING (prompt); CHECK_STRING (prompt);
if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) if (!NILP (last_input_event)
&& use_dialog_box && ! 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; Lisp_Object pane, menu, obj;
redisplay_preserve_echo_area (4); redisplay_preserve_echo_area (4);
@ -6358,4 +6363,5 @@ The same variable also affects the function `read-answer'. */);
defsubr (&Sbuffer_line_statistics); defsubr (&Sbuffer_line_statistics);
DEFSYM (Qreal_this_command, "real-this-command"); DEFSYM (Qreal_this_command, "real-this-command");
DEFSYM (Qfrom__tty_menu_p, "from--tty-menu-p");
} }