From 954968a80749457c62bdf37515f9397c92d3022e Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Wed, 27 Nov 2024 09:45:19 +0200 Subject: [PATCH] Add command symbol property 'repeat-continue-only' for 'repeat-mode' * lisp/repeat.el: (repeat-post-hook): Ignore commands with 'repeat-continue-only' symbol property when repeat was not in progress (bug#74140). * test/lisp/repeat-tests.el (repeat-tests-continue-only): New test. (repeat-tests-bind-keys): Prepare for :continue-only. (cherry picked from commit 64c289590b56ea08d646b74f1a4b5de0a1faa2e2) --- etc/NEWS | 3 +++ lisp/repeat.el | 4 +++- test/lisp/repeat-tests.el | 41 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 6d458701af5..9451ea8f94d 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -812,6 +812,9 @@ provide a ':columns' spec, so that the number of columns and their widths can be determined. Columns widths can be set explicitly, or they will be calculated based on the window width. +** New symbol propery 'repeat-continue-only' for 'repeat-mode'. +A command with this symbol propery will not activate the repeat map, +but will only continue the already activated repeating sequence. * Changes in Emacs 31.1 on Non-Free Operating Systems diff --git a/lisp/repeat.el b/lisp/repeat.el index 2be182769ad..6b0c69905d8 100644 --- a/lisp/repeat.el +++ b/lisp/repeat.el @@ -503,7 +503,9 @@ See `describe-repeat-maps' for a list of all repeatable commands." (let ((was-in-progress repeat-in-progress)) (setq repeat-in-progress nil) (let ((map (repeat-get-map))) - (when (repeat-check-map map) + (when (and (repeat-check-map map) + (or (null (repeat--command-property 'repeat-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 5b3a72a37ae..c560a283039 100644 --- a/test/lisp/repeat-tests.el +++ b/test/lisp/repeat-tests.el @@ -25,7 +25,7 @@ (require 'repeat) ;; Key mnemonics: a - Activate (enter, also b), c - Continue (also d), -;; q - Quit (exit) +;; o - continue-Only (not activate), q - Quit (exit) (defvar repeat-tests-calls nil) @@ -45,6 +45,10 @@ (interactive "p") (push `(,arg d) repeat-tests-calls)) +(defun repeat-tests-call-o (&optional arg) + (interactive "p") + (push `(,arg o) repeat-tests-calls)) + (defun repeat-tests-call-q (&optional arg) (interactive "p") (push `(,arg q) repeat-tests-calls)) @@ -54,7 +58,8 @@ :doc "Keymap for keys that initiate repeating sequences." "C-x w a" 'repeat-tests-call-a "C-M-a" 'repeat-tests-call-a - "C-M-b" 'repeat-tests-call-b) + "C-M-b" 'repeat-tests-call-b + "C-M-o" 'repeat-tests-call-o) (defvar-keymap repeat-tests-repeat-map :doc "Keymap for repeating sequences." @@ -63,8 +68,12 @@ "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) @@ -171,6 +180,19 @@ ;; TODO: :tags '(:expensive-test) for repeat-exit-timeout +(ert-deftest repeat-tests-continue-only () + (with-repeat-mode repeat-tests-map + (let ((repeat-echo-function 'ignore) + (repeat-check-key nil)) + ;; 'C-M-o' used as continue-only + (repeat-tests--check + "C-M-a c C-M-o c z" + '((1 a) (1 c) (1 o) (1 c)) "z") + ;; 'C-M-o' should not activate + (repeat-tests--check + "C-M-o c z" + '((1 o)) "cz")))) + (require 'use-package) @@ -186,6 +208,10 @@ (interactive "p") (push `(,arg d) repeat-tests-calls)) +(defun repeat-tests-bind-call-o (&optional arg) + (interactive "p") + (push `(,arg o) repeat-tests-calls)) + (defun repeat-tests-bind-call-q (&optional arg) (interactive "p") (push `(,arg q) repeat-tests-calls)) @@ -195,9 +221,12 @@ (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) ) @@ -208,6 +237,14 @@ (with-repeat-mode repeat-tests-bind-keys-map (let ((repeat-echo-function 'ignore) (repeat-check-key nil)) + ;; 'C-M-o' used as continue-only + (repeat-tests--check + "C-M-a c C-M-o c z" + '((1 a) (1 c) (1 o) (1 c)) "z") + ;; 'C-M-o' should not activate + ;; (repeat-tests--check + ;; "C-M-o c z" + ;; '((1 o)) "cz") ;; 'q' should exit (repeat-tests--check "C-M-a c q c" -- 2.39.5