title: Terminal emacs colors only work with TERM=xterm-256color
body: <p>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 - <code>gnome-terminal</code> or <code>tmux</code>) result in emacs having wrong colors, whereas vim displays colors correctly. However, if I <code>export TERM=xterm-256color</code>, the colors work just fine in emacs.</p>
  
  <p>Can anyone explain what's going on, or offer a solution?</p>
  
  <h2>Update</h2>
  
  <p>Here's what I'm dealing with:</p>
  
  <p><img src="https://i.stack.imgur.com/DAqzV.png" alt="enter image description here"></p>
  
  <p>I can get the colors to look correct in the terminal by adding the following to my <code>init.el</code>:</p>
  
  <pre><code>(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"))
  </code></pre>
  
  <p>This feels really, really wrong though. There has to be a logical explanation for this...</p>
  
  <h2>P.S.</h2>
  
  <p>I have very little knowledge of terminfo and the precise role that <code>$TERM</code> plays in the process of color terminal behavior. <del>If it's safe to always use <code>xterm-256color</code> (even when <code>$TERM</code> "should" be <code>gnome-256color</code> or <code>screen-256color</code>), I'll go with that.</del></p>