Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terminal emacs colors only work with TERM=xterm-256color

Tags:

emacs

I've found that terminal emacs does not render the correct colors unless I explicitly set TERM=xterm-256color. I use gnome-terminal, and from what I understand, TERM should be set to gnome-256color. Similarly, I tend to use tmux a lot, which advises against any TERM setting other than screen-256color. Unfortunately, both of those settings (within their respective context - gnome-terminal or tmux) result in emacs having wrong colors, whereas vim displays colors correctly. However, if I export TERM=xterm-256color, the colors work just fine in emacs.

Can anyone explain what's going on, or offer a solution?

Update

Here's what I'm dealing with:

enter image description here

I can get the colors to look correct in the terminal by adding the following to my init.el:

(defun terminal-init-gnome ()   "Terminal initialization function for gnome-terminal."    ;; This is a dirty hack that I accidentally stumbled across:   ;;  initializing "rxvt" first and _then_ "xterm" seems   ;;  to make the colors work... although I have no idea why.   (tty-run-terminal-initialization (selected-frame) "rxvt")    (tty-run-terminal-initialization (selected-frame) "xterm")) 

This feels really, really wrong though. There has to be a logical explanation for this...

P.S.

I have very little knowledge of terminfo and the precise role that $TERM plays in the process of color terminal behavior. If it's safe to always use xterm-256color (even when $TERM "should" be gnome-256color or screen-256color), I'll go with that.

like image 237
Charles Avatar asked Oct 01 '11 01:10

Charles


People also ask

What is term xterm-256color?

xterm-256color describes Xterm with support for 256 colors enabled. xterm-color describes an older branch of Xterm that supports eight colors. xterm-color is not recommended, since it describes a variant of Xterm that's less functional and that you're not likely to be using.

How do you set xterm-256color?

To enable colors on XTerm you will need to run the configure scripts with the --enable-256-color switch, in addition you may also need to set your TERM environment variable to xterm-256color .


1 Answers

Maybe I'm not understanding something, buy why don't you run emacs like this:

TERM=xterm-256color emacs -nw 

This way Emacs has its own TERM setting that you know works. You can also make an alias or wrap this in shell-script.

like image 63
event_jr Avatar answered Oct 05 '22 08:10

event_jr