问题
stackoverflow! In the past few days I was trying to customize my emacs a little bit and I faced the problem that I don't know how to approach.
What I'm trying to do is to define a global keybinding and an ido-mode keybinding that would use the same keys to do different things.
Ido-mode keybinding is defined this way:
(defun ido-my-keys ()
"Add my keybindings for ido."
(define-key ido-completion-map (kbd "M-<return>")
'ido-invoke-in-vertical-split)
)
(add-hook 'ido-setup-hook 'ido-my-keys)
And it works fine until I place the following line in my .emacs file:
(global-set-key (kbd "M-<return>") 'insert-newline-and-indent)
With this line present M-return invokes insert-newline-and-indent even from ido-switch-buffer. Interestingly, when I use global-set-key interactively (i.e. not from init-file but from M-x invocation), everything works as expected.
Thanks for your help. Sorry for my english.
The problem turned out to be in ergoemacs-mode that I had turned on. This mode defines an advice for global-set-key that causes this effect.
I solved the problem by moving the global-set-key call above the ergoemacs initialization. Not the best solution, but a simple one.
回答1:
The problem was caused by ergoemacs-keybindings package, or, to be more specific, by ergoemacs-mode.el
This package defines an advice for global-set-key that, in fact, replaces it with its own ergoemacs-global-set-key. But since ergoemacs is a minor mode, its keymap has higher precedence than the global map, thus overriding keybinding of ido minor mode.
I see three solutions to that problem:
- Comment-out advice in ergoemacs-mode.el.
- Use global-set-key BEFORE you turn on ergoemacs-mode.
- Wait for the ergoemacs author to fix the bug ;)
来源:https://stackoverflow.com/questions/9877557/ido-mode-binding-masked-by-global-set-key