diff options
| author | Lars Ingebrigtsen <larsi@gnus.org> | 2022-06-24 11:00:06 +0200 | 
|---|---|---|
| committer | Lars Ingebrigtsen <larsi@gnus.org> | 2022-06-24 11:04:51 +0200 | 
| commit | bed9fd41efc72526a7fddcbe73c2ad9a97495356 (patch) | |
| tree | b31e98db1b149a5096f7ce371b53ccbf37d852b8 /lisp/emacs-lisp | |
| parent | 49910adf872a98d9c144d34478a53ecb3e01856f (diff) | |
| download | emacs-bed9fd41efc72526a7fddcbe73c2ad9a97495356.tar.gz | |
Allow read-multiple-choice to do long-form answers
* doc/lispref/commands.texi (Reading One Event): Document it.
* lisp/emacs-lisp/rmc.el (read-multiple-choice): Allow using
long-form answers instead of single character ones.
(read-multiple-choice--long-answers): New function.
(read-multiple-choice--short-answers): Refactored out from the
main function.
Diffstat (limited to 'lisp/emacs-lisp')
| -rw-r--r-- | lisp/emacs-lisp/rmc.el | 25 | 
1 files changed, 22 insertions, 3 deletions
| diff --git a/lisp/emacs-lisp/rmc.el b/lisp/emacs-lisp/rmc.el index 195035e6be9..dae6590b9bc 100644 --- a/lisp/emacs-lisp/rmc.el +++ b/lisp/emacs-lisp/rmc.el @@ -23,8 +23,6 @@  ;;; Code: -(require 'seq) -  (defun rmc--add-key-description (elem)    (let* ((char (car elem))           (name (cadr elem)) @@ -125,7 +123,8 @@      buf))  ;;;###autoload -(defun read-multiple-choice (prompt choices &optional help-string show-help) +(defun read-multiple-choice (prompt choices &optional help-string show-help +                                    long-form)    "Ask user to select an entry from CHOICES, promting with PROMPT.  This function allows to ask the user a multiple-choice question. @@ -163,12 +162,21 @@ dialogs.  Otherwise, the function will always use text-mode dialogs.  The return value is the matching entry from the CHOICES list. +If LONG-FORM, do a `completing-read' over the NAME elements in +CHOICES instead. +  Usage example:  \(read-multiple-choice \"Continue connecting?\"                        \\='((?a \"always\")                          (?s \"session only\")                          (?n \"no\")))" +  (if long-form +      (read-multiple-choice--long-answers prompt choices) +    (read-multiple-choice--short-answers +     prompt choices help-string show-help))) + +(defun read-multiple-choice--short-answers (prompt choices help-string show-help)    (let* ((prompt-choices            (if show-help choices (append choices '((?? "?")))))           (altered-names (mapcar #'rmc--add-key-description prompt-choices)) @@ -244,6 +252,17 @@ Usage example:        (kill-buffer buf))      (assq tchar choices))) +(defun read-multiple-choice--long-answers (prompt choices) +  (let ((answer +         (completing-read +          (concat prompt " (" +                  (mapconcat #'identity (mapcar #'cadr choices) "/") +                  ") ") +          (mapcar #'cadr choices) nil t))) +    (seq-find (lambda (elem) +                (equal (cadr elem) answer)) +              choices))) +  (provide 'rmc)  ;;; rmc.el ends here | 
