File: ansi-color.el.html

This file provides a function that takes a string or a region containing Select Graphic Rendition (SGR) control sequences (formerly known as ANSI escape sequences) and tries to translate these into faces.

This allows you to run ls --color=yes in shell-mode. It is now enabled by default; to disable it, set ansi-color-for-comint-mode to nil.

Note that starting your shell from within Emacs might set the TERM environment variable. The new setting might disable the output of SGR control sequences. Using ls --color=yes forces ls to produce these.

SGR control sequences are defined in section 3.8.117 of the ECMA-48 standard (identical to ISO/IEC 6429), which is freely available as a PDF file <URL:https://www.ecma-international.org/publications/standards/Ecma-048.htm>. The "Graphic Rendition Combination Mode (GRCM)" implemented is
"cumulative mode" as defined in section 7.2.8. Cumulative mode
means that whenever possible, SGR control sequences are combined
(i.e. blue and bold).

The basic functions are:

ansi-color-apply to colorize a string containing SGR control sequences.

ansi-color-filter-apply to filter SGR control sequences from a string.

ansi-color-apply-on-region to colorize a region containing SGR control sequences.

ansi-color-filter-region to filter SGR control sequences from a region.

; Thanks

Georges Brun-Cottan <gbruncot@emc.com> for improving ansi-color.el substantially by adding the code needed to cope with arbitrary chunks of output and the filter functions.

Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk> for pointing me to ECMA-48.

Stefan Monnier <foo@acm.com> for explaining obscure font-lock stuff and for code suggestions.

Defined variables (15)

ansi-color--control-seq-fragment-regexpRegexp matching a partial ANSI control sequence.
ansi-color-apply-face-functionFunction for applying an Ansi Color face to text in a buffer.
ansi-color-basic-faces-vectorFaces used for SGR control sequences determining a face.
ansi-color-bold-is-brightIf set to non-nil, combining ANSI bold and a color produces the bright
ansi-color-bright-colors-vectorFaces used for SGR control sequences determining a "bright" color.
ansi-color-contextContext saved between two calls to ‘ansi-color-apply’.
ansi-color-context-regionContext saved between two calls to ‘ansi-color-apply-on-region’.
ansi-color-control-seq-regexpRegexp matching an ANSI control sequence.
ansi-color-faces-vectorFaces used for SGR control sequences determining a face.
ansi-color-for-comint-modeDetermines what to do with comint output.
ansi-color-for-compilation-modeDetermines what to do with compilation output.
ansi-color-mapA brand new color map, formerly suitable for ‘ansi-color-get-face’.
ansi-color-names-vectorColors used for SGR control sequences determining a color.
ansi-color-normal-colors-vectorFaces used for SGR control sequences determining a color.
ansi-color-parameter-regexpRegexp that matches SGR control sequence parameters.

Defined functions (24)

ansi-color--code-as-hex(COLOR)
ansi-color--ensure-context(CONTEXT-SYM POSITION)
ansi-color--face-vec-face(FACE-VEC)
ansi-color--update-face-vec(FACE-VEC ITERATOR)
ansi-color-apply(STRING)
ansi-color-apply-on-region(BEGIN END &optional PRESERVE-SEQUENCES)
ansi-color-apply-overlay-face(BEG END FACE)
ansi-color-apply-sequence(ESCAPE-SEQUENCE CODES)
ansi-color-apply-text-property-face(BEG END FACE)
ansi-color-compilation-filter()
ansi-color-filter-apply(STRING)
ansi-color-filter-region(BEGIN END)
ansi-color-for-comint-mode-filter()
ansi-color-for-comint-mode-off()
ansi-color-for-comint-mode-on()
ansi-color-freeze-overlay(OVERLAY IS-AFTER BEGIN END &optional LEN)
ansi-color-get-face-1(ANSI-CODE &optional BRIGHT)
ansi-color-make-color-map()
ansi-color-make-extent(FROM TO &optional BUFFER)
ansi-color-make-face(PROPERTY COLOR)
ansi-color-map-update(SYMBOL VALUE)
ansi-color-parse-sequence(ESCAPE-SEQ)
ansi-color-process-output(IGNORED)
ansi-color-set-extent-face(EXTENT FACE)

Defined faces (23)

ansi-color-blackFace used to render black color code.
ansi-color-blueFace used to render blue color code.
ansi-color-boldFace used to render bold text.
ansi-color-bright-blackFace used to render bright black color code.
ansi-color-bright-blueFace used to render bright blue color code.
ansi-color-bright-cyanFace used to render bright cyan color code.
ansi-color-bright-greenFace used to render bright green color code.
ansi-color-bright-magentaFace used to render bright magenta color code.
ansi-color-bright-redFace used to render bright red color code.
ansi-color-bright-whiteFace used to render bright white color code.
ansi-color-bright-yellowFace used to render bright yellow color code.
ansi-color-cyanFace used to render cyan color code.
ansi-color-faintFace used to render faint text.
ansi-color-fast-blinkFace used to render rapidly blinking text.
ansi-color-greenFace used to render green color code.
ansi-color-inverseFace used to render inverted video text.
ansi-color-italicFace used to render italic text.
ansi-color-magentaFace used to render magenta color code.
ansi-color-redFace used to render red color code.
ansi-color-slow-blinkFace used to render slowly blinking text.
ansi-color-underlineFace used to render underlined text.
ansi-color-whiteFace used to render white color code.
ansi-color-yellowFace used to render yellow color code.