From 15de559d98b1b19733bacf0c39716d5ebabe6dfa Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Tue, 6 Apr 2021 00:02:43 +0300 Subject: [PATCH] * lisp/repeat.el (repeat-keep-prefix): New defcustom. * lisp/repeat.el (repeat-map): New autoloaded global variable. (repeat-post-hook): Use 'repeat-map' when non-nil and reset it to nil afterwards. (repeat-post-hook): Keep the current prefix when 'repeat-keep-prefix' is non-nil. * lisp/window.el (other-window-repeat-map): Add "O" that sets 'repeat-map' to 'other-window-repeat-map' before calling '(other-window -1)'. https://lists.gnu.org/archive/html/emacs-devel/2021-03/msg01387.html --- etc/NEWS | 4 ++++ lisp/repeat.el | 19 ++++++++++++++++--- lisp/window.el | 4 ++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 1421efcaa07..c8400ba8c27 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2251,6 +2251,10 @@ You can type 'C-x u u' instead of 'C-x u C-x u' to undo many changes, 'M-g n n p p' to navigate next-error matches. Any other key exits transient mode and then is executed normally. 'repeat-exit-key' defines an additional key to exit mode like 'isearch-exit' ('RET'). +With 'repeat-keep-prefix' you can keep the prefix arg of the previous command. +For example, this can help to reverse the window navigation direction +with e.g. 'C-x o M-- o o'. Also it can help to set a new step with +e.g. 'C-x { C-5 { { {' will set the window resizing step to 5 columns. * New Modes and Packages in Emacs 28.1 diff --git a/lisp/repeat.el b/lisp/repeat.el index a5ab43950c2..1830bcc0497 100644 --- a/lisp/repeat.el +++ b/lisp/repeat.el @@ -342,6 +342,14 @@ For example, you can set it to like `isearch-exit'." :group 'convenience :version "28.1") +(defcustom repeat-keep-prefix t + "Keep the prefix arg of the previous command." + :type 'boolean + :group 'convenience + :version "28.1") + +;;;###autoload (defvar repeat-map nil) + ;;;###autoload (define-minor-mode repeat-mode "Toggle Repeat mode. @@ -364,8 +372,9 @@ When Repeat mode is enabled, and the command symbol has the property named (defun repeat-post-hook () "Function run after commands to set transient keymap for repeatable keys." (when repeat-mode - (let ((rep-map (and (symbolp this-command) - (get this-command 'repeat-map)))) + (let ((rep-map (or repeat-map + (and (symbolp this-command) + (get this-command 'repeat-map))))) (when rep-map (when (boundp rep-map) (setq rep-map (symbol-value rep-map))) @@ -382,6 +391,9 @@ When Repeat mode is enabled, and the command symbol has the property named (when (or (lookup-key map (this-single-command-keys) nil) prefix-command-p) + (when (and repeat-keep-prefix (not prefix-command-p)) + (setq prefix-arg current-prefix-arg)) + ;; Messaging (unless prefix-command-p (map-keymap (lambda (key _) (push key keys)) map) @@ -402,7 +414,8 @@ When Repeat mode is enabled, and the command symbol has the property named (when repeat-exit-key (define-key map repeat-exit-key 'ignore)) - (set-transient-map map))))))) + (set-transient-map map)))))) + (setq repeat-map nil)) (provide 'repeat) diff --git a/lisp/window.el b/lisp/window.el index f27631bb86a..071761ea50f 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -10256,6 +10256,10 @@ displaying that processes's buffer." (defvar other-window-repeat-map (let ((map (make-sparse-keymap))) (define-key map "o" 'other-window) + (define-key map "O" (lambda () + (interactive) + (setq repeat-map 'other-window-repeat-map) + (other-window -1))) map) "Keymap to repeat other-window key sequences. Used in `repeat-mode'.") (put 'other-window 'repeat-map 'other-window-repeat-map) -- 2.39.5