branch: externals/compat commit 7321d20be7a4ac2f214f149419314c075c239ec8 Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
compat-29: Add read-multiple-choice with LONG-FORM argument --- NEWS.org | 1 + compat-29.el | 19 +++++++++++++++++++ compat-tests.el | 11 ++++------- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/NEWS.org b/NEWS.org index 4b3ef8fb8b..ee51da768f 100644 --- a/NEWS.org +++ b/NEWS.org @@ -25,6 +25,7 @@ - compat-29: Add ~use-region-beginning~, ~use-region-end~ and ~use-region-noncontiguous-p~. - compat-29: Add ~get-scratch-buffer-create~. - compat-29: Add ~substitute-quotes~. +- compat-29: Add ~read-multiple-choice~ with LONG-FORM argument. * Release of "Compat" Version 29.1.2.0 diff --git a/compat-29.el b/compat-29.el index 5d441a93e1..df39dc6214 100644 --- a/compat-29.el +++ b/compat-29.el @@ -1183,5 +1183,24 @@ Also see `buttonize'." ;; Obsolete Alias since 29 (compat-defalias button-buttonize buttonize :obsolete t) ;; <compat-tests:button-buttonize> +;;;; Defined in rmc.el + +(compat-defun read-multiple-choice ;; <compat-tests:read-multiple-choice> + (prompt choices &optional _help-str _show-help long-form) + "Handle LONG-FORM argument." + :explicit t + (if (not long-form) + (read-multiple-choice prompt choices) + (let ((answer + (completing-read + (concat prompt " (" + (mapconcat #'identity (mapcar #'cadr choices) "/") + ") ") + (mapcar #'cadr choices) nil t))) + (catch 'found + (dolist (c choices) + (when (equal answer (cadr c)) + (throw 'found c))))))) + (provide 'compat-29) ;;; compat-29.el ends here diff --git a/compat-tests.el b/compat-tests.el index 92ea3f86e2..7aad543243 100644 --- a/compat-tests.el +++ b/compat-tests.el @@ -328,8 +328,7 @@ (ert-deftest read-multiple-choice () (let ((orig-re (symbol-function #'read-event)) (orig-rc (symbol-function #'read-char)) - ;;(orig-cr completing-read-function) - ) + (orig-cr completing-read-function)) (unwind-protect (dolist (test '(("Choose" (?a "first" "first description") @@ -339,14 +338,12 @@ (dolist (choice (cdr test)) (fset #'read-char (lambda (&rest _) (car choice))) (fset #'read-event (lambda (&rest _) (car choice))) - ;; TODO long form support - ;;(setq completing-read-function (lambda (&rest _) (cadr choice))) - ;;(should-equal choice (read-multiple-choice (car test) (cdr test) nil nil 'long)) + (setq completing-read-function (lambda (&rest _) (cadr choice))) + (should-equal choice (compat-call read-multiple-choice (car test) (cdr test) nil nil 'long)) (should-equal choice (read-multiple-choice (car test) (cdr test))))) (fset #'read-event orig-re) (fset #'read-char orig-rc) - ;;(setq completing-read-function orig-cr) - ))) + (setq completing-read-function orig-cr)))) (ert-deftest with-environment-variables () (let ((A "COMPAT_TESTS__VAR") (B "/foo/bar"))