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
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.
;; 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).
For Emacs other than ansi-term:
I believe it's partially a function of your terminal type, for one.
$ echo $TERM xterm-256color
This post might also be worth a look, titled: Piping Ls Through Less With Colors on Mac OS X. Also this setting might prove helpful.
$ export LESS="-erX" -or- $ export LESS="-eRX"
You can consult the man page for
less to find out more about the various switches above.