Function: xterm-register-default-colors
xterm-register-default-colors is a byte-compiled function defined in
xterm.el.gz.
Signature
(xterm-register-default-colors COLORS)
Documentation
Register the default set of colors for xterm or compatible emulator.
This function registers the number of colors returned by display-color-cells
for the currently selected frame. The first (16) colors are taken from
COLORS, which see, while the rest are computed assuming
either the 88- or 256-color standard color scheme supported by latest
versions of xterm.
Source Code
;; Defined in /usr/src/emacs/lisp/term/xterm.el.gz
(defun xterm-register-default-colors (colors)
"Register the default set of colors for xterm or compatible emulator.
This function registers the number of colors returned by `display-color-cells'
for the currently selected frame. The first (16) colors are taken from
COLORS, which see, while the rest are computed assuming
either the 88- or 256-color standard color scheme supported by latest
versions of xterm."
(let* ((ncolors (display-color-cells))
(color (car colors)))
(if (> ncolors 0)
;; Clear the 8 default tty colors registered by startup.el
(tty-color-clear))
;; Only register as many colors as are supported by the display.
(while (and (> ncolors 0) colors)
(tty-color-define (car color) (cadr color)
(mapcar #'xterm-rgb-convert-to-16bit
(car (cddr color))))
(setq colors (cdr colors)
color (car colors)
ncolors (1- ncolors)))
;; We've exhausted the colors from `colors'. If there
;; are more colors to support, compute them now.
(when (> ncolors 0)
(cond
((= ncolors 16777200) ; 24-bit xterm
;; all named tty colors
(let ((idx (length xterm-standard-colors)))
(mapc (lambda (color)
(unless (assoc (car color) xterm-standard-colors)
(tty-color-define (car color) idx (cdr color))
(setq idx (1+ idx))))
color-name-rgb-alist)))
((= ncolors 240) ; 256-color xterm
;; 216 non-gray colors first
(let ((r 0) (g 0) (b 0))
(while (> ncolors 24)
;; This and other formulas taken from 256colres.pl and
;; 88colres.pl in the xterm distribution.
(tty-color-define (format "color-%d" (- 256 ncolors))
(- 256 ncolors)
(mapcar #'xterm-rgb-convert-to-16bit
(list (if (zerop r) 0 (+ (* r 40) 55))
(if (zerop g) 0 (+ (* g 40) 55))
(if (zerop b) 0 (+ (* b 40) 55)))))
(setq b (1+ b))
(if (> b 5)
(setq g (1+ g)
b 0))
(if (> g 5)
(setq r (1+ r)
g 0))
(setq ncolors (1- ncolors))))
;; Now the 24 gray colors
(while (> ncolors 0)
(setq color (xterm-rgb-convert-to-16bit (+ 8 (* (- 24 ncolors) 10))))
(tty-color-define (format "color-%d" (- 256 ncolors))
(- 256 ncolors)
(list color color color))
(setq ncolors (1- ncolors))))
((= ncolors 72) ; 88-color xterm
;; 64 non-gray colors
(let ((levels '(0 139 205 255))
(r 0) (g 0) (b 0))
(while (> ncolors 8)
(tty-color-define (format "color-%d" (- 88 ncolors))
(- 88 ncolors)
(mapcar #'xterm-rgb-convert-to-16bit
(list (nth r levels)
(nth g levels)
(nth b levels))))
(setq b (1+ b))
(if (> b 3)
(setq g (1+ g)
b 0))
(if (> g 3)
(setq r (1+ r)
g 0))
(setq ncolors (1- ncolors))))
;; Now the 8 gray colors
(while (> ncolors 0)
(setq color (xterm-rgb-convert-to-16bit
(floor
(if (= ncolors 8)
46.36363636
(+ (* (- 8 ncolors) 23.18181818) 69.54545454)))))
(tty-color-define (format "color-%d" (- 88 ncolors))
(- 88 ncolors)
(list color color color))
(setq ncolors (1- ncolors))))
(t (error "Unsupported number of xterm colors (%d)" (+ 16 ncolors)))))
;; Modifying color mappings means realized faces don't use the
;; right colors, so clear them.
(clear-face-cache)))