Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
2  
Possible duplicate of Properly distinguish Ctrl+i and Tab – Drew Feb 12 at 13:35
1  
Same problem, different entry point, I think it would be nice to keep both questions around for people coming from different searches. – Jordon Biondo Feb 12 at 15:58
1  
1  
Possible duplicate of How to bind C-i as different from TAB? – Gilles Feb 14 at 0:39
up vote 11 down vote accepted

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 ()
  (interactive)
  (message "C-m is not the same as RET any more!"))

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

See also

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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