From e5646f7903cdc616c978988fce9609771d1e231b Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Thu, 19 Jun 2025 09:40:36 +0300 Subject: [PATCH] Fix repeat-echo-message-string for keys with hints (bug#78797). * lisp/repeat.el (repeat-echo-message-string): For one character use it to format hints. For multi-key sequence first print it, then use the last character to format hints in parenthesis. * test/lisp/repeat-tests.el (repeat-tests-another-repeat-map): Add hints. (repeat-tests-hints): Add test. --- lisp/repeat.el | 11 +++++++++-- test/lisp/repeat-tests.el | 21 ++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lisp/repeat.el b/lisp/repeat.el index 9308f972a91..93c4a397335 100644 --- a/lisp/repeat.el +++ b/lisp/repeat.el @@ -586,9 +586,16 @@ This function can be used to force exit of repetition while it's active." (let ((key (car key-cmd)) (cmd (cdr key-cmd))) (if-let* ((hint (and (symbolp cmd) - (get cmd 'repeat-hint)))) + (get cmd 'repeat-hint))) + (last (aref key (1- (length key))))) ;; Reuse `read-multiple-choice' formatting. - (cdr (rmc--add-key-description (list key hint))) + (if (= (length key) 1) + (cdr (rmc--add-key-description (list last hint))) + (format "%s (%s)" + (propertize (key-description key) + 'face 'read-multiple-choice-face) + (cdr (rmc--add-key-description + (list (event-basic-type last) hint))))) (propertize (key-description key) 'face 'read-multiple-choice-face)))) keys ", ") diff --git a/test/lisp/repeat-tests.el b/test/lisp/repeat-tests.el index 3f17978468c..480fffc05ef 100644 --- a/test/lisp/repeat-tests.el +++ b/test/lisp/repeat-tests.el @@ -93,7 +93,9 @@ :repeat ( :enter (repeat-tests-call-s) :continue (repeat-tests-call-e repeat-tests-call-o - repeat-tests-call-u)) + repeat-tests-call-u) + :hints ((repeat-tests-call-t . "test") + (repeat-tests-call-o . "another test"))) "s" 'ignore ;; for non-nil repeat-check-key only "t" 'repeat-tests-call-t "C-M-o" 'repeat-tests-call-o @@ -238,8 +240,7 @@ ;; 'C-M-o' should also activate (repeat-tests--check "C-M-o c z" - '((1 o) (1 c)) "z") - ))) + '((1 o) (1 c)) "z")))) (ert-deftest repeat-tests-continue-another () (with-repeat-mode repeat-tests-global-map @@ -269,6 +270,20 @@ "C-M-a c C-M-o C-M-o c z" '((1 a) (1 c) (1 o) (1 o) (1 c)) "z")))) +(ert-deftest repeat-tests-hints () + (with-repeat-mode repeat-tests-global-map + (let ((repeat-echo-function 'ignore) + (repeat-check-key nil)) + (execute-kbd-macro (kbd "C-M-s")) + (should (equal (repeat-echo-message-string (repeat-get-map repeat-in-progress)) + #("Repeat with s, [T]est, C-M-o (an[O]ther test), C-M-u" + 12 13 + (face read-multiple-choice-face) + 23 28 + (face read-multiple-choice-face) + 47 52 + (face read-multiple-choice-face))))))) + (require 'use-package)