How to provide a true alias key sequence in emacs?

1

I would like in Emacs a key sequence FOO to be an true alias for a sequence BAR. Whenever FOO is entered it should perform the same action as entering BAR does.

I cannot use something like:

(global-set-key (kbd "FOO") (key-binding (kbd "BAR")))

That binds FOO to the current action for BAR . If BAR will be later remapped or overwritten or hidden by a minor mode, that will not be reflected by FOO.

I tried to workaround that using:

(global-set-key (kbd "FOO") 
  (lambda ()
   (interactive)
   (key-binding (kbd "BAR")))

But that still is not a true alias. The interactive spec for the lambda is not the same as for the action that BAR is bound to. I suppose I can address that using (interactive (advice-eval-interactive ...)), but it seems rater complex for something that sounds like a basic functionality.

So perhaps I missed some Emacs API for doing key aliasing?

Igor Bukanov

Posted 2018-12-27T16:27:32.473

Reputation: 213

Answers

1

You can try:

(global-set-key (kbd "FOO") (kbd "BAR"))

Stefan

Posted 2018-12-27T16:27:32.473

Reputation: 1 052