Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I suspect this is some sort of magic terminal definition thing but I've noticed some magic keys not working on terminals. When I type M-RET to create a new item in org mode I instead get a newline. M-x describe-key reports seeing C-M-j instead.

Sure I could rebind C-M-j to do what's expected but I'd really like to know why there is a disconnect between what I type and what the remote terminal sees.

Edit:

gnome-terminal on Ubuntu Hardy Heron ssh'ing to Debian Stable running emacs23

share|improve this question
2  
What terminal emulation program, what OS, Emacs version ,etc. FWIW on Terminal.app, OSX Leopard, Emacs 23, I get M-RET. –  Richard Hoskins Aug 5 '09 at 17:00
add comment

3 Answers

up vote 1 down vote accepted

Does your Ubuntu setup have a strange keyboard layout or does it remap keys?

Go to System, then Preferences, and then Keyboard, and choose the Layouts tab. I find that Generic 104-key keyboard works the best as it includes the Win keys (I have the standard multimedia keys too and they still work). This seems to make things work no matter what terminal application I am using or whether I am SSH'ing.

Also, make sure that the Alt key isn't mapped to something by checking the Layout Options.

share|improve this answer
    
It seems to be a gnome-terminal thing as if I use rxvt I can get M-RET to work fine. I've also been unable to reset gnome-terminals default character encoding to UTF-8 but I think that is unrelated to the keybinding issue. In terms of layout I have it set to Microsoft Natural and a remapped Caps-Lock->Control. –  stsquad Oct 7 '09 at 11:21
add comment

There's not really a disconnect. Behind the scenes there's really no such thing as an "enter" or a "return". There are carriage-return characters and new-line characters.

Carriage return is Ctrl-M. New-line is Ctrl-J.

So, a Meta-RET being reported as a Meta-Ctrl-J makes perfect sense.

share|improve this answer
    
Depends on the hardware and OS. Some systems are capable of distinguishing between Ctrl-J and RET keystrokes, and can generate different code sequences for them. –  David R Tribble Nov 12 '09 at 22:50
add comment

I don't know. Based on others' responses, it does seem to be a gnome-terminal thing. For those who want to remap keys to get certain functionality to work, here is an example snippet:

;; Workaround for org-mode problem with gnome terminal
;; https://gist.github.com/hanachin/997420
(add-hook 'org-mode-hook
      (lambda ()
        (if window-system
            nil
          (progn
            (define-key org-mode-map "\C-\M-j" 'org-meta-return)
            (define-key org-mode-map "\C-j" 'org-insert-heading-respect-content)))))
share|improve this answer
add comment

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.