eugene
eugene

Reputation: 41785

emacs unbound key bindings

How do I clear a binding or edit a binding an emacs package provide?

For instance I had keybindings M-c to capitalize a word.
After I install some 3rd party emacs package, it is changed to calc-dispatch.

I'd like to use M-c as capitalize as before, and set calc-dispatch to something else.

How can I do this in general?

Upvotes: 3

Views: 957

Answers (2)

louxiu
louxiu

Reputation: 2915

The keybind maps are loaded by order. The keybind map which loaded later will have higher priority. This is why the local key map will override the global keymap, because the global key map is loaded before the local key map(the mode key map). Something is wrong here. Look phils's comment.

What I solve this problem is add a hook to that specify mode to disable that key bind and rebind it to other key in that key map.

First, you need to find the key-map name which defines the M-c bind to calc-dispatch. It is usually the combination of mode name and mode-map.

For example, the name of python mode key map is py-mode-map.

Second, remove the M-c bind in that mode and rebind to other key using hook.

For example, in python mode, I want to remove the bind C-j (py-newline-and-indent). And rebind it to C-i. Because globally I bind C-j to linum-ace-jump. This is the similar case with yours.

(add-hook 'python-mode-hook 
          #'(lambda () 
              (define-key py-mode-map "\C-j" nil)
              (define-key py-mode-map "\C-i" 'py-newline-and-indent)))

Upvotes: 2

PascalVKooten
PascalVKooten

Reputation: 21481

What you ask for is:

(global-set-key (kbd "M-c") 'capitalize-word)

This is in general the way to set words globally.

Maybe if you want to substite the two, you can try this:

(substitute-key-definition
           'capitalize-word 'calc-dispatch (current-global-map))



(define-key KEYMAPNAME (kbd "KEYCOMBO") 'FUNCNAME)

Is for specific mode. For example: (define-key emacs-lisp-mode (kbd "M-c) 'capitalize-word).

(global-set-key (kbd "M-c") nil)

Is to generally unbind a key (globally).

You can easily find more on this by just googling.

Upvotes: 1

Related Questions