4

I'm trying to get a custom color-theme (solarized) setup for my emacs that utilizes a 16 color palette, which I've already set up for my terminal (gnome-terminal).

When running emacs from a normal terminal with TERM=xterm-256color, I can correctly get M-x list-colors-display to show all 16 ansi colors, e.g. red, green, brightgreen, brightred, etc.

However, when running it from within tmux and TERM=screen-256color, M-x list-colors-display only lists the basic 8 colors, and is missing the extended bright colors. Under both settings, evaluating (display-color-cells) reports 256 colors. The only references to the bright colors that I can find are in lisp/term/xterm.el and lisp/term/rxvt.el, so it would seem the issue is in the TERM setting.

For tmux to work properly the TERM must be set to screen or screen-256color, so setting TERM differently is out. I have had some luck using an alias:

alias emacs='TERM=xterm-256color emacs'

Is there a better way than this to force emacs to allow the use of all 16 ansi colors?

1 Answer 1

2

As you found, the additional colors are configured by a TERM-specific library file (e.g. term/lisp). Newer versions of GNU Emacs includes a term/screen that re-uses the color definitions from term/xterm, but it sounds like your version of Emacs does not do this.

If you do not want to upgrade to a newer Emacs, then you can probably just use the content from a Gist that includes a term/screen.el and a bit that you can put in your .emacs to enable it; that version of term/screen.el also includes a few of the key definitions that you might find useful if you enable tmux’s xterm-keys option.

The core bits of the code look like this:

;;; .emacs addition
(add-to-list 'load-path "~/.emacs.d/lisp/")

;;; ~/.emacs.d/lisp/term/screen.el
(load "term/xterm") 
(defun terminal-init-screen ()
  (xterm-register-default-colors)
  (tty-set-up-initial-frame-faces))
5
  • I do sometimes have to use version 23, which appears to be missing the screen definitions as you mentioned. I'll give the solution you posted a try. Thanks!
    – agrubb
    Jan 9, 2013 at 23:11
  • As a follow up, the solution you posted is working fine as far as color support goes. One problem I have noticed using this approach is that emacs appears to lose the ability to support underlined faces when running using this method, but using the alias approach works fine. I've tried hunting down where underline support is defined but haven't had any luck. Any thoughts?
    – agrubb
    Jan 25, 2013 at 21:00
  • @agrubb: Emacs is probably using a terminfo entry for your active TERM (e.g. screen-256color) that includes an ncv capability that says that the terminal can not support underlining and color at the same time; this causes Emacs to forgo underlining in favor of bold (see the defface underline in faces.el). You can check your terminfo entry with tput ncv (ideally, to support underlining you need -1, or a number where the the “2 bit” is off). In emacs you can use M-x : (display-supports-face-attributes-p '(:underline t)) to check for underline support. Jan 26, 2013 at 2:53
  • @agrubb: The terminfo entry in newer releases of ncurses clears ncv from its screen entries, so I guess your Emacs binary is using an older version if the terminfo database. You could build a custom entry that clears ncv with a command like this: { infocmp -x screen-256color; printf '\t%s\n' 'ncv@,'; } > /tmp/t && tic -x /tmp/t (when run as non-root, it will write a new screen-256color entry under ~/.terminfo/). You can get an overview of the faces with M-x list-faces-display to check how (e.g.) underline is shown. Jan 26, 2013 at 2:54
  • That was the problem. Building the custom terminfo entry did the trick. Thanks!
    – agrubb
    Jan 28, 2013 at 19:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .