3
votes

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
Have you tried entering a different mode to see if the key bindings that are trumping you are mode specific or global? That will affect how you deal with the situation. - lawlist

1 Answers

4
votes

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))