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?
Here's what I'm dealing with:
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...
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.
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.
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With