问题
I'm trying to map Ctrl + minus ("C--") to undo in Emacs 24.3 (from http://emacsformacosx.com) in Mac OS X 10.8.4, but I can't get it to work. There seems to be some very global key binding for decreasing the font size, which I can't seem to override. Can anyone tell me what I'm doing wrong?
I have the following in my .emacs.
(global-set-key (kbd "C--") 'undo) ;; Doesn't work
(global-set-key (kbd "C-u") 'undo) ;; Just for testing, does work
When I press Ctrl+U, it triggers undo, but when I press Ctrl+minus, it decreases the font size. It might be simply that I should use something other than "C--", but it looks like it should work. I checked the key bindings (via C-h b) and there, C-u is bound to undo, but C-- is bound to text-scale-decrease. It would probably be possible to find where that key is bound and get some clue, but my Emacs-fu is too weak.
I'm using the graphical version of Emacs, not the terminal version.
回答1:
With these type of problems I usually try f1 k and right after the key combination that I'm having a problem with, C-- in your case. One of two things should happen:
- Nothing happens - this means that the shortcut is being intercepted at the level of the operating system.
- It gives you a description of a function that's being called.
It's probable that it was set by either your major mode or one of the minor modes.
So you should investigate that as well, searching though the references
to this function, which is
text-scale-decrease
in you case. After you find eitherglobal-set-key
, orlocal-set-key
ordefine-key
with this function, either comment it out, or better just call the same function with same shortcut andnil
in your~/.emacs
.
UPD: how to unset a key
When you find that some source that you're loading e.g. starter-kit
is setting the key,
you just need to unset it later in the same way:
- If it was set with
(global-set-key (kbd "C--") 'text-scale-decrease)
, you unset it with(global-set-key (kbd "C--") nil)
. - If it was set with
(define-key markdown-mode-map (kbd "C--") 'text-scale-descrease)
, you unset it with(define-key markdown-mode-map (kbd "C--") nil)
. If it was set with
(add-hook 'markdown-mode-hook (lambda()(local-set-key (kbd "C--") 'text-scale-descrease))
you unset with
(add-hook 'markdown-mode-hook (lambda()(local-set-key (kbd "C--") nil))
来源:https://stackoverflow.com/questions/17784902/cant-map-ctrl-minus-in-emacs-in-mac-os-x