emacs-super-duper-yes-or-no

Replace the yes-or-no function with an even more demanding yes or no prompt, rather than with y-or-n.
Log | Files | Refs | LICENSE

commit 0d8b512eecd214b0e3cf2bd719b9df723f2c77d5
parent 89cfe2c41dcadd8bfa4c2aae35f9631e6b3dd097
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date:   Sun,  8 Oct 2023 00:22:55 +0300

Ask for an hard input only for the affermative by default.

Customize with super-duper-yes-or-no-two-prongs if you want a hard input for both affermative and negative.

Diffstat:
Msuper-duper-yes-or-no.el | 104+++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 64 insertions(+), 40 deletions(-)

diff --git a/super-duper-yes-or-no.el b/super-duper-yes-or-no.el @@ -86,7 +86,7 @@ This number is used in `sd-yes-or-no-toggle-case-p'." :type 'integer :group 'super-duper-yes-or-no) -(defcustom sd--arithmetic-problem-template +(defcustom sd-arithmetic-problem-template '(+ (* 0 0) (* 0 0)) "Template used to create arithmetic problems. @@ -98,6 +98,11 @@ stay unchanged." :type 'list :group 'super-duper-yes-or-no) +(defcustom sd-two-prongs nil + "If t, ask for two hard to enter inputs, otherwise ask only for the affermative." + :type 'bool + :group 'super-duper-yes-or-no) + (defun sd--randint (minimum maximum) "Return an integer between MINIMUM (inclusive) and MAXIMUM (exclusive)." @@ -108,7 +113,7 @@ stay unchanged." (defun sd--make-random-input-string (wanted-number-of-words) "Make a list of words, WANTED-NUMBER-OF-WORDS long. -Used in the `super-duper-yes-or-no-yes-or-no-words-p' function." +Used in the `sd-yes-or-no-words-p' function." (cl-loop with wordlist-size = (seq-length sd-words) @@ -168,8 +173,11 @@ Examples: (defun sd-yes-or-no-words-p (prompt) "Ask user a yes or no question. -Display in minibuffer PROMPT followed by two sequences of words, -one for yes and the other for no." +Display in minibuffer PROMPT followed by a sequence of words the +user must enter to choose yes. + +If the variable `sd-two-prongs' is t, ask two sequences, one for +the affermative and one for the negative." (cl-loop for wanted-yes-or-no = (super-duper-yes-or-no--make-random-yes-or-no-input-pair @@ -179,7 +187,9 @@ one for yes and the other for no." (car wanted-yes-or-no) for wanted-no = - (cadr wanted-yes-or-no) + (if sd-two-prongs + (cadr wanted-yes-or-no) + (list "no")) for wanted-yes-string = (apply 'concat @@ -296,11 +306,13 @@ the toggle count AND they are not toggled." (defun sd-yes-or-no-toggle-case-p (prompt) "Ask user a yes or no question, but expect the uppercase letters. -Display in minibuffer PROMPT followed by two lines, one for yes -and the other for no. Each of those two lines have a sequence of -uppercase letters sprinkled inside. If you want to answer yes, -write in sequence the uppercase letters of the first line, -otherwise, the uppercase letters of the second." +Display in minibuffer PROMPT followed by a string with some of +its letters' case flipped. Enter the uppercase letters found in +sequence for the affermative and \"no\" for the negative. + +If `sd-two-prongs' is t, provides the user with two of such +strings. Enter the second one's uppercase letters for the +negative." (cl-loop for wanted-yes-prompt = (sd--randomly-toggle-string-case @@ -308,17 +320,21 @@ otherwise, the uppercase letters of the second." sd-number-of-case-toggle-characters) for wanted-no-prompt = - (sd--randomly-toggle-string-case - sd-upper-case-phrase-for-no - sd-number-of-case-toggle-characters) + (if sd-two-prongs + (sd--randomly-toggle-string-case + sd-upper-case-phrase-for-no + sd-number-of-case-toggle-characters) + "(Enter \"no\" for no)") for wanted-input-yes = (sd--string-only-uppercase wanted-yes-prompt) for wanted-input-no = - (sd--string-only-uppercase - wanted-no-prompt) + (if sd-two-prongs + (sd--string-only-uppercase + wanted-no-prompt) + "no") while (equal wanted-input-yes @@ -374,50 +390,58 @@ otherwise, the uppercase letters of the second." (defun sd-yes-or-no-arithmetic-problem-p (prompt) "Ask user a yes or no question, but as an answer to an arithmetic expression. -Display in minibuffer PROMPT followed by two arithmetic -expressions, one for yes and the other for no. If you want to -answer yes, write the number that is the answer to the first -problem, otherwise, the answer to the second problem." +Display in minibuffer PROMPT followed by an arithmetic +expression. Enter the answer to the expression for affermitive +and \"no\" for the negative. + +If `sd-two-prongs' us t, two arithmetic expressions appear, +enter the second's result for the negative." (cl-loop for wanted-yes-prompt = (sd--make-arithmetic-problem - sd--arithmetic-problem-template) + sd-arithmetic-problem-template) for wanted-no-prompt = - (sd--make-arithmetic-problem - sd--arithmetic-problem-template) + (if sd-two-prongs + (sd--make-arithmetic-problem + sd-arithmetic-problem-template) + "no") for wanted-input-yes = - (eval wanted-yes-prompt) + (number-to-string (eval wanted-yes-prompt)) for wanted-input-no = - (eval wanted-no-prompt) + (if sd-two-prongs + (number-to-string (eval wanted-no-prompt)) + "no") while - (= wanted-input-yes - wanted-input-no) + (equal wanted-input-yes + wanted-input-no) finally return (cl-loop for user-input = - (string-to-number - (read-from-minibuffer - (concat prompt - "Please answer " - (format "%S" wanted-yes-prompt) - " for \"yes\" and " - (format "%S" wanted-no-prompt) - " for \"no\": "))) + + (read-from-minibuffer + (concat prompt + "Please answer " + (format "%S" wanted-yes-prompt) + " for \"yes\" and " + (format "%S" wanted-no-prompt) + " for \"no\": " + (format "%s" (list wanted-input-yes + wanted-input-no)))) until - (or (= user-input - wanted-input-yes) - (= user-input - wanted-input-no)) + (or (equal user-input + wanted-input-yes) + (equal user-input + wanted-input-no)) finally return - (= user-input - wanted-input-yes)))) + (equal user-input + wanted-input-yes)))) (provide 'super-duper-yes-or-no)