When in javascript mode trying to use C-c C-m i get an error saying "C-c RET is undefined?"

What makes Emacs believe I am pressing RET?

How can i properly make this keybinding work?


Emacs "thinks" that C-m is RET because "Control M" is the ASCII control character "carriage return". Even though this reason is "historical" Emacs can run in a terminal and so it needs to support the way terminals still work now.

Try opening a terminal window, typing "ls", and pressing C-m. You will see that it is interpreted as "return", even though you are not in Emacs.

See Control character on Wikipedia for details about control characters.

To distinguish C-m from RET in a GUI Emacs, one could change C-i to C-m in @nispio's answer:

(define-key input-decode-map [?\C-m] [C-m])

;; now we can do this:

(defun my-command ()
  (message "C-m is not the same as RET any more!"))

(global-set-key (kbd "<C-m>") #'my-command)

See also

  • 2
    This is brilliant, thank you. Now I can have C-m as a prefix map for multiple-cursors. – John Wiegley Dec 9 '17 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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