From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#70576: [PATCH] `repeat-echo-message-string': support repeat keymap "hints" Date: Sun, 28 Apr 2024 19:38:38 +0300 Organization: LINKOV.NET Message-ID: <86ttjle92p.fsf@mail.linkov.net> References: <45C35B69-6DA8-4212-BD87-50B2A3959A86@gmail.com> <86h6fo3e7e.fsf@mail.linkov.net> <86cyqaezhc.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37438"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: 70576@debbugs.gnu.org To: JD Smith Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Apr 28 19:08:25 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s180n-0009Ym-0d for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 28 Apr 2024 19:08:25 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1809-0007L9-Bs; Sun, 28 Apr 2024 13:07:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1807-0007KA-Gh for bug-gnu-emacs@gnu.org; Sun, 28 Apr 2024 13:07:43 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1807-0002Vk-39 for bug-gnu-emacs@gnu.org; Sun, 28 Apr 2024 13:07:43 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s180Q-0001S2-H5 for bug-gnu-emacs@gnu.org; Sun, 28 Apr 2024 13:08:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 28 Apr 2024 17:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70576 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 70576-submit@debbugs.gnu.org id=B70576.17143240765555 (code B ref 70576); Sun, 28 Apr 2024 17:08:02 +0000 Original-Received: (at 70576) by debbugs.gnu.org; 28 Apr 2024 17:07:56 +0000 Original-Received: from localhost ([127.0.0.1]:51266 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s180J-0001RX-V5 for submit@debbugs.gnu.org; Sun, 28 Apr 2024 13:07:56 -0400 Original-Received: from relay4-d.mail.gandi.net ([217.70.183.196]:44395) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s180H-0001RN-J9 for 70576@debbugs.gnu.org; Sun, 28 Apr 2024 13:07:54 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id CBCBAE0003; Sun, 28 Apr 2024 17:07:26 +0000 (UTC) In-Reply-To: (JD Smith's message of "Sun, 28 Apr 2024 08:45:19 -0400") X-GND-Sasl: juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:284102 Archived-At: --=-=-= Content-Type: text/plain >> (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? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=repeat-hint.patch 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. --=-=-=--