Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs error: Key sequence M-x g starts with non-prefix key M-x

Tags:

emacs

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

like image 760
Marius Hofert Avatar asked Feb 27 '12 08:02

Marius Hofert


1 Answers

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)
like image 55
François Févotte Avatar answered Sep 28 '22 02:09

François Févotte