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#74140: [PATCH] Add :continue-only directive for repeat maps in bind-keys, use-package Date: Thu, 28 Nov 2024 21:12:25 +0200 Organization: LINKOV.NET Message-ID: <87r06vxjdy.fsf@mail.linkov.net> References: 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="32985"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) Cc: 74140@debbugs.gnu.org To: Paul Nelson Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 28 20:15:31 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 1tGjz8-0008NG-A0 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 28 Nov 2024 20:15:30 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGjyj-0002ya-SG; Thu, 28 Nov 2024 14:15:06 -0500 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 1tGjyh-0002wN-2n for bug-gnu-emacs@gnu.org; Thu, 28 Nov 2024 14:15:03 -0500 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 1tGjyg-0006cB-Mc for bug-gnu-emacs@gnu.org; Thu, 28 Nov 2024 14:15:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=dn1qTZUDSWqEMtzMTiotFYsWp5sVUMf+3tDEMraTTh0=; b=oiOqoM9dKA5ApMdGdbzkBF3NJyNvfXWzQZemP+XsSUcF/n1mafcDy0Q7tJ0IOvaUG28vHfVMNFpQbOQl42+Hkth8AAyNeRTMrGIQ4khRCchzv2b7j+tkSawhuKOTJisyVmmxslGUZDCOYno2yN7L6IoRR4IaulPZ0HfR40ADh8bflG9/KLAZvumXBLM4ZzGwWASqWNUtAKyrh2GW4m1tgIlYb2UkNihJUaSbVq/NHQ3yL8DPQMG5sSltwoOtCbHLDSoS840nOE0j1RPOQvLqOhk6sdDO3dCdP8V+6XiEv2p6W7E7mnp0VQQK3lR4irvqD++PTDN7EvXZnX3XM3dX6g==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tGjyg-0003m3-CE for bug-gnu-emacs@gnu.org; Thu, 28 Nov 2024 14:15:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 28 Nov 2024 19:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74140 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 74140-submit@debbugs.gnu.org id=B74140.173282126714427 (code B ref 74140); Thu, 28 Nov 2024 19:15:02 +0000 Original-Received: (at 74140) by debbugs.gnu.org; 28 Nov 2024 19:14:27 +0000 Original-Received: from localhost ([127.0.0.1]:39758 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tGjy6-0003kc-KJ for submit@debbugs.gnu.org; Thu, 28 Nov 2024 14:14:27 -0500 Original-Received: from relay6-d.mail.gandi.net ([217.70.183.198]:49289) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tGjy4-0003kK-D8 for 74140@debbugs.gnu.org; Thu, 28 Nov 2024 14:14:25 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id E956FC0004; Thu, 28 Nov 2024 19:14:14 +0000 (UTC) In-Reply-To: (Paul Nelson's message of "Wed, 27 Nov 2024 16:19:01 +0100") 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:296065 Archived-At: --=-=-= Content-Type: text/plain >> Thanks for pointing out the case when the command is bound to the same key >> globally and in the repeat map. So checking for a key can't help here. >> >> Therefore, I implemented another solution in repeat.el. There is now >> a new symbol property 'repeat-continue-only'. And a command with this >> symbol property will not activate the repeat map, but will only continue >> the already activated repeating sequence. This is implemented by >> a simple change: >> >> (when (and (repeat-check-map map) >> (or (null (repeat--command-property 'repeat-continue-only)) >> was-in-progress)) >> > > Thanks, I took a look. One disadvantage of this approach is that it > does not allow the same command to enter one repeat map and continue > another. I'll confess that I'm not aware of any such examples in my > config, but it still seems like an undesirable "non-local" effect. Other existing properties such as 'repeat-exit-timeout' or 'repeat-check-key' don't accept a list of repeat maps, but only a non-nil value (including the special symbol :no). However, this can be changed gradually by adding support for the list to them. So below is a patch that adds support for a list of maps. And users don't have to populate the list manually because 'defvar-keymap' does this automatically with :continue-only in the same patch. > This issue motivated my suggestion that the symbol property should be a > list of repeat maps that the command continues, although I haven't > considered the details (e.g., concerning the map vs. the symbol that > points to it) - maybe you have a clearer picture of those. Using a variable value for the map property is supported but not encouraged. There are too many problems when not using a symbol. So let's support only symbols in the list of repeat maps for :continue-only. >> BTW, while writing the 'bind-keys' test, I noticed there is no way >> to specify a command that only activates, but not continues >> (the same as :entry in 'defvar-keymap'). Is it true that 'bind-keys' >> has no such keyword, so there is a need to do this explicitly with: >> >> (put 'repeat-tests-bind-call-a 'repeat-map 'repeat-tests-bind-keys-repeat-map) > > Yes, that's also my understanding (but it's not clear to me that it > requires such a keyword if its purpose is to bind keys in a map). My goal was to write the same test for 'bind-keys' as for 'defvar-keymap' in test/lisp/repeat-tests.el: (bind-keys :map repeat-tests-bind-keys-map ("C-M-a" . repeat-tests-bind-call-a) ("C-M-o" . repeat-tests-bind-call-o) :repeat-map repeat-tests-bind-keys-repeat-map :continue ("c" . repeat-tests-bind-call-c) :continue-only ("C-M-o" . repeat-tests-bind-call-o) :exit ("q" . repeat-tests-bind-call-q)) But I can't find a way to do the same what the :enter key does in 'defvar-keymap', so needed to set the symbol explicitly: (put 'repeat-tests-bind-call-a 'repeat-map 'repeat-tests-bind-keys-repeat-map) --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=repeat-continue-only.patch diff --git a/lisp/keymap.el b/lisp/keymap.el index 9b133e1ca82..43c8d918ba7 100644 --- a/lisp/keymap.el +++ b/lisp/keymap.el @@ -687,6 +687,7 @@ defvar-keymap `:exit' and `:hints', for example: :repeat (:enter (commands ...) :exit (commands ...) + :continue-only (commands ...) :hints ((command . \"hint\") ...)) `:enter' specifies the list of additional commands that only @@ -702,6 +703,10 @@ defvar-keymap in this specific map, but should not have the `repeat-map' symbol property. +`:continue-only' specifies the list of commands that should not +enter `repeat-mode'. These command should only continue the +already activated repeating sequence. + `: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. @@ -740,6 +745,10 @@ defvar-keymap def) (dolist (def (plist-get repeat :enter)) (push `(put ',def 'repeat-map ',variable-name) props)) + (dolist (def (plist-get repeat :continue-only)) + (push `(put ',def 'repeat-continue-only + (cons ',variable-name (get ',def 'repeat-continue-only))) + props)) (while defs (pop defs) (setq def (pop defs)) diff --git a/lisp/repeat.el b/lisp/repeat.el index 11d26a477b6..45888d9db08 100644 --- a/lisp/repeat.el +++ b/lisp/repeat.el @@ -505,8 +505,12 @@ repeat-post-hook (setq repeat-in-progress nil) (let ((map (repeat-get-map))) (when (and (repeat-check-map map) - (or (null (repeat--command-property 'repeat-continue-only)) - was-in-progress)) + (let ((continue-only (repeat--command-property 'repeat-continue-only))) + (or (null continue-only) + (and (or (not (consp continue-only)) + (memq (repeat--command-property 'repeat-map) + continue-only)) + was-in-progress)))) ;; Messaging (funcall repeat-echo-function map) diff --git a/test/lisp/repeat-tests.el b/test/lisp/repeat-tests.el index c560a283039..527963e3ef8 100644 --- a/test/lisp/repeat-tests.el +++ b/test/lisp/repeat-tests.el @@ -63,17 +63,15 @@ repeat-tests-map (defvar-keymap repeat-tests-repeat-map :doc "Keymap for repeating sequences." - :repeat ( :enter (repeat-tests-call-a) - :exit (repeat-tests-call-q)) + :repeat ( :enter (repeat-tests-call-a) + :continue-only (repeat-tests-call-o) + :exit (repeat-tests-call-q)) "a" 'ignore ;; for non-nil repeat-check-key only "c" 'repeat-tests-call-c "d" 'repeat-tests-call-d "C-M-o" 'repeat-tests-call-o "q" 'repeat-tests-call-q) -;; TODO: add new keyword ':continue-only (repeat-tests-call-o)' -(put 'repeat-tests-call-o 'repeat-continue-only t) - ;; Test using a variable instead of the symbol: (put 'repeat-tests-call-b 'repeat-map repeat-tests-repeat-map) --=-=-=--