[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Repeat lambda (was: Some minor suggestions to Tab Bar)

From: Juri Linkov
Subject: Repeat lambda (was: Some minor suggestions to Tab Bar)
Date: Tue, 23 Mar 2021 20:30:47 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

>> (defvar tab-bar-move-repeat-map
>>  (let ((map (make-sparse-keymap)))
>>    (define-key map "m" 'tab-move)
>>    (define-key map "M" (lambda ()
>>                          (interactive)
>>                          (tab-move -1)))
>>    map)
>>  "Keymap to repeat tab move key sequences `C-x t m m'.
>> Used in `repeat-mode'.")
>> (put 'tab-move 'repeat-map 'tab-bar-move-repeat-map)
> One nitpicking is that `C-x t m M m’ is not allowed
> since `(tab-move -1)` hasn’t a `repeat-map’ property.
> Maybe name it tab-move-prev and set the property?

This can't be a general solution since there are other keymaps
where repeating lambda is required.

For example, other-window-repeat-map currently has no keybinding
that could switch to navigating windows in the opposite direction.
There were proposals to bind it to "O", but since there is no such
command as "previous-window" to cycle windows backwards,
using a lambda is required, but currently this doesn't work:

  (define-key other-window-repeat-map "O"
    (lambda ()
      (other-window -1)))

Stefan already asked about this, but I had no idea
how it could be improved.  Now I tried to set
the KEEP-PRED arg of set-transient-map to t, and
it seems both lambdas above can be used with this change:

diff --git a/lisp/repeat.el b/lisp/repeat.el
index 84a613da0c..4be4f766ef 100644
--- a/lisp/repeat.el
+++ b/lisp/repeat.el
@@ -398,7 +398,7 @@ repeat-post-hook
             (when repeat-exit-key
               (define-key map repeat-exit-key 'ignore))
-            (set-transient-map map)))))))
+            (set-transient-map map t)))))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]