3

I am trying to bind <C-return>. I tried global-set-key but it didn't work. I then found a suggestion in "Globally override key binding in Emacs" where someone created a custom minor-mode which included their keybindings, like this:

(define-key my-keys-minor-mode-map (kbd "<C-return>") 'insert-and-indent-line-above)

Bit it still won't replace the current binding. If I do a describe-key and press C-Return it tells me that it is bound to cua-set-rectangle-mark.

How do I make this binding supersede all other bindings?

Community
  • 1
  • 1
MDCore
  • 17,583
  • 8
  • 43
  • 48
  • Did you actually try making the minor mode? It's a clean technique for this sort of thing; if you paste your code then we can help you debug that instead. – jrockway Sep 21 '10 at 16:53
  • I did. And it is running (I can see `my-keys` next to `ErgoEmacs` :) – MDCore Sep 22 '10 at 14:58

2 Answers2

8

It sounds like you have cua-mode enabled, which is setting that binding. You can disable cua-mode:

(cua-mode -1)

Or, change the binding for cua-set-rectangle-mark like so:

(setq cua-rectangle-mark-key (kbd "C-S-<return>"))
(cua-mode 1)

And then your binding should take effect (using the global-set-key).

Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
  • I do want cua-mode but changing the key before cua-mode starts did the trick – MDCore Sep 22 '10 at 15:15
  • 1
    +1 for good answer, but a little comment for people trying to use the code as shown here. It should be (setq cua-rectangle-mark-key (kbd "C-S-")). Please note the < and > symbols. It causes an error and it might not be obvious why. – Cthutu Feb 04 '13 at 20:57
  • @Cthutu Thanks for noticing that. I did it in Emacs, and it actually put the <> around the entire key chord - so I updated with that. – Trey Jackson Feb 04 '13 at 21:09
  • What's the difference between wrapping the entire chord and just wrapping the return? Is there a difference? – Cthutu Feb 05 '13 at 18:33
  • @Cthutu That would make a great SO question. :) Apparently there is no difference. I actually prefer the way you have it set up, so I'm editing again. For more information on accepted syntax, check the documentation for `edmacro-mode` (which apparently isn't documented in *info*. – Trey Jackson Feb 05 '13 at 20:30
0

You want to use global-unset-key.

(global-unset-key (read-kbd-macro "C-<return>"))
Joe Casadonte
  • 15,888
  • 11
  • 45
  • 57
  • if I `eval-region` this line it still doesn't unbind it. very strange. – MDCore Sep 20 '10 at 13:56
  • 3
    Because the binding is in the `cua-mode-map`, not the `(current-global-map)`. From the docs: "Note that if KEY has a local binding in the current buffer, that local binding will continue to shadow any global binding that you make with this function." – jrockway Sep 21 '10 at 16:37