]> git.eshelyaron.com Git - emacs.git/commitdiff
Support hints in the :repeat keyword of defvar-keymap for repeat-mode
authorJuri Linkov <juri@linkov.net>
Thu, 2 May 2024 06:46:48 +0000 (09:46 +0300)
committerEshel Yaron <me@eshelyaron.com>
Mon, 6 May 2024 16:33:11 +0000 (18:33 +0200)
* lisp/keymap.el (defvar-keymap): Add :hints to the :repeat keyword.
Put the property 'repeat-hint' on the command symbol.

* lisp/repeat.el (repeat-echo-message-string): Show hint strings
defined with the property 'repeat-hint' on the command symbol (bug#70576).

(cherry picked from commit 0023891e84285c2ea2a8029f479135f792c9d1e9)

etc/NEWS
lisp/keymap.el
lisp/repeat.el

index 53e79dfd0d925fdbea116a298a8a463f769ce16b..de5a35975f4b568b1616eb6a9b287e1def51baff 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2779,6 +2779,10 @@ major mode.
 ** The variable 'rx-constituents' is now obsolete.
 Use 'rx-define', 'rx-let' and 'rx-let-eval' instead.
 
+---
+** 'defvar-keymap' can specify hints for 'repeat-mode'.
+Using ':repeat (:hints ((command . "hint") ...))' will show
+the hint string in the echo area together with repeatable keys.
 
 \f
 * Changes in Emacs 30.1 on Non-Free Operating Systems
index b2b475c7d71853f28ccbd6d0f5db0399402088ec..cbd26f1060e21d0777015ca0bcff16d782f343af 100644 (file)
@@ -603,10 +603,11 @@ non-nil, all commands in the map will have the `repeat-map'
 symbol property.
 
 More control is available over which commands are repeatable; the
-value can also be a property list with properties `:enter' and
-`:exit', for example:
+value can also be a property list with properties `:enter',
+`:exit' and `:hints', for example:
 
-     :repeat (:enter (commands ...) :exit (commands ...))
+     :repeat (:enter (commands ...) :exit (commands ...)
+              :hints ((command . \"hint\") ...))
 
 `:enter' specifies the list of additional commands that only
 enter `repeat-mode'.  When the list is empty, then only the
@@ -621,6 +622,10 @@ Specifying a list of commands is useful when those commands exist
 in this specific map, but should not have the `repeat-map' symbol
 property.
 
+`:hints' is a list of cons pairs where car is a command and
+cdr is a string that is displayed alongside of the repeatable key
+in the echo area.
+
 \(fn VARIABLE-NAME &key DOC FULL PARENT SUPPRESS NAME PREFIX KEYMAP REPEAT &rest [KEY DEFINITION]...)"
   (declare (indent 1))
   (let ((opts nil)
@@ -660,7 +665,9 @@ property.
           (setq def (pop defs))
           (when (and (memq (car def) '(function quote))
                      (not (memq (cadr def) (plist-get repeat :exit))))
-            (push `(put ,def 'repeat-map ',variable-name) props)))))
+            (push `(put ,def 'repeat-map ',variable-name) props)))
+        (dolist (def (plist-get repeat :hints))
+          (push `(put ',(car def) 'repeat-hint ',(cdr def)) props))))
 
     (let ((defvar-form
            `(defvar ,variable-name
index 0a59494c0977308e7da35b23aaeb8037c1ffeafe..412afc35ba73197cda74fbb4237d3972f5fb5128 100644 (file)
@@ -553,20 +553,27 @@ This function can be used to force exit of repetition while it's active."
 (defun repeat-echo-message-string (keymap)
   "Return a string with the list of repeating keys in KEYMAP."
   (let (keys)
-    (map-keymap (lambda (key cmd) (and cmd (push key keys))) keymap)
-    (format-message "Repeat with %s%s"
-                    (mapconcat (lambda (key)
-                                 (substitute-command-keys
-                                  (format "\\`%s'"
-                                          (key-description (vector key)))))
-                               keys ", ")
-                    (if repeat-exit-key
-                        (substitute-command-keys
-                         (format ", or exit with \\`%s'"
-                                 (if (key-valid-p repeat-exit-key)
-                                     repeat-exit-key
-                                   (key-description repeat-exit-key))))
-                      ""))))
+    (map-keymap (lambda (key cmd) (and cmd (push (cons key cmd) keys)))
+                keymap)
+    (format-message
+     "Repeat with %s%s"
+     (mapconcat (lambda (key-cmd)
+                  (let* ((key (car key-cmd))
+                         (cmd (cdr key-cmd))
+                         (hint (when (symbolp cmd)
+                                 (get cmd 'repeat-hint))))
+                    (substitute-command-keys
+                     (format "\\`%s'%s"
+                             (key-description (vector key))
+                             (if hint (format ":%s" hint) "")))))
+                keys ", ")
+     (if repeat-exit-key
+         (substitute-command-keys
+          (format ", or exit with \\`%s'"
+                  (if (key-valid-p repeat-exit-key)
+                      repeat-exit-key
+                    (key-description repeat-exit-key))))
+       ""))))
 
 (defun repeat-echo-message (keymap)
   "Display in the echo area the repeating keys defined by KEYMAP.