From: Juri Linkov Date: Thu, 25 Feb 2021 18:45:40 +0000 (+0200) Subject: New variable 'use-short-answers' to use 'y-or-n-p' instead of 'yes-or-no-p' X-Git-Tag: emacs-28.0.90~3544 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=297c0e0306f111c1e7564b2bb49a7e1a925a55bb;p=emacs.git New variable 'use-short-answers' to use 'y-or-n-p' instead of 'yes-or-no-p' * lisp/cus-start.el: Add use-short-answers. * lisp/emacs-lisp/map-ynp.el (read-answer): Handle use-short-answers. (read-answer-short): Add use-short-answers to docstring. * src/fns.c (Fyes_or_no_p): Call y-or-n-p if use_short_answers is true. (syms_of_fns): Add DEFVAR_BOOL use-short-answers (bug#46594). --- diff --git a/etc/NEWS b/etc/NEWS index caa366aaef8..1ec080a6db5 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2414,6 +2414,11 @@ and display the result. When non-nil, then functions 'read-char-choice' and 'y-or-n-p' (respectively) use the function 'read-key' to read a character instead of using the minibuffer. +--- +** New variable 'use-short-answers' to use 'y-or-n-p' instead of 'yes-or-no-p'. +This relieves of the need to define an alias that maps one to another +in the init file. The same variable also affects the function 'read-answer'. + +++ ** 'set-window-configuration' now takes an optional 'dont-set-frame' parameter which, when non-nil, instructs the function not to select diff --git a/lisp/cus-start.el b/lisp/cus-start.el index c0a4a6dda06..7b05f5796a4 100644 --- a/lisp/cus-start.el +++ b/lisp/cus-start.el @@ -302,6 +302,7 @@ Leaving \"Default\" unchecked is equivalent with specifying a default of ;; fns.c (use-dialog-box menu boolean "21.1") (use-file-dialog menu boolean "22.1") + (use-short-answers menu boolean "28.1") (focus-follows-mouse frames (choice (const :tag "Off (nil)" :value nil) diff --git a/lisp/emacs-lisp/map-ynp.el b/lisp/emacs-lisp/map-ynp.el index 14112a1c147..86a0c76fd16 100644 --- a/lisp/emacs-lisp/map-ynp.el +++ b/lisp/emacs-lisp/map-ynp.el @@ -265,7 +265,8 @@ C-g to quit (cancel the whole command); "If non-nil, `read-answer' accepts single-character answers. If t, accept short (single key-press) answers to the question. If nil, require long answers. If `auto', accept short answers if -the function cell of `yes-or-no-p' is set to `y-or-n-p'." +`use-short-answers' is non-nil, or the function cell of `yes-or-no-p' +is set to `y-or-n-p'." :type '(choice (const :tag "Accept short answers" t) (const :tag "Require long answer" nil) (const :tag "Guess preference" auto)) @@ -304,7 +305,8 @@ Return a long answer even in case of accepting short ones. When `use-dialog-box' is t, pop up a dialog window to get user input." (let* ((short (if (eq read-answer-short 'auto) - (eq (symbol-function 'yes-or-no-p) 'y-or-n-p) + (or use-short-answers + (eq (symbol-function 'yes-or-no-p) 'y-or-n-p)) read-answer-short)) (answers-with-help (if (assoc "help" answers) diff --git a/src/fns.c b/src/fns.c index c16f9c63998..79b5a1e9930 100644 --- a/src/fns.c +++ b/src/fns.c @@ -2873,6 +2873,11 @@ if `last-nonmenu-event' is nil, and `use-dialog-box' is non-nil. */) return obj; } + if (use_short_answers) + { + return call1 (intern ("y-or-n-p"), prompt); + } + AUTO_STRING (yes_or_no, "(yes or no) "); prompt = CALLN (Fconcat, prompt, yes_or_no); @@ -5904,6 +5909,15 @@ that disables the use of a file dialog, regardless of the value of this variable. */); use_file_dialog = true; + DEFVAR_BOOL ("use-short-answers", use_short_answers, + doc: /* Non-nil means `yes-or-no-p' uses shorter answers "y" or "n". +It's discouraged to use single-key answers because `yes-or-no-p' is +intended to be used when it's thought that you should not respond too +quickly, so you take time and perhaps think more about the answer. +When non-nil, then `yes-or-no-p' uses `y-or-n-p' to read an answer. +The same variable also affects the function `read-answer'. */); + use_short_answers = false; + defsubr (&Sidentity); defsubr (&Srandom); defsubr (&Slength);