]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix repeat-mode to keep the same map symbol for repeat-continue
authorJuri Linkov <juri@linkov.net>
Tue, 14 Jan 2025 19:41:48 +0000 (21:41 +0200)
committerEshel Yaron <me@eshelyaron.com>
Fri, 17 Jan 2025 11:30:53 +0000 (12:30 +0100)
* 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
test/lisp/repeat-tests.el

index e772fb0c934eb69fc2ee5585bdcbc51d440f47cf..2b062cf5b7af8f844515849820f3d0078d50384f 100644 (file)
@@ -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)
index 70690722164b900862d81052f9205245782e1cf3..8e564b3e08146147c5aab311ee8c69ba114bdf79 100644 (file)
        '((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"))))
 
 \f
 (require 'use-package)