From 6bbd1cc5c9cd3db40dcb1ce82f478473b1f78131 Mon Sep 17 00:00:00 2001 From: Felician Nemeth Date: Thu, 17 Mar 2022 12:44:43 +0100 Subject: [PATCH] Format long help texts better in read-multiple-choice * lisp/emacs-lisp/rmc.el (rmc--show-help): Format long help texts better (bug#54430). --- lisp/emacs-lisp/rmc.el | 12 +++++++++--- test/lisp/emacs-lisp/rmc-tests.el | 24 +++++++++++++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lisp/emacs-lisp/rmc.el b/lisp/emacs-lisp/rmc.el index e635c7f200c..c450505dfd9 100644 --- a/lisp/emacs-lisp/rmc.el +++ b/lisp/emacs-lisp/rmc.el @@ -112,9 +112,15 @@ (goto-char start) (dolist (line (split-string text "\n")) (end-of-line) - (if (bolp) - (insert line "\n") - (insert line)) + (if (not (bolp)) + (insert line) + (insert (make-string + (max (- (* (mod (1- times) columns) + (+ fill-column 4)) + (current-column)) + 0) + ?\s)) + (insert line "\n")) (forward-line 1)))))))) buf)) diff --git a/test/lisp/emacs-lisp/rmc-tests.el b/test/lisp/emacs-lisp/rmc-tests.el index c1c46d6400e..ed30d82c3b8 100644 --- a/test/lisp/emacs-lisp/rmc-tests.el +++ b/test/lisp/emacs-lisp/rmc-tests.el @@ -66,5 +66,27 @@ (should (equal (list char str) (read-multiple-choice "Do it? " '((?y "yes") (?n "no")))))))) -(provide 'rmc-tests) +(ert-deftest test-read-multiple-choice-help () + (let ((chars '(?o ?a)) + help) + (cl-letf* (((symbol-function #'read-event) + (lambda () + (message "chars %S" chars) + (when (= 1 (length chars)) + (with-current-buffer "*Multiple Choice Help*" + (setq help (buffer-string)))) + (pop chars)))) + (read-multiple-choice + "Choose:" + '((?a "aaa") + (?b "bbb") + (?c "ccc" "a really long description of ccc"))) + (should (equal help "Choose: + +a: [A]aa b: [B]bb c: [C]cc + a really long + description of ccc + \n?: [?] +"))))) + ;;; rmc-tests.el ends here -- 2.39.2