emacs -nw and xterm (Getting xterm to recognize the ALT key)

The terminal emulators I’ve used so far are konsole, gnome-terminal and xterm. Since my RHEL box at work is KDE-based and my ubuntu machine at home is gnome based, konsole and gnome-terminal have received heavy usage. The other day I decided to (re)try out xterm on my ubuntu 10.04. I like xterm and have used it before, but I couldn’t for the life of me remember why I switched back.

Once I started some real work, of course, it all came back to me.

I’m a heavy emacs user and often have emacs running in terminal mode over an ssh session. And xterm by default does not recognize the ALT key. The alternative is the (ugh!) ESC key. This of course can get very frustrating. And if you (like me) are not careful, your source files might end up with the character ÿ scattered all over the place. And so, determined to continue using xterm, I set out to look for a solution.

The most common solution found online was of course to edit the ~/.Xdefaults and/or ~/.Xresources with the following lines-

~ $ cat ~/.Xdefaults | tail -n 3
Xterm*metaSendsEscape:     TRUE
Xterm*altSendsEscape:      TRUE
Xterm*eightBitInput:       false
~ $

and also to edit the .inputrc to have the following lines-

~ $ cat .inputrc 
set meta-flag on
set convert-meta off
set output-meta on
~ $ 

But that still didn’t quite do it for me.

After much digging/reading, I figured out that while ~/.Xdefaults under your home directory has settings for the current user, the file /etc/X11/app-defaults/XTerm contains settings that can be globally applied.

xterm*metaSendsEscape: true

And so adding the above line to the above file allowed XTerm to recognize the ALT key the way emacs likes it.

This entry was posted in config and tagged , , . Bookmark the permalink.

5 Responses to emacs -nw and xterm (Getting xterm to recognize the ALT key)

  1. ilya says:

    Still doesn’t work for me.

    % appres Xterm | grep metaSendsEscape
    Xterm*metaSendsEscape: TRUE
    % appres Xterm | grep altSendsEscape
    Xterm*altSendsEscape: TRUE
    % appres Xterm | grep eightBitInput
    Xterm*eightBitInput: false

    then in emacs when I M-x brings up the minibuffer prompt as expected but A-x “~120” and no prompt.
    C-q M-x produces “?” which is probably displayed because it can’t display the character and C-q A-x produces “^[[27;3;120~”.

    Any ideas?

  2. nixnoob says:

    Did you reload the X config files after editing them?
    You can do that by running xrdb -merge ~/.Xresources

    Also did you make the required changes to .inputrc ?

  3. ilya says:

    hi nixnoob,
    yes, i did xrdb merge. the output of appres command confirms that the settings took effect. i also created ~/.inputrc but am not sure that is needed (is this shell specific; i am using tcsh)?
    Is there a way to tell emacs that “^[[27;3;” is alt?
    thank you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s