annotate lisp/ansi-color.el @ 112425:9f7614f1a892

Merge from emacs-23
author Glenn Morris <rgm@gnu.org>
date Sat, 22 Jan 2011 11:36:45 -0800
parents ef719132ddfa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
1 ;;; ansi-color.el --- translate ANSI escape sequences into faces
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
64762
41bb365f41c4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64091
diff changeset
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
112218
376148b31b5e Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 108671
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
6 ;; Author: Alex Schroeder <alex@gnu.org>
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
7 ;; Maintainer: Alex Schroeder <alex@gnu.org>
35305
64ea5b1e9d94 (ansi-colors) <defgroup>: Fix :version by Dave
Gerd Moellmann <gerd@gnu.org>
parents: 35207
diff changeset
8 ;; Version: 3.4.2
64ea5b1e9d94 (ansi-colors) <defgroup>: Fix :version by Dave
Gerd Moellmann <gerd@gnu.org>
parents: 35207
diff changeset
9 ;; Keywords: comm processes terminals services
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
15 ;; the Free Software Foundation, either version 3 of the License, or
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
16 ;; (at your option) any later version.
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
17
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
21 ;; GNU General Public License for more details.
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
22
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
28 ;; This file provides a function that takes a string or a region
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
29 ;; containing Select Graphic Rendition (SGR) control sequences (formerly
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
30 ;; known as ANSI escape sequences) and tries to translate these into
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
31 ;; faces.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
32 ;;
106441
973490180e7c Fix commentary to reflect that ansi-color is now enabled by default.
Chong Yidong <cyd@stupidchicken.com>
parents: 106439
diff changeset
33 ;; This allows you to run ls --color=yes in shell-mode. It is now
973490180e7c Fix commentary to reflect that ansi-color is now enabled by default.
Chong Yidong <cyd@stupidchicken.com>
parents: 106439
diff changeset
34 ;; enabled by default; to disable it, set ansi-color-for-comint-mode
973490180e7c Fix commentary to reflect that ansi-color is now enabled by default.
Chong Yidong <cyd@stupidchicken.com>
parents: 106439
diff changeset
35 ;; to nil.
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
36 ;;
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
37 ;; Note that starting your shell from within Emacs might set the TERM
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
38 ;; environment variable. The new setting might disable the output of
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
39 ;; SGR control sequences. Using ls --color=yes forces ls to produce
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
40 ;; these.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
41 ;;
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
42 ;; SGR control sequences are defined in section 3.8.117 of the ECMA-48
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
43 ;; standard (identical to ISO/IEC 6429), which is freely available as a
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
44 ;; PDF file <URL:http://www.ecma.ch/ecma1/STAND/ECMA-048.HTM>. The
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
45 ;; "Graphic Rendition Combination Mode (GRCM)" implemented is
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
46 ;; "cumulative mode" as defined in section 7.2.8. Cumulative mode means
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
47 ;; that whenever possible, SGR control sequences are combined (ie. blue
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
48 ;; and bold).
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
50 ;; The basic functions are:
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;;
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
52 ;; `ansi-color-apply' to colorize a string containing SGR control
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
53 ;; sequences.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
54 ;;
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
55 ;; `ansi-color-filter-apply' to filter SGR control sequences from a
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
56 ;; string.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
57 ;;
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
58 ;; `ansi-color-apply-on-region' to colorize a region containing SGR
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
59 ;; control sequences.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
60 ;;
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
61 ;; `ansi-color-filter-region' to filter SGR control sequences from a
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
62 ;; region.
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
63
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
64 ;;; Thanks
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
65
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
66 ;; Georges Brun-Cottan <gbruncot@emc.com> for improving ansi-color.el
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
67 ;; substantially by adding the code needed to cope with arbitrary chunks
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
68 ;; of output and the filter functions.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
69 ;;
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
70 ;; Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk> for pointing me to ECMA-48.
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
71 ;;
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
72 ;; Stefan Monnier <foo@acm.com> explaing obscure font-lock stuff and
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
73 ;; code suggestions.
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;;; Code:
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78
65285
a72d65bb7e3f (comint-last-output-start): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 64802
diff changeset
79 (defvar comint-last-output-start)
a72d65bb7e3f (comint-last-output-start): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 64802
diff changeset
80
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
81 ;; Customization
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
82
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
83 (defgroup ansi-colors nil
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
84 "Translating SGR control sequences to faces.
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
85 This translation effectively colorizes strings and regions based upon
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
86 SGR control sequences embedded in the text. SGR (Select Graphic
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
87 Rendition) control sequences are defined in section 3.8.117 of the
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
88 ECMA-48 standard \(identical to ISO/IEC 6429), which is freely available
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
89 as a PDF file <URL:http://www.ecma.ch/ecma1/STAND/ECMA-048.HTM>."
35207
16c26d4faf83 (ansi-colors) <defgroup>: Fix :version.
Gerd Moellmann <gerd@gnu.org>
parents: 35160
diff changeset
90 :version "21.1"
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
91 :group 'processes)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
92
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
93 (defcustom ansi-color-faces-vector
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
94 [default bold default italic underline bold bold-italic modeline]
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
95 "Faces used for SGR control sequences determining a face.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
96 This vector holds the faces used for SGR control sequence parameters 0
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
97 to 7.
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
99 Parameter Description Face used by default
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
100 0 default default
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
101 1 bold bold
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
102 2 faint default
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
103 3 italic italic
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
104 4 underlined underline
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
105 5 slowly blinking bold
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
106 6 rapidly blinking bold-italic
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
107 7 negative image modeline
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
109 Note that the symbol `default' is special: It will not be combined
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
110 with the current face.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
111
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
112 This vector is used by `ansi-color-make-color-map' to create a color
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
113 map. This color map is stored in the variable `ansi-color-map'."
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
114 :type '(vector face face face face face face face face)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
115 :set 'ansi-color-map-update
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
116 :initialize 'custom-initialize-default
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
117 :group 'ansi-colors)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
118
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
119 (defcustom ansi-color-names-vector
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 ["black" "red" "green" "yellow" "blue" "magenta" "cyan" "white"]
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
121 "Colors used for SGR control sequences determining a color.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
122 This vector holds the colors used for SGR control sequences parameters
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
123 30 to 37 \(foreground colors) and 40 to 47 (background colors).
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
124
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
125 Parameter Color
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
126 30 40 black
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
127 31 41 red
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
128 32 42 green
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
129 33 43 yellow
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
130 34 44 blue
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
131 35 45 magenta
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
132 36 46 cyan
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
133 37 47 white
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
135 This vector is used by `ansi-color-make-color-map' to create a color
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
136 map. This color map is stored in the variable `ansi-color-map'."
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
137 :type '(vector string string string string string string string string)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
138 :set 'ansi-color-map-update
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
139 :initialize 'custom-initialize-default
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
140 :group 'ansi-colors)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
141
102797
1c872d7c3c04 (ansi-color-get-face): Use
Andreas Schwab <schwab@linux-m68k.org>
parents: 100908
diff changeset
142 (defconst ansi-color-regexp "\033\\[\\([0-9;]*m\\)"
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
143 "Regexp that matches SGR control sequences.")
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
144
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
145 (defconst ansi-color-drop-regexp
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
146 "\033\\[\\([ABCDsuK]\\|2J\\|=[0-9]+[hI]\\|[0-9;]*[Hf]\\)"
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
147 "Regexp that matches ANSI control sequences to silently drop.")
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
148
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
149 (defconst ansi-color-parameter-regexp "\\([0-9]*\\)[m;]"
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
150 "Regexp that matches SGR control sequence parameters.")
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
151
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
152
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
153 ;; Convenience functions for comint modes (eg. shell-mode)
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
155
106439
f2a95599cf8c * shell.el (shell): Require ansi-color (Bug#5113).
Chong Yidong <cyd@stupidchicken.com>
parents: 105054
diff changeset
156 (defcustom ansi-color-for-comint-mode t
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
157 "Determines what to do with comint output.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
158 If nil, do nothing.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
159 If the symbol `filter', then filter all SGR control sequences.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
160 If anything else (such as t), then translate SGR control sequences
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
161 into text properties.
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
162
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
163 In order for this to have any effect, `ansi-color-process-output' must
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
164 be in `comint-output-filter-functions'.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
165
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
166 This can be used to enable colorized ls --color=yes output
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
167 in shell buffers. You set this variable by calling one of:
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
168 \\[ansi-color-for-comint-mode-on]
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
169 \\[ansi-color-for-comint-mode-off]
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
170 \\[ansi-color-for-comint-mode-filter]"
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
171 :type '(choice (const :tag "Do nothing" nil)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
172 (const :tag "Filter" filter)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
173 (const :tag "Translate" t))
106456
80fcf69fbcec * ansi-color.el (ansi-color-for-comint-mode): Add :version
Chong Yidong <cyd@stupidchicken.com>
parents: 106441
diff changeset
174 :group 'ansi-colors
80fcf69fbcec * ansi-color.el (ansi-color-for-comint-mode): Add :version
Chong Yidong <cyd@stupidchicken.com>
parents: 106441
diff changeset
175 :version "23.2")
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
176
35686
1126fb97e2d7 (ansi-color-for-comint-mode): Add :version.
Gerd Moellmann <gerd@gnu.org>
parents: 35305
diff changeset
177 ;;;###autoload
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
178 (defun ansi-color-for-comint-mode-on ()
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
179 "Set `ansi-color-for-comint-mode' to t."
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
180 (interactive)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
181 (setq ansi-color-for-comint-mode t))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
182
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
183 (defun ansi-color-for-comint-mode-off ()
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
184 "Set `ansi-color-for-comint-mode' to nil."
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
185 (interactive)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
186 (setq ansi-color-for-comint-mode nil))
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
187
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
188 (defun ansi-color-for-comint-mode-filter ()
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
189 "Set `ansi-color-for-comint-mode' to symbol `filter'."
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
190 (interactive)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
191 (setq ansi-color-for-comint-mode 'filter))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
192
35686
1126fb97e2d7 (ansi-color-for-comint-mode): Add :version.
Gerd Moellmann <gerd@gnu.org>
parents: 35305
diff changeset
193 ;;;###autoload
103087
aeca2cf7cbdb Change arg name to make it clear that it's ignored.
Chong Yidong <cyd@stupidchicken.com>
parents: 102797
diff changeset
194 (defun ansi-color-process-output (ignored)
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
195 "Maybe translate SGR control sequences of comint output into text properties.
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
196
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
197 Depending on variable `ansi-color-for-comint-mode' the comint output is
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
198 either not processed, SGR control sequences are filtered using
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
199 `ansi-color-filter-region', or SGR control sequences are translated into
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
200 text properties using `ansi-color-apply-on-region'.
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
201
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
202 The comint output is assumed to lie between the marker
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
203 `comint-last-output-start' and the process-mark.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
204
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
205 This is a good function to put in `comint-output-filter-functions'."
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
206 (let ((start-marker (or comint-last-output-start
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
207 (point-min-marker)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
208 (end-marker (process-mark (get-buffer-process (current-buffer)))))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
209 (cond ((eq ansi-color-for-comint-mode nil))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
210 ((eq ansi-color-for-comint-mode 'filter)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
211 (ansi-color-filter-region start-marker end-marker))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
212 (t
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
213 (ansi-color-apply-on-region start-marker end-marker)))))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
214
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
215 (add-hook 'comint-output-filter-functions
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
216 'ansi-color-process-output)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
217
111834
6951f234b0c3 * lisp/ansi-color.el (ansi-color-unfontify-region): Replace by trivial def.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110305
diff changeset
218 (defalias 'ansi-color-unfontify-region 'font-lock-default-unfontify-region)
6951f234b0c3 * lisp/ansi-color.el (ansi-color-unfontify-region): Replace by trivial def.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110305
diff changeset
219 (make-obsolete 'ansi-color-unfontify-region "not needed any more" "24.1")
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
220
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
221 ;; Working with strings
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
222 (defvar ansi-color-context nil
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
223 "Context saved between two calls to `ansi-color-apply'.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
224 This is a list of the form (FACES FRAGMENT) or nil. FACES is a list of
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
225 faces the last call to `ansi-color-apply' ended with, and FRAGMENT is a
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
226 string starting with an escape sequence, possibly the start of a new
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
227 escape sequence.")
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
228 (make-variable-buffer-local 'ansi-color-context)
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
229
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
230 (defun ansi-color-filter-apply (string)
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
231 "Filter out all ANSI control sequences from STRING.
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
232
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
233 Every call to this function will set and use the buffer-local variable
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
234 `ansi-color-context' to save partial escape sequences. This information
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
235 will be used for the next call to `ansi-color-apply'. Set
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
236 `ansi-color-context' to nil if you don't want this.
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
237
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
238 This function can be added to `comint-preoutput-filter-functions'."
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
239 (let ((start 0) end result)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
240 ;; if context was saved and is a string, prepend it
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
241 (if (cadr ansi-color-context)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
242 (setq string (concat (cadr ansi-color-context) string)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
243 ansi-color-context nil))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
244 ;; find the next escape sequence
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
245 (while (setq end (string-match ansi-color-regexp string start))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
246 (setq result (concat result (substring string start end))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
247 start (match-end 0)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
248 ;; save context, add the remainder of the string to the result
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
249 (let (fragment)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
250 (if (string-match "\033" string start)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
251 (let ((pos (match-beginning 0)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
252 (setq fragment (substring string pos)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
253 result (concat result (substring string start pos))))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
254 (setq result (concat result (substring string start))))
111834
6951f234b0c3 * lisp/ansi-color.el (ansi-color-unfontify-region): Replace by trivial def.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110305
diff changeset
255 (setq ansi-color-context (if fragment (list nil fragment))))
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
256 result))
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
258 (defun ansi-color-apply (string)
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
259 "Translates SGR control sequences into text properties.
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
260 Delete all other control sequences without processing them.
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
261
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
262 Applies SGR control sequences setting foreground and background colors
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
263 to STRING using text properties and returns the result. The colors used
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
264 are given in `ansi-color-faces-vector' and `ansi-color-names-vector'.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
265 See function `ansi-color-apply-sequence' for details.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
266
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
267 Every call to this function will set and use the buffer-local variable
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
268 `ansi-color-context' to save partial escape sequences and current face.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
269 This information will be used for the next call to `ansi-color-apply'.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
270 Set `ansi-color-context' to nil if you don't want this.
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271
111834
6951f234b0c3 * lisp/ansi-color.el (ansi-color-unfontify-region): Replace by trivial def.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110305
diff changeset
272 This function can be added to `comint-preoutput-filter-functions'."
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
273 (let ((face (car ansi-color-context))
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
274 (start 0) end escape-sequence result
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
275 colorized-substring)
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
276 ;; If context was saved and is a string, prepend it.
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
277 (if (cadr ansi-color-context)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
278 (setq string (concat (cadr ansi-color-context) string)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
279 ansi-color-context nil))
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
280 ;; Find the next escape sequence.
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
281 (while (setq end (string-match ansi-color-regexp string start))
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
282 (setq escape-sequence (match-string 1 string))
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
283 ;; Colorize the old block from start to end using old face.
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
284 (when face
111834
6951f234b0c3 * lisp/ansi-color.el (ansi-color-unfontify-region): Replace by trivial def.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110305
diff changeset
285 (put-text-property start end 'font-lock-face face string))
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
286 (setq colorized-substring (substring string start end)
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
287 start (match-end 0))
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
288 ;; Eliminate unrecognized ANSI sequences.
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
289 (while (string-match ansi-color-drop-regexp colorized-substring)
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
290 (setq colorized-substring
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
291 (replace-match "" nil nil colorized-substring)))
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
292 (push colorized-substring result)
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
293 ;; Create new face, by applying escape sequence parameters.
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
294 (setq face (ansi-color-apply-sequence escape-sequence face)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
295 ;; if the rest of the string should have a face, put it there
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
296 (when face
111834
6951f234b0c3 * lisp/ansi-color.el (ansi-color-unfontify-region): Replace by trivial def.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110305
diff changeset
297 (put-text-property start (length string) 'font-lock-face face string))
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
298 ;; save context, add the remainder of the string to the result
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
299 (let (fragment)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
300 (if (string-match "\033" string start)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
301 (let ((pos (match-beginning 0)))
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
302 (setq fragment (substring string pos))
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
303 (push (substring string start pos) result))
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
304 (push (substring string start) result))
111834
6951f234b0c3 * lisp/ansi-color.el (ansi-color-unfontify-region): Replace by trivial def.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110305
diff changeset
305 (setq ansi-color-context (if (or face fragment) (list face fragment))))
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
306 (apply 'concat (nreverse result))))
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
307
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
308 ;; Working with regions
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
310 (defvar ansi-color-context-region nil
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
311 "Context saved between two calls to `ansi-color-apply-on-region'.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
312 This is a list of the form (FACES MARKER) or nil. FACES is a list of
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
313 faces the last call to `ansi-color-apply-on-region' ended with, and
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
314 MARKER is a buffer position within an escape sequence or the last
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
315 position processed.")
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
316 (make-variable-buffer-local 'ansi-color-context-region)
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
317
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
318 (defun ansi-color-filter-region (begin end)
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
319 "Filter out all ANSI control sequences from region BEGIN to END.
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
320
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
321 Every call to this function will set and use the buffer-local variable
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
322 `ansi-color-context-region' to save position. This information will be
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
323 used for the next call to `ansi-color-apply-on-region'. Specifically,
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
324 it will override BEGIN, the start of the region. Set
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
325 `ansi-color-context-region' to nil if you don't want this."
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
326 (let ((end-marker (copy-marker end))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
327 (start (or (cadr ansi-color-context-region) begin)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
328 (save-excursion
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
329 (goto-char start)
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
330 ;; Delete unrecognized escape sequences.
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
331 (while (re-search-forward ansi-color-drop-regexp end-marker t)
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
332 (replace-match ""))
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
333 (goto-char start)
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
334 ;; Delete SGR escape sequences.
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
335 (while (re-search-forward ansi-color-regexp end-marker t)
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
336 (replace-match ""))
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
337 ;; save context, add the remainder of the string to the result
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
338 (if (re-search-forward "\033" end-marker t)
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
339 (setq ansi-color-context-region (list nil (match-beginning 0)))
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
340 (setq ansi-color-context-region nil)))))
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
341
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
342 (defun ansi-color-apply-on-region (begin end)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
343 "Translates SGR control sequences into overlays or extents.
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
344 Delete all other control sequences without processing them.
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
345
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
346 SGR control sequences are applied by setting foreground and
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
347 background colors to the text between BEGIN and END using
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
348 overlays. The colors used are given in `ansi-color-faces-vector'
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
349 and `ansi-color-names-vector'. See `ansi-color-apply-sequence'
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
350 for details.
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
351
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
352 Every call to this function will set and use the buffer-local variable
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
353 `ansi-color-context-region' to save position and current face. This
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
354 information will be used for the next call to
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
355 `ansi-color-apply-on-region'. Specifically, it will override BEGIN, the
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
356 start of the region and set the face with which to start. Set
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
357 `ansi-color-context-region' to nil if you don't want this."
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
358 (let ((face (car ansi-color-context-region))
49588
37645a051842 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 45250
diff changeset
359 (start-marker (or (cadr ansi-color-context-region)
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
360 (copy-marker begin)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
361 (end-marker (copy-marker end))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
362 escape-sequence)
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
363 ;; First, eliminate unrecognized ANSI control sequences.
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
364 (save-excursion
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
365 (goto-char start-marker)
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
366 (while (re-search-forward ansi-color-drop-regexp end-marker t)
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
367 (replace-match "")))
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
368 (save-excursion
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
369 (goto-char start-marker)
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
370 ;; Find the next SGR sequence.
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
371 (while (re-search-forward ansi-color-regexp end-marker t)
108671
1a054db83296 * ansi-color.el: Delete unused escape sequences (Bug#6085).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
372 ;; Colorize the old block from start to end using old face.
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
373 (when face
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
374 (ansi-color-set-extent-face
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
375 (ansi-color-make-extent start-marker (match-beginning 0))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
376 face))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
377 ;; store escape sequence and new start position
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
378 (setq escape-sequence (match-string 1)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
379 start-marker (copy-marker (match-end 0)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
380 ;; delete the escape sequence
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
381 (replace-match "")
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
382 ;; create new face by applying all the parameters in the escape
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
383 ;; sequence
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
384 (setq face (ansi-color-apply-sequence escape-sequence face)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
385 ;; search for the possible start of a new escape sequence
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
386 (if (re-search-forward "\033" end-marker t)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
387 (progn
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
388 ;; if the rest of the region should have a face, put it there
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
389 (when face
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
390 (ansi-color-set-extent-face
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
391 (ansi-color-make-extent start-marker (point))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
392 face))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
393 ;; save face and point
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
394 (setq ansi-color-context-region
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
395 (list face (copy-marker (match-beginning 0)))))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
396 ;; if the rest of the region should have a face, put it there
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
397 (if face
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
398 (progn
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
399 (ansi-color-set-extent-face
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
400 (ansi-color-make-extent start-marker end-marker)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
401 face)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
402 (setq ansi-color-context-region (list face)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
403 ;; reset context
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
404 (setq ansi-color-context-region nil))))))
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
405
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
406 ;; This function helps you look for overlapping overlays. This is
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
407 ;; usefull in comint-buffers. Overlapping overlays should not happen!
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
408 ;; A possible cause for bugs are the markers. If you create an overlay
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
409 ;; up to the end of the region, then that end might coincide with the
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
410 ;; process-mark. As text is added BEFORE the process-mark, the overlay
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
411 ;; will keep growing. Therefore, as more overlays are created later on,
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
412 ;; there will be TWO OR MORE overlays covering the buffer at that point.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
413 ;; This function helps you check your buffer for these situations.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
414 ; (defun ansi-color-debug-overlays ()
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
415 ; (interactive)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
416 ; (let ((pos (point-min)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
417 ; (while (< pos (point-max))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
418 ; (if (<= 2 (length (overlays-at pos)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
419 ; (progn
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
420 ; (goto-char pos)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
421 ; (error "%d overlays at %d" (length (overlays-at pos)) pos))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
422 ; (let (message-log-max)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
423 ; (message "Reached %d." pos)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
424 ; (setq pos (next-overlay-change pos)))))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
425
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
426 ;; Emacs/XEmacs compatibility layer
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
427
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
428 (defun ansi-color-make-face (property color)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
429 "Return a face with PROPERTY set to COLOR.
49588
37645a051842 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 45250
diff changeset
430 PROPERTY can be either symbol `foreground' or symbol `background'.
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
431
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
432 For Emacs, we just return the cons cell \(PROPERTY . COLOR).
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
433 For XEmacs, we create a temporary face and return it."
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
434 (if (featurep 'xemacs)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
435 (let ((face (make-face (intern (concat color "-" (symbol-name property)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
436 "Temporary face created by ansi-color."
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
437 t)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
438 (set-face-property face property color)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
439 face)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
440 (cond ((eq property 'foreground)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
441 (cons 'foreground-color color))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
442 ((eq property 'background)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
443 (cons 'background-color color))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
444 (t
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
445 (cons property color)))))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
446
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
447 (defun ansi-color-make-extent (from to &optional object)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
448 "Make an extent for the range [FROM, TO) in OBJECT.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
449
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
450 OBJECT defaults to the current buffer. XEmacs uses `make-extent', Emacs
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
451 uses `make-overlay'. XEmacs can use a buffer or a string for OBJECT,
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
452 Emacs requires OBJECT to be a buffer."
64802
4f150b99e062 (ansi-color-make-extent, ansi-color-set-extent-face):
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
453 (if (fboundp 'make-extent)
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
454 (make-extent from to object)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
455 ;; In Emacs, the overlay might end at the process-mark in comint
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
456 ;; buffers. In that case, new text will be inserted before the
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
457 ;; process-mark, ie. inside the overlay (using insert-before-marks).
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
458 ;; In order to avoid this, we use the `insert-behind-hooks' overlay
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
459 ;; property to make sure it works.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
460 (let ((overlay (make-overlay from to object)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
461 (overlay-put overlay 'modification-hooks '(ansi-color-freeze-overlay))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
462 overlay)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
463
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
464 (defun ansi-color-freeze-overlay (overlay is-after begin end &optional len)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
465 "Prevent OVERLAY from being extended.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
466 This function can be used for the `modification-hooks' overlay
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
467 property."
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
468 ;; if stuff was inserted at the end of the overlay
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
469 (when (and is-after
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
470 (= 0 len)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
471 (= end (overlay-end overlay)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
472 ;; reset the end of the overlay
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
473 (move-overlay overlay (overlay-start overlay) begin)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
474
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
475 (defun ansi-color-set-extent-face (extent face)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
476 "Set the `face' property of EXTENT to FACE.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
477 XEmacs uses `set-extent-face', Emacs uses `overlay-put'."
87941
d77b6e5ee8af * sieve.el (sieve-make-overlay, sieve-overlay-put, sieve-overlays-at):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87649
diff changeset
478 (if (featurep 'xemacs)
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
479 (set-extent-face extent face)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
480 (overlay-put extent 'face face)))
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
481
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
482 ;; Helper functions
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
483
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
484 (defun ansi-color-apply-sequence (escape-sequence faces)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
485 "Apply ESCAPE-SEQ to FACES and return the new list of faces.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
486
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
487 ESCAPE-SEQ is an escape sequences parsed by `ansi-color-get-face'.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
488
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
489 If the new faces start with the symbol `default', then the new
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
490 faces are returned. If the faces start with something else,
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
491 they are appended to the front of the FACES list, and the new
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
492 list of faces is returned.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
493
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
494 If `ansi-color-get-face' returns nil, then we either got a
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
495 null-sequence, or we stumbled upon some garbage. In either
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
496 case we return nil."
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
497 (let ((new-faces (ansi-color-get-face escape-sequence)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
498 (cond ((null new-faces)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
499 nil)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
500 ((eq (car new-faces) 'default)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
501 (cdr new-faces))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
502 (t
45250
21ed0daaa2c6 (ansi-color-get-face): Avoid add-to-list on local var.
Richard M. Stallman <rms@gnu.org>
parents: 41608
diff changeset
503 ;; Like (append NEW-FACES FACES)
21ed0daaa2c6 (ansi-color-get-face): Avoid add-to-list on local var.
Richard M. Stallman <rms@gnu.org>
parents: 41608
diff changeset
504 ;; but delete duplicates in FACES.
21ed0daaa2c6 (ansi-color-get-face): Avoid add-to-list on local var.
Richard M. Stallman <rms@gnu.org>
parents: 41608
diff changeset
505 (let ((modified-faces (copy-sequence faces)))
21ed0daaa2c6 (ansi-color-get-face): Avoid add-to-list on local var.
Richard M. Stallman <rms@gnu.org>
parents: 41608
diff changeset
506 (dolist (face (nreverse new-faces))
21ed0daaa2c6 (ansi-color-get-face): Avoid add-to-list on local var.
Richard M. Stallman <rms@gnu.org>
parents: 41608
diff changeset
507 (setq modified-faces (delete face modified-faces))
21ed0daaa2c6 (ansi-color-get-face): Avoid add-to-list on local var.
Richard M. Stallman <rms@gnu.org>
parents: 41608
diff changeset
508 (push face modified-faces))
21ed0daaa2c6 (ansi-color-get-face): Avoid add-to-list on local var.
Richard M. Stallman <rms@gnu.org>
parents: 41608
diff changeset
509 modified-faces)))))
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
510
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
511 (defun ansi-color-make-color-map ()
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
512 "Creates a vector of face definitions and returns it.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
513
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
514 The index into the vector is an ANSI code. See the documentation of
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
515 `ansi-color-map' for an example.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
516
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
517 The face definitions are based upon the variables
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
518 `ansi-color-faces-vector' and `ansi-color-names-vector'."
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
519 (let ((ansi-color-map (make-vector 50 nil))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
520 (index 0))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
521 ;; miscellaneous attributes
84856
2b87e65c55a0 (ansi-color-make-color-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78236
diff changeset
522 (mapc
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
523 (function (lambda (e)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
524 (aset ansi-color-map index e)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
525 (setq index (1+ index)) ))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
526 ansi-color-faces-vector)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
527 ;; foreground attributes
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
528 (setq index 30)
84856
2b87e65c55a0 (ansi-color-make-color-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78236
diff changeset
529 (mapc
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
530 (function (lambda (e)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
531 (aset ansi-color-map index
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
532 (ansi-color-make-face 'foreground e))
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
533 (setq index (1+ index)) ))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
534 ansi-color-names-vector)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
535 ;; background attributes
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
536 (setq index 40)
84856
2b87e65c55a0 (ansi-color-make-color-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78236
diff changeset
537 (mapc
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
538 (function (lambda (e)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
539 (aset ansi-color-map index
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
540 (ansi-color-make-face 'background e))
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
541 (setq index (1+ index)) ))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
542 ansi-color-names-vector)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
543 ansi-color-map))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
544
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
545 (defvar ansi-color-map (ansi-color-make-color-map)
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
546 "A brand new color map suitable for `ansi-color-get-face'.
25225
38f98813a83d (ansi-color-to-text-properties): Added New state 5
Karl Heuer <kwzh@gnu.org>
parents: 25171
diff changeset
547
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
548 The value of this variable is usually constructed by
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
549 `ansi-color-make-color-map'. The values in the array are such that the
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
550 numbers included in an SGR control sequences point to the correct
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
551 foreground or background colors.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
552
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
553 Example: The sequence \033[34m specifies a blue foreground. Therefore:
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
554 (aref ansi-color-map 34)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
555 => \(foreground-color . \"blue\")")
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
556
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
557 (defun ansi-color-map-update (symbol value)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
558 "Update `ansi-color-map'.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
559
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
560 Whenever the vectors used to construct `ansi-color-map' are changed,
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
561 this function is called. Therefore this function is listed as the :set
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
562 property of `ansi-color-faces-vector' and `ansi-color-names-vector'."
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
563 (set-default symbol value)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
564 (setq ansi-color-map (ansi-color-make-color-map)))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
565
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
566 (defun ansi-color-get-face-1 (ansi-code)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
567 "Get face definition from `ansi-color-map'.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
568 ANSI-CODE is used as an index into the vector."
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
569 (condition-case nil
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
570 (aref ansi-color-map ansi-code)
105054
c889dc6f230f (ansi-color-get-face-1): Fix typo in handler.
Glenn Morris <rgm@gnu.org>
parents: 103087
diff changeset
571 (args-out-of-range nil)))
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
572
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
573 (defun ansi-color-get-face (escape-seq)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
574 "Create a new face by applying all the parameters in ESCAPE-SEQ.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
575
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
576 Should any of the parameters result in the default face (usually this is
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
577 the parameter 0), then the effect of all previous parameters is cancelled.
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
578
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
579 ESCAPE-SEQ is a SGR control sequences such as \\033[34m. The parameter
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
580 34 is used by `ansi-color-get-face-1' to return a face definition."
102797
1c872d7c3c04 (ansi-color-get-face): Use
Andreas Schwab <schwab@linux-m68k.org>
parents: 100908
diff changeset
581 (let ((i 0)
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
582 f val)
102797
1c872d7c3c04 (ansi-color-get-face): Use
Andreas Schwab <schwab@linux-m68k.org>
parents: 100908
diff changeset
583 (while (string-match ansi-color-parameter-regexp escape-seq i)
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
584 (setq i (match-end 0)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
585 val (ansi-color-get-face-1
102797
1c872d7c3c04 (ansi-color-get-face): Use
Andreas Schwab <schwab@linux-m68k.org>
parents: 100908
diff changeset
586 (string-to-number (match-string 1 escape-seq) 10)))
35160
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
587 (cond ((not val))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
588 ((eq val 'default)
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
589 (setq f (list val)))
75a8ca0bdd1d (ansi-color-process-output): Use markers instead
Gerd Moellmann <gerd@gnu.org>
parents: 31595
diff changeset
590 (t
45250
21ed0daaa2c6 (ansi-color-get-face): Avoid add-to-list on local var.
Richard M. Stallman <rms@gnu.org>
parents: 41608
diff changeset
591 (unless (member val f)
21ed0daaa2c6 (ansi-color-get-face): Avoid add-to-list on local var.
Richard M. Stallman <rms@gnu.org>
parents: 41608
diff changeset
592 (push val f)))))
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
593 f))
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 (provide 'ansi-color)
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
597 ;;; ansi-color.el ends here