modulitos
modulitos

Reputation: 15854

emacs: assign single key-binding to multiple commands, using the universal argument

Here is my attempt:

(global-set-key [M-left] (key-binding (kbd "C-u C-@")))

After I evaluate the above expression, invoking alt + left gives me the message <M-left> is undefined. The following, however, works:

(global-set-key [M-left] (key-binding (kbd "C-u")))

But this is only the universal argument part of my command. How do I combine these two commands into one Emacs key-binding?

Upvotes: 1

Views: 963

Answers (2)

phils
phils

Reputation: 73345

sds has provided the solutions, but for clarification, if you evaluate (key-binding (kbd "C-u C-@")) you'll see that it returns nil -- because that is not a bound key sequence.

In fact C-u runs the command universal-argument, which takes care of reading a subsequent key sequence from the user (C-@ in your case).

Upvotes: 1

sds
sds

Reputation: 60062

There are two ways to do this: define a Keyboard Macro interactively or write a function:

(define-key global-map [M-left]
  (lambda ()
    (interactive)
    (set-mark-command t)))

Upvotes: 3

Related Questions