avd
avd

Reputation: 14441

Emacs: by mistake binded M-x to a different function

By mistake I have binded M-x ( used for doing all the operations ) to a newly defined function ? How do I unbind it ? Now Alt-x always executes my function :( I dont want to exit emacs and restart again, I have lot of buffers open, so is there a way out here ?

Upvotes: 2

Views: 348

Answers (2)

gavinb
gavinb

Reputation: 20018

You could invoke M-: (or Alt-Shift-;) to run eval-expression. Then use global-set-key to reassign "M-x" to its default value (execute-extended-command).

If you're worried about having a lot of buffers open and losing your workspace, you can always enable the desktop extension, which will save and restore the state of your buffers and windows.

Upvotes: 4

flolo
flolo

Reputation: 15486

The command usually run is execute-extended-command, just rebind it.

To rebind it, you have several options:

  1. Just make what you did before, but just use instead your own function above mentioned execute-extended-command. If you did it with M-x command, then you maybe dont know, but M-x is not only produced by Alt-x, but as there are keyboard layouts that have no Alt (or Meta) key, you can use Esc x instead.

  2. Rebind it with elisp command. To do this, change to the *scratch* buffer, enter (global-set-key (kbd "M-x") 'execute-extended-command) and execute it with C-j.

  3. Maybe by using the menue (I usually dont use it, so I am not sure on this point)

Upvotes: 6

Related Questions