Customizing less colors

color-managementcolorsemacsless

When using less in OS X, how can I customize the colors with with things are displayed? When I run less within an ansi-term in Emacs the colors don't come out nicely.

$ less --version
less 418
Copyright (C) 1984-2007 Mark Nudelman

Best Answer

For OSX, this refers to Emacs 22.1.1; Fedora with Emacs 24 has the same behavior.

Emac's ansi-term supports 8 colors. That is all that ANSI specified, and "ansi-term" is named appropriately. The eterm-color terminal description in ncurses is used for this terminal type. Emacs sets TERM to this value (see source):

(defvar term-term-name "eterm-color"
  "Name to use for TERM.
Using \"emacs\" loses, because bash disables editing if $TERM == emacs.")

If you override TERM, e.g., to tell applications that it has more colors, then the extra colors will not be used. Likewise, hard-coded applications which ignore the terminal database cannot use extra colors either.

While Emacs can use more than 8 colors in a terminal, ansi-term does not. Reading the source, look for term-ansi-current-color, and see that there is only logic for 30-37, 39, 40-47 and 49:

   ;; Foreground
   ((and (>= parameter 30) (<= parameter 37))
    (setq term-ansi-current-color (- parameter 29)))

   ;; Reset foreground
   ((eq parameter 39)
    (setq term-ansi-current-color 0))

   ;; Background
   ((and (>= parameter 40) (<= parameter 47))
    (setq term-ansi-current-bg-color (- parameter 39)))

   ;; Reset background
   ((eq parameter 49)
    (setq term-ansi-current-bg-color 0))

You may be able to change the palette of colors used by your terminal, but there is no way to make ansi-term differ from that (it will use the first 8 colors even if Emacs can use 256).

Further reading:

For Emacs other than ansi-term:

Also:

Related Question