From c8161fda6409d459aeabd8db6128f5ca5d09e129 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Tue, 14 Jan 2025 21:41:48 +0200 Subject: [PATCH] Fix repeat-mode to keep the same map symbol for repeat-continue * lisp/repeat.el (repeat-get-map-sym): New function refactored from 'repeat-get-map'. (repeat-get-map): Move continue-related code to 'repeat-get-map-sym'. (repeat-pre-hook): Use 'repeat-get-map-sym' and 'repeat-get-map'. Set 'repeat-map' to 'map-sym'. (repeat-post-hook): Use 'repeat-get-map-sym'. * test/lisp/repeat-tests.el (repeat-tests-continue-another): Improve to invoke double key 'C-M-o C-M-o' that should not switch between maps (bug#74140). (cherry picked from commit 0bd12f560b0b288e6c7717bf2e0f664c17d07619) --- lisp/repeat.el | 29 +++++++++++++++++------------ test/lisp/repeat-tests.el | 7 +++++-- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lisp/repeat.el b/lisp/repeat.el index e772fb0c934..2b062cf5b7a 100644 --- a/lisp/repeat.el +++ b/lisp/repeat.el @@ -451,21 +451,25 @@ See `describe-repeat-maps' for a list of all repeatable commands." (and (symbolp real-this-command) (get real-this-command property)))) -(defun repeat-get-map (&optional rep-map) - "Return a transient map for keys repeatable after the current command." +(defun repeat-get-map-sym () + "Return a transient map possibly as a symbol." (when repeat-mode - (let ((rep-map (or rep-map repeat-map (repeat--command-property 'repeat-map))) + (let ((map-sym (or repeat-map (repeat--command-property 'repeat-map))) (continue (repeat--command-property 'repeat-continue))) (when continue (if repeat-in-progress (when (and (consp continue) (memq repeat-in-progress continue)) - (setq rep-map repeat-in-progress)) - (setq rep-map nil))) - (when rep-map - (when (and (symbolp rep-map) (boundp rep-map)) - (setq rep-map (symbol-value rep-map))) - rep-map)))) + (setq map-sym repeat-in-progress)) + (setq map-sym nil))) + map-sym))) + +(defun repeat-get-map (map) + "Return a transient map for keys repeatable after the current command." + (when map + (when (and (symbolp map) (boundp map)) + (setq map (symbol-value map))) + map)) (defun repeat-check-key (key map) "Check if the last KEY is suitable for activating the repeating MAP." @@ -495,20 +499,21 @@ See `describe-repeat-maps' for a list of all repeatable commands." "Function run before commands to handle repeatable keys." (when (and repeat-mode repeat-keep-prefix repeat-in-progress (not prefix-arg) current-prefix-arg) - (let ((map (repeat-get-map))) + (let* ((map-sym (repeat-get-map-sym)) + (map (repeat-get-map map-sym))) ;; Only when repeat-post-hook will activate the same map (when (repeat-check-map map) ;; Optimize to use less logic in the function `repeat-get-map' ;; for the next call: when called again from `repeat-post-hook' ;; it will use the variable `repeat-map'. - (setq repeat-map map) + (setq repeat-map map-sym) ;; Preserve universal argument (setq prefix-arg current-prefix-arg))))) (defun repeat-post-hook () "Function run after commands to set transient keymap for repeatable keys." (let* ((was-in-progress repeat-in-progress) - (map-sym (or repeat-map (repeat--command-property 'repeat-map))) + (map-sym (repeat-get-map-sym)) (map (repeat-get-map map-sym))) (setq repeat-in-progress nil) (when (repeat-check-map map) diff --git a/test/lisp/repeat-tests.el b/test/lisp/repeat-tests.el index 70690722164..8e564b3e081 100644 --- a/test/lisp/repeat-tests.el +++ b/test/lisp/repeat-tests.el @@ -233,8 +233,11 @@ '((1 u)) "tz") ;; 'C-M-o' shared with another map should continue current map (repeat-tests--check - "C-M-s t C-M-o t C-M-o t z" - '((1 s) (1 t) (1 o) (1 t) (1 o) (1 t)) "z")))) + "C-M-s t C-M-o C-M-o t z" + '((1 s) (1 t) (1 o) (1 o) (1 t)) "z") + (repeat-tests--check + "C-M-a c C-M-o C-M-o c z" + '((1 a) (1 c) (1 o) (1 o) (1 c)) "z")))) (require 'use-package) -- 2.39.5