From: Juri Linkov <juri@linkov.net>
To: JD Smith <jdtsmith@gmail.com>
Cc: 70576@debbugs.gnu.org
Subject: bug#70576: [PATCH] `repeat-echo-message-string': support repeat keymap "hints"
Date: Sun, 28 Apr 2024 19:38:38 +0300 [thread overview]
Message-ID: <86ttjle92p.fsf@mail.linkov.net> (raw)
In-Reply-To: <F002D0AE-8594-429F-8313-EF867AD6DB5C@gmail.com> (JD Smith's message of "Sun, 28 Apr 2024 08:45:19 -0400")
[-- Attachment #1: Type: text/plain, Size: 710 bytes --]
>> (defvar-keymap expreg-repeat-map
>> :doc "Repeat map for `expreg' actions."
>> :repeat '(:hints ((expreg-expand . "expand") (expreg-contract . "contract")))
>> "\\" 'expreg-expand
>> "|" 'expreg-contract)
>
> If a hint is missing for a command, it should just have its key mentioned.
> It looks like your idea would require changes to defvar-keymap. Do you
> want to propose a patch? We'd need some way to pass the hints in; perhaps
> the macro could set a property on the command symbol as you initially
> proposed.
Alright, let's add this to defvar-keymap. Please try the following patch.
PS: Do you still think a new custom variable should be added to be able to
disable hint strings?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: repeat-hint.patch --]
[-- Type: text/x-diff, Size: 3706 bytes --]
diff --git a/lisp/keymap.el b/lisp/keymap.el
index b2b475c7d71..cbd26f1060e 100644
--- a/lisp/keymap.el
+++ b/lisp/keymap.el
@@ -603,10 +603,11 @@ defvar-keymap
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 @@ defvar-keymap
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 @@ defvar-keymap
(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
diff --git a/lisp/repeat.el b/lisp/repeat.el
index 0a59494c097..b9c96fa4e12 100644
--- a/lisp/repeat.el
+++ b/lisp/repeat.el
@@ -553,20 +553,27 @@ repeat--clear-prev
(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.
next prev parent reply other threads:[~2024-04-28 16:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-25 22:31 bug#70576: [PATCH] `repeat-echo-message-string': support repeat keymap "hints" JD Smith
2024-04-26 6:06 ` Juri Linkov
2024-04-26 14:37 ` JD Smith
2024-04-28 6:58 ` Juri Linkov
2024-04-28 12:45 ` JD Smith
2024-04-28 16:38 ` Juri Linkov [this message]
2024-05-02 6:48 ` Juri Linkov
2024-05-02 7:16 ` Eli Zaretskii
2024-05-02 11:47 ` JD Smith
2024-05-02 16:16 ` Juri Linkov
2024-05-02 18:14 ` Eli Zaretskii
2024-05-03 6:23 ` Juri Linkov
2024-05-03 7:15 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86ttjle92p.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=70576@debbugs.gnu.org \
--cc=jdtsmith@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.