I have the following code in .emacs
: (global-set-key (kbd "M-x g") 'gnus)
to start Gnus with the keybinding M-x g
. I obtain: error: Key sequence M-x g starts with non-prefix key M-x
. How can I define keybindings starting with M-x
? Is this a bad thing to do and should be avoided? I find it more intuitive since the "long version" is M-x gnus
. Defining it as C-c g
for example is no problem but then you start Gnus with C-c g
and, for example, R via M-x R
which is not very intuitive (in contrast to starting both via M-x + 1 letter
Asked
Active
Viewed 1.6k times
16

Marius Hofert
- 6,546
- 10
- 48
- 102
1 Answers
25
The key M-x is already bound to the command execute-extended-command
, which then asks you to provide the name of a command to execute (in you case: gnus
).
Since R
is a command only one-character long, it looks like M-x R is a key sequence, but it's not: it's M-x followed by entering R
in the minibuffer and you have to hit RET to validate your input.
In short:
- you can not set key sequences beginning with M-x since this key is already bound to a command and is thus not a prefix (unlike C-c, which does nothing but wait for you to type another key, but should be reserved for bindings specific to the current modes).
- the standard way to do things would be to continue starting gnus using M-x gnus or to rebind it to an entirely different key if you need to be very quick (you could for example use one of the F1-F12 keys)
- if you really want to have a M-x + letter binding, you can define a one-letter alias to the command
gnus
, like this:
(defalias 'g 'gnus)

François Févotte
- 19,520
- 4
- 51
- 74
-
3The fourth option would be to clear M-x and make it a prefix key: http://stackoverflow.com/questions/1024374/how-can-i-make-c-p-an-emacs-prefix-key-for-develperlysense (However, M-x is such a core emacs key that in this case it's probably a bad idea.) – idbrii May 11 '15 at 10:23