Can't map Ctrl + minus in Emacs in Mac OS X

∥☆過路亽.° 提交于 2020-01-24 17:57:04

问题


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:

  1. Nothing happens - this means that the shortcut is being intercepted at the level of the operating system.
  2. 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 either global-set-key, or local-set-key or define-key with this function, either comment it out, or better just call the same function with same shortcut and nil 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:

  1. If it was set with (global-set-key (kbd "C--") 'text-scale-decrease), you unset it with (global-set-key (kbd "C--") nil).
  2. 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).
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!