I'm trying to configure Ctrl-Alt-Enter to insert a new top-level heading and the current date in the following format:

* [2023-02-07 Tue]

This is what I've come up with:

(defun heading-date ()
    (insert (format-time-string "[%Y-%m-%d %a]"))
(global-set-key (kbd "C-M-return") 'heading-date)

However, when I press Ctrl-Alt-Enter I get this error in Emacs:

<C-M-return> is undefined

I've also tried reversing the order of C and M for experimentation's sake but of course that did not help:

(global-set-key (kbd "M-C-return") 'heading-date)

How can I capture the Ctrl-Alt-Enter combination to run this function?

1 Answer 1


Ten minutes after posting I come up with the solution! ))

It turns out to bind return the entire binding must be surrounded with brackets <>. So this is the binding:

(global-set-key (kbd "<C-M-return>") 'heading-date)

Answer found from this post after noticing the error on startup error C-M- must prefix a single character, not return. Lesson learned: Watch those startup errors!

  • 1
    When you are unsure about the notion of a key, just C-h k and press the key[s].
    – nichijou
    Feb 7, 2023 at 15:29
  • @nichijou Thank you. That is useful information, but I do not believe that it would have helped identify how to bind that key combination.
    – dotancohen
    Feb 7, 2023 at 15:49
  • Presumably this is only useful in an Org mode buffer. If that's the case, then you'd be better off binding the key in org-mode-map, rather than the global map: (define-key org-mode-map (kbd "C-M-<return>") #'heading-date). Note also that you can evaluate the kbd function with any argument in your *scratch* buffer to see what it returns: switch to that buffer, type the first form you tried, (kbd "M-C-return"), press C-j after the closing paren to evaluate it and in this case, you'll get an error, so you know the string is wrong.
    – NickD
    Feb 8, 2023 at 20:41
  • Terrific, thank you NickD!
    – dotancohen
    Feb 9, 2023 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.