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#51281: 28.0.60; repeat-mode issues Date: Tue, 19 Oct 2021 10:12:20 +0300 Organization: LINKOV.NET Message-ID: <87tuhdijk3.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="26071"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) To: 51281@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 19 09:18:05 2021 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 1mcjNt-0006ez-7c for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 19 Oct 2021 09:18:05 +0200 Original-Received: from localhost ([::1]:57004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcjNr-0004nm-TC for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 19 Oct 2021 03:18:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcjK1-0000zf-U9 for bug-gnu-emacs@gnu.org; Tue, 19 Oct 2021 03:14:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcjJy-0003KH-HL for bug-gnu-emacs@gnu.org; Tue, 19 Oct 2021 03:14:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mcjJy-0000Wh-6F for bug-gnu-emacs@gnu.org; Tue, 19 Oct 2021 03:14: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: Tue, 19 Oct 2021 07:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 51281 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16346276271984 (code B ref -1); Tue, 19 Oct 2021 07:14:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 19 Oct 2021 07:13:47 +0000 Original-Received: from localhost ([127.0.0.1]:49244 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mcjJj-0000Vv-Fb for submit@debbugs.gnu.org; Tue, 19 Oct 2021 03:13:47 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:54376) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mcjJg-0000Vn-IQ for submit@debbugs.gnu.org; Tue, 19 Oct 2021 03:13:46 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51794) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcjJe-0000Wp-Jy for bug-gnu-emacs@gnu.org; Tue, 19 Oct 2021 03:13:44 -0400 Original-Received: from relay6-d.mail.gandi.net ([217.70.183.198]:36507) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcjJX-0002xz-IQ for bug-gnu-emacs@gnu.org; Tue, 19 Oct 2021 03:13:42 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 1E7B2C0013 for ; Tue, 19 Oct 2021 07:13:32 +0000 (UTC) Received-SPF: pass client-ip=217.70.183.198; envelope-from=juri@linkov.net; helo=relay6-d.mail.gandi.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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" Xref: news.gmane.io gmane.emacs.bugs:217548 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Currently there is a bug where the prefix arg changed for the repeatable commands, is applied to the next non-repeatable command. For example: C-- C-x o o C-n or C-x o C-- o C-n `C-n' moves up, not down. This patch fixes this bug: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=repeat-mode-fixes.patch diff --git a/lisp/repeat.el b/lisp/repeat.el index ee9e14b515..f4526c20f4 100644 --- a/lisp/repeat.el +++ b/lisp/repeat.el @@ -390,7 +390,10 @@ repeat-mode See `describe-repeat-maps' for a list of all repeatable command." :global t :group 'convenience (if (not repeat-mode) - (remove-hook 'post-command-hook 'repeat-post-hook) + (progn + (remove-hook 'pre-command-hook 'repeat-pre-hook) + (remove-hook 'post-command-hook 'repeat-post-hook)) + (add-hook 'pre-command-hook 'repeat-pre-hook) (add-hook 'post-command-hook 'repeat-post-hook) (let* ((keymaps nil) (commands (all-completions @@ -402,27 +405,60 @@ repeat-mode (length commands) (length (delete-dups keymaps)))))) -(defun repeat-post-hook () - "Function run after commands to set transient keymap for repeatable keys." - (let ((was-in-progress repeat-in-progress)) - (setq repeat-in-progress nil) +(defun repeat-map () + "Return a map for keys repeatable after the current command." (when repeat-mode (let ((rep-map (or repeat-map (and (symbolp real-this-command) (get real-this-command 'repeat-map))))) (when rep-map - (when (boundp rep-map) + (when (and (symbolp rep-map) (boundp rep-map)) (setq rep-map (symbol-value rep-map))) - (let ((map (copy-keymap rep-map))) + (if repeat-exit-key + ;; `repeat-exit-key' modifies the map by adding keys + (copy-keymap rep-map) + rep-map))))) + +(defun repeat-map-valid (map) + "Check if MAP can be used for the next command. +Can contain more conditions." + (and map + ;; Avoid using repeatable keys when minibuffer prompt pops up + (zerop (minibuffer-depth)) ;; Exit when the last char is not among repeatable keys, ;; so e.g. `C-x u u' repeats undo, whereas `C-/ u' doesn't. - (when (and (zerop (minibuffer-depth)) ; avoid remapping in prompts - (or (lookup-key map (this-command-keys-vector)) - prefix-arg)) + (or (lookup-key map (vector last-nonmenu-event)) + ;; `prefix-arg' can affect next repeatable commands + ;; (and repeat-keep-prefix prefix-arg) + ))) + +(defun repeat-pre-hook () + "Function run before commands to handle repeatable keys." + ;; Reset prefix-arg before the next non-repeatable command, + ;; e.g. `C-- C-x o o C-n' or `C-x o C-- o C-n', so `C-n' + ;; should not use `prefix-arg' to go in opposite direction. + (when (and repeat-keep-prefix prefix-arg repeat-in-progress) + (let ((map (repeat-map))) + (if map + ;; Optimize to use less logic in `repeat-map' + ;; when called again from `repeat-post-hook' + (setq repeat-map map) + ;; When `repeat-post-hook' will exit the repeatable sequence, + ;; this means the current command is not repeatable, + ;; so reset `prefix-arg' enabled for repeatable commands only. + (setq prefix-arg nil))))) + +(defun repeat-post-hook () + "Function run after commands to set transient keymap for repeatable keys." + (let ((was-in-progress repeat-in-progress)) + (setq repeat-in-progress nil) + + (let ((map (repeat-map))) + (when (repeat-map-valid map) ;; Messaging - (unless prefix-arg + (unless prefix-arg ;; Don't overwrite prefix arg echo (funcall repeat-echo-function map)) ;; Adding an exit key @@ -446,7 +482,7 @@ repeat-post-hook (lambda () (setq repeat-in-progress nil) (funcall exitfun) - (funcall repeat-echo-function nil))))))))))) + (funcall repeat-echo-function nil)))))))) (setq repeat-map nil) (when (and was-in-progress (not repeat-in-progress)) --=-=-=--