emacs-devel
[Top][All Lists]
Advanced

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

RE: Patch for emacs/basic.texi


From: Drew Adams
Subject: RE: Patch for emacs/basic.texi
Date: Wed, 16 Sep 2020 16:59:14 +0000 (UTC)

> > Isn't `C-x u` also a default keybinding? Although it requires two
> > keypresses, that should work on all keyboard layouts.
> 
> It is a default binding, but it's more cumbersome for "undo bursts"
> (repeating "undo" a bunch of times).
> 
> (It's one of those bindings, along with with "C-x o", that I wish came
> with a "C-x z"-like transient map.)

It's trivial to create a repeating command, so you
can use `C-x u u u u ...'.

Either of the definitions below for this (`undo-repeat')
works.  The second one is not specific to any key binding
- use it with any prefix key, not just `C-x u'.

Then use this binding:
(global-set-key [remap undo] 'undo-repeat)

1.

(defun undo-repeat (arg)
  "Same as `undo', but repeatable even on a prefix key.
E.g., if bound to `C-x u' then you can use `C-x u u u...' to repeat."
  (interactive "*P")
  (undo arg)
  (set-transient-map (let ((map  (make-sparse-keymap)))
                       (define-key map "u" 'undo-repeat)
                       map)))

2.

(defun repeat-command (command)
  "Repeat COMMAND."
  (require 'repeat) ; Define its vars before we let-bind them.
  (let ((repeat-previous-repeated-command  command)
        (repeat-message-function           #'ignore)
        (last-repeatable-command           'repeat))
    (repeat nil)))

(defun undo-repeat (arg)
  "Same as `undo', but repeatable even on a prefix key.
E.g., if bound to `C-x u' then you can use `C-x u u u...' to repeat."
  (interactive "*P")
  (repeat-command 'undo))


Similarly, for `C-x o' (`other-window'):

(defun other-window-repeat ()
  "Same as `other-window', but repeatable even on a prefix key.
E.g., if bound to `C-x o' then you can use `C-x o o o...' to repeat."
  (interactive)
  (repeat-command 'other-window))

(global-set-key [remap other-window] 'other-window-repeat)

I do this all over the place, where it makes sense.



reply via email to

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