]> git.eshelyaron.com Git - emacs.git/commitdiff
Format long help texts better in read-multiple-choice
authorFelician Nemeth <felician.nemeth@gmail.com>
Thu, 17 Mar 2022 11:44:43 +0000 (12:44 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 17 Mar 2022 11:55:39 +0000 (12:55 +0100)
* lisp/emacs-lisp/rmc.el (rmc--show-help): Format long help texts
better (bug#54430).

lisp/emacs-lisp/rmc.el
test/lisp/emacs-lisp/rmc-tests.el

index e635c7f200c2af502b3d6955bdae1d58e97f7e91..c450505dfd9b63489d78f1d9407abc3cc304c056 100644 (file)
                 (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))
 
index c1c46d6400e66be47ca863266c3cdca2b191e496..ed30d82c3b8d645e1dfa90c21071413ab5139f8c 100644 (file)
       (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