Reputation: 96370
Say I have some interactive function in Emacs my-function
, how can I bind it to Ctrl + RET?
I have tried with:
(global-set-key (kbd "C-RET") 'my-function)
and
(global-set-key (kbd "C-return") 'my-function)
but none of them seem to work. is this at all possible?
Upvotes: 10
Views: 3407
Reputation: 8195
This should work:
(global-set-key [(control return)] 'my-function)
It works for me, but may not in a terminal as per @phils's answer.
Upvotes: 0
Reputation: 73334
Always remember that kbd
very conveniently accepts the exact same syntax that Emacs gives you when you ask it about a key sequence, so you never ever have to guess.
C-hkC-RET tells me:
<C-return>
therefore I would use (kbd "<C-return>")
OTOH, when running Emacs in my terminal, C-hkC-RET tells me:
C-j
because C-RET
isn't a valid control character in a terminal, and therefore Emacs isn't receiving the same input that it gets in GUI mode (so I wouldn't be able to use that binding in my terminal).
Upvotes: 23