emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 26ef5c09e0a: Add `yes-or-no-prompt' user option


From: Robert Pluim
Subject: master 26ef5c09e0a: Add `yes-or-no-prompt' user option
Date: Mon, 23 Jan 2023 03:17:58 -0500 (EST)

branch: master
commit 26ef5c09e0a0b13c02e34d858f32c09b42d26dff
Author: Robert Pluim <rpluim@gmail.com>
Commit: Robert Pluim <rpluim@gmail.com>

    Add `yes-or-no-prompt' user option
    
    This implements Bug#60312
    
    * src/fns.c (syms_of_fns): Define `yes-or-no-prompt' Lisp variable.
    (Fyes_or_no_p): Use `yes-or-no-prompt' instead of a hard-coded string.
    * lisp/cus-start.el (standard): Add custom specification for it.
    
    * doc/emacs/mini.texi (Yes or No Prompts): Document `yes-or-no-prompt'
    * doc/lispref/minibuf.texi (Yes-or-No Queries): And here.
    
    * etc/NEWS: Announce the new option.
---
 doc/emacs/mini.texi      | 10 ++++++----
 doc/lispref/minibuf.texi | 10 ++++++----
 etc/NEWS                 |  6 ++++++
 lisp/cus-start.el        |  1 +
 src/fns.c                | 16 +++++++++++-----
 5 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/doc/emacs/mini.texi b/doc/emacs/mini.texi
index 6fb312ec321..898d9e904f6 100644
--- a/doc/emacs/mini.texi
+++ b/doc/emacs/mini.texi
@@ -953,12 +953,14 @@ File ‘foo.el’ exists; overwrite? (y or n)
 @end smallexample
 
 @cindex yes or no prompt
+@vindex yes-or-no-prompt
   The second type of yes-or-no query is typically employed if giving
 the wrong answer would have serious consequences; it thus features a
-longer prompt ending with @samp{(yes or no)}.  For example, if you
-invoke @kbd{C-x k} (@code{kill-buffer}) on a file-visiting buffer with
-unsaved changes, Emacs activates the minibuffer with a prompt like
-this:
+longer prompt ending with @samp{(yes or no)} (or the value of
+@code{yes-or-no-prompt} if you've customized that).  For example, if
+you invoke @kbd{C-x k} (@code{kill-buffer}) on a file-visiting buffer
+with unsaved changes, Emacs activates the minibuffer with a prompt
+like this:
 
 @smallexample
 Buffer foo.el modified; kill anyway? (yes or no)
diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi
index 114e5d38a80..4b957a68401 100644
--- a/doc/lispref/minibuf.texi
+++ b/doc/lispref/minibuf.texi
@@ -2233,10 +2233,12 @@ minibuffer.  It returns @code{t} if the user enters 
@samp{yes},
 @code{nil} if the user types @samp{no}.  The user must type @key{RET} to
 finalize the response.  Upper and lower case are equivalent.
 
-@code{yes-or-no-p} starts by displaying @var{prompt} in the minibuffer,
-followed by @w{@samp{(yes or no) }}.  The user must type one of the
-expected responses; otherwise, the function responds @samp{Please answer
-yes or no.}, waits about two seconds and repeats the request.
+@vindex yes-or-no-prompt
+@code{yes-or-no-p} starts by displaying @var{prompt} in the
+minibuffer, followed by the value of @code{yes-or-no-prompt} @w{(default
+@samp{(yes or no) })}.  The user must type one of the expected
+responses; otherwise, the function responds @w{@samp{Please answer yes or
+no.}}, waits about two seconds and repeats the request.
 
 @code{yes-or-no-p} requires more work from the user than
 @code{y-or-n-p} and is appropriate for more crucial decisions.
diff --git a/etc/NEWS b/etc/NEWS
index 10e91ec4ab9..5b8ab06086c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -50,6 +50,12 @@ as it has in batch mode since Emacs 24.
 When non-nil, this option suppresses moving remote files to the local
 trash when deleting.  Default is nil.
 
++++
+** New user option 'yes-or-no-prompt'.
+This allows the user to customize the prompt that is appended by
+'yes-or-no-p' when asking questions.  The default value is
+"(yes or no) ".
+
 
 * Editing Changes in Emacs 30.1
 
diff --git a/lisp/cus-start.el b/lisp/cus-start.el
index 054683d7cf6..6ca7d7fcafd 100644
--- a/lisp/cus-start.el
+++ b/lisp/cus-start.el
@@ -310,6 +310,7 @@ Leaving \"Default\" unchecked is equivalent with specifying 
a default of
                       (const :tag "Off" :value nil)
                       (const :tag "On" :value t)
                       (const :tag "Auto-raise" :value auto-raise)) "26.1")
+             (yes-or-no-prompt menu string "30.1")
             ;; fontset.c
             ;; FIXME nil is the initial value, fontset.el setqs it.
             (vertical-centering-font-regexp display
diff --git a/src/fns.c b/src/fns.c
index d8bd7d318b0..59d5b5c0850 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -3182,13 +3182,14 @@ DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 1, 
0,
 Return t if answer is yes, and nil if the answer is no.
 
 PROMPT is the string to display to ask the question; `yes-or-no-p'
-adds \"(yes or no) \" to it.
+appends `yes-or-no-prompt' (default \"(yes or no) \") to it.
 
 The user must confirm the answer with RET, and can edit it until it
 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\".
+\"yes\" or \"no\", this function will ask for \"y\" or \"n\" (and
+ignore the value of `yes-or-no-prompt').
 
 If dialog boxes are supported, a dialog box will be used
 if `last-nonmenu-event' is nil, and `use-dialog-box' is non-nil.  */)
@@ -3213,8 +3214,7 @@ if `last-nonmenu-event' is nil, and `use-dialog-box' is 
non-nil.  */)
   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);
+  prompt = CALLN (Fconcat, prompt, Vyes_or_no_prompt);
 
   specpdl_ref count = SPECPDL_INDEX ();
   specbind (Qenable_recursive_minibuffers, Qt);
@@ -6265,9 +6265,15 @@ When non-nil, `yes-or-no-p' will use `y-or-n-p' to read 
the answer.
 We recommend against setting this variable non-nil, because `yes-or-no-p'
 is intended to be used when users are expected not to respond too
 quickly, but to take their time and perhaps think about the answer.
-The same variable also affects the function `read-answer'.  */);
+The same variable also affects the function `read-answer'.  See also
+`yes-or-no-prompt'.  */);
   use_short_answers = false;
 
+  DEFVAR_LISP ("yes-or-no-prompt", Vyes_or_no_prompt,
+    doc: /* String to append when `yes-or-no-p' asks a question.
+For best results this should end in a space.  */);
+  Vyes_or_no_prompt = make_unibyte_string ("(yes or no) ", strlen ("(yes or 
no) "));
+
   defsubr (&Sidentity);
   defsubr (&Srandom);
   defsubr (&Slength);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]