annotate lisp/ansi-color.el @ 34735:2d590f9a5d31

(delete_window, Fsplit_window) (Fset_window_configuration): Call ensure_frame_matrix.
author Gerd Moellmann <gerd@gnu.org>
date Wed, 20 Dec 2000 12:00:24 +0000
parents 5ad18c4ebe5c
children 75a8ca0bdd1d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
1 ;;; ansi-color.el --- translate ANSI into text-properties
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
3 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
5 ;; Author: Alex Schroeder <alex@gnu.org>
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
6 ;; Maintainer: Alex Schroeder <alex@gnu.org>
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
7 ;; Version: 2.4.0
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Keywords: comm processes
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify it
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; under the terms of the GNU General Public License as published by the
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; Free Software Foundation; either version 2, or (at your option) any
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; later version.
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;;
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful, but
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; General Public License for more details.
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;;
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
29 ;; This file provides a function that takes a string containing Select
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
30 ;; Graphic Rendition (SGR) control sequences (formerly known as ANSI
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
31 ;; escape sequences) and tries to replace these with text-properties.
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;;
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
33 ;; This allows you to run ls --color=yes in shell-mode: If
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
34 ;; `ansi-color-for-shell-mode' is non-nil, the SGR control sequences are
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
35 ;; translated into text-properties, colorizing the ls output. If
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
36 ;; `ansi-color-for-shell-mode' is nil, the SGR control sequences are
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
37 ;; stripped, making the ls output legible.
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
39 ;; 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
40 ;; 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
41 ;; 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
42 ;; "Graphic Rendition Combination Mode (GRCM)" implemented is
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
43 ;; "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
44 ;; that whenever possible, SGR control sequences are combined (ie. blue
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
45 ;; and bold).
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
47 ;; The basic functions are:
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;;
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
49 ;; `ansi-color-apply' to colorize a string containing SGR control
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
50 ;; sequences.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
51 ;;
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
52 ;; `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
53 ;; string.
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-apply-on-region' to colorize a region containing SGR
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
56 ;; control sequences.
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-filter-region' to filter SGR control sequences from a
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
59 ;; region.
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
60
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
61 ;; Instead of defining lots of new faces, this package uses
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
62 ;; text-properties as described in the elisp manual
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
63 ;; *Note (elisp)Special Properties::.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
64
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
65 ;;; Thanks
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
66
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
67 ;; 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
68 ;; 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
69 ;; of output and the filter functions.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
70 ;;
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
71 ;; Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk> for pointing me to ECMA-48.
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73
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 ;;; Code:
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
77 ;; Customization
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
78
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
79 (defgroup ansi-colors nil
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
80 "Translating SGR control sequences to text-properties.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
81 This translation effectively colorizes strings and regions based upon
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
82 SGR control sequences embedded in the text. SGR (Select Graphic
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
83 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
84 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
85 as a PDF file <URL:http://www.ecma.ch/ecma1/STAND/ECMA-048.HTM>."
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
86 :version "20.7"
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
87 :group 'processes)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
88
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
89 (defcustom ansi-color-faces-vector
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
90 [default bold default italic underline bold bold-italic modeline]
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
91 "Faces used for SGR control sequences determining a face.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
92 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
93 to 7.
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
95 Parameter Description Face used by default
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
96 0 default default
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
97 1 bold bold
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
98 2 faint default
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
99 3 italic italic
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
100 4 underlined underline
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
101 5 slowly blinking bold
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
102 6 rapidly blinking bold-italic
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
103 7 negative image modeline
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
105 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
106 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
107 :type '(vector face face face face face face face face)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
108 :set 'ansi-color-map-update
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
109 :initialize 'custom-initialize-default
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
110 :group 'ansi-colors)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
111
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
112 (defcustom ansi-color-names-vector
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 ["black" "red" "green" "yellow" "blue" "magenta" "cyan" "white"]
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
114 "Colors used for SGR control sequences determining a color.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
115 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
116 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
117
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
118 Parameter Color
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
119 30 40 black
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
120 31 41 red
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
121 32 42 green
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
122 33 43 yellow
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
123 34 44 blue
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
124 35 45 magenta
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
125 36 46 cyan
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
126 37 47 white
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
128 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
129 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
130 :type '(vector string string string string string string string string)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
131 :set 'ansi-color-map-update
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
132 :initialize 'custom-initialize-default
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
133 :group 'ansi-colors)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
134
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
135 (defcustom ansi-color-for-shell-mode nil
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
136 "Determine wether font-lock or ansi-color get to fontify shell buffers.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
137
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
138 If non-nil and `global-font-lock-mode' is non-nil, ansi-color will be
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
139 used. This adds `ansi-color-apply' to
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
140 `comint-preoutput-filter-functions' and removes
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
141 `ansi-color-filter-apply' for all shell-mode buffers.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
142
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
143 If non-nil and global-font-lock-mode is nil, both `ansi-color-apply' and
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
144 `ansi-color-filter-apply' will be removed from
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
145 `comint-preoutput-filter-functions' for all shell-mode buffers.
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
147 If nil, font-lock will be used (if it is enabled). This adds
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
148 `ansi-color-filter-apply' to `comint-preoutput-filter-functions' and
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
149 removes `ansi-color-apply' for all shell-mode buffers."
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
150 :version "20.8"
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
151 :type 'boolean
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
152 :set (function (lambda (symbol value)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
153 (set-default symbol value)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
154 (save-excursion
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
155 (let ((buffers (buffer-list))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
156 buffer)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
157 (while buffers
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
158 (setq buffer (car buffers)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
159 buffers (cdr buffers))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
160 (set-buffer buffer)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
161 (when (eq major-mode 'shell-mode)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
162 (if value
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
163 (if global-font-lock-mode
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
164 (progn
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
165 (font-lock-mode 0)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
166 (remove-hook 'comint-preoutput-filter-functions
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
167 'ansi-color-filter-apply)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
168 (add-hook 'comint-preoutput-filter-functions
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
169 'ansi-color-apply))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
170 (remove-hook 'comint-preoutput-filter-functions
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
171 'ansi-color-filter-apply)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
172 (remove-hook 'comint-preoutput-filter-functions
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
173 'ansi-color-apply))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
174 (if global-font-lock-mode
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
175 (font-lock-mode 1))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
176 (remove-hook 'comint-preoutput-filter-functions
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
177 'ansi-color-apply)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
178 (add-hook 'comint-preoutput-filter-functions
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
179 'ansi-color-filter-apply))))))))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
180 :initialize 'custom-initialize-reset
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
181 :group 'ansi-colors)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
182
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
183 (defconst ansi-color-regexp "\033\\[\\([0-9;]*\\)m"
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
184 "Regexp that matches SGR control sequences.")
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
185
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
186 (defconst ansi-color-parameter-regexp "\\([0-9]*\\)[m;]"
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
187 "Regexp that matches SGR control sequence parameters.")
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
188
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
189
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
190 ;; Main functions
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
192
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
193 (defun ansi-color-filter-apply (s)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
194 "Filter out all SGR control sequences from S.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
195
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
196 This function can be added to `comint-preoutput-filter-functions'."
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
197 (while (string-match ansi-color-regexp s)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
198 (setq s (replace-match "" t t s)))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
199 s)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
200
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
201
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
202 (defun ansi-color-filter-region (begin end)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
203 "Filter out all SGR control sequences from region START END.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
204
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
205 Returns the first point it is safe to start with. Used to speedup
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
206 further processing.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
207
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
208 Design to cope with arbitrary chunk of output such as the ones get by
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
209 comint-output-filter-functions, e.g.:
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
210
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
211 \(defvar last-context nil)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
212 \(make-variable-buffer-local 'last-context)
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
214 \(defun filter-out-color-in-buffer (s)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
215 \(setq last-context
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
216 \(ansi-color-filter-region
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
217 \(if last-context
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
218 last-context
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
219 \(if (marker-position comint-last-output-start)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
220 \(marker-position comint-last-output-start)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
221 1))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
222 \(marker-position (process-mark (get-buffer-process (current-buffer)))) ))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
223 s)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
224
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
225 \(add-hook 'comint-output-filter-functions 'filter-out-color-in-buffer)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
226 "
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
227 (let ((endm (copy-marker end)))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
228 (save-excursion
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
229 (goto-char begin)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
230 (while (re-search-forward ansi-color-regexp endm t)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
231 (replace-match ""))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
232 (if (re-search-forward "\033" endm t)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
233 (match-beginning 0)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
234 (marker-position endm)))))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
235
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
237 (defun ansi-color-apply (string)
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
238 "Translates SGR control sequences into text-properties.
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
239
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
240 Applies SGR control sequences setting foreground and background colors
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
241 to STRING and returns the result. The colors used are given in
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
242 `ansi-color-faces-vector' and `ansi-color-names-vector'.
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
244 This function can be added to `comint-preoutput-filter-functions'."
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
245 (let (face (start 0) end escape-sequence null-sequence result)
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
246 ;; find the next escape sequence
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
247 (while (setq end (string-match ansi-color-regexp string start))
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
248 ;; store escape sequence
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
249 (setq escape-sequence (match-string 1 string)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
250 null-sequence (string-equal escape-sequence ""))
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
251 ;; colorize the old block from start to end using old face
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
252 (if face
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
253 (put-text-property start end 'face face string))
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
254 (setq result (concat result (substring string start end))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
255 start (match-end 0))
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
256 ;; create new face by applying all the parameters in the escape sequence
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
257 (if null-sequence
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
258 (setq face nil)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
259 (setq face (ansi-color-get-face escape-sequence))))
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
260 (concat result (substring string start))))
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
262
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
263 (defun ansi-color-apply-on-region (begin end &optional context)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
264 "Translates SGR control sequences into text-properties.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
265
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
266 Applies SGR control sequences setting foreground and background colors
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
267 to text in region. The colors used are given in
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
268 `ansi-color-faces-vector' and `ansi-color-names-vector'.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
269 Returns a context than can be used to speedup further processing.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
270 Context is a (begin (start . face)) list.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
271
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
272 Design to cope with arbitrary chunk of output such as the ones get by
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
273 comint-output-filter-functions, e.g.:
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
274
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
275 \(defvar last-context nil)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
276 \(make-variable-buffer-local 'last-context)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
277
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
278 \(defun ansi-output-filter (s)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
279 \(setq last-context
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
280 \(ansi-color-apply-on-region
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
281 \(if last-context
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
282 \(car last-context)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
283 \(if (marker-position comint-last-output-start)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
284 \(marker-position comint-last-output-start)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
285 1))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
286 \(process-mark (get-buffer-process (current-buffer)))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
287 last-context ))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
288 s)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
289
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
290 \(add-hook 'comint-output-filter-functions 'ansi-output-filter)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
291 "
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
292 (let ((endm (copy-marker end))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
293 (face (if (and context (cdr context))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
294 (cdr (cdr context))))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
295 (face-start (if (and context (cdr context))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
296 (car (cdr context))))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
297 (next-safe-start begin)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
298 escape-sequence
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
299 null-sequence
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
300 stop )
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
301 (save-excursion
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
302 (goto-char begin)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
303 ;; find the next escape sequence
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
304 (while (setq stop (re-search-forward ansi-color-regexp endm t))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
305 ;; store escape sequence
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
306 (setq escape-sequence (match-string 1))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
307 (setq null-sequence (string-equal (match-string 1) ""))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
308 (setq next-safe-start (match-beginning 0))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
309 (if face
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
310 (put-text-property face-start next-safe-start 'face face)) ; colorize
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
311 (replace-match "") ; delete the ANSI sequence
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
312 (if null-sequence
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
313 (setq face nil)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
314 (setq face-start next-safe-start)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
315 (setq face (ansi-color-get-face escape-sequence))))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
316 (setq next-safe-start
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
317 (if (re-search-forward "\033" endm t)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
318 (match-beginning 0)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
319 (marker-position endm))))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
320 (cons next-safe-start
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
321 (if face
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
322 (cons face-start face))) ))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
323
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
324 ;; Helper functions
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
325
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
326 (defun ansi-color-make-color-map ()
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
327 "Creates a vector of face definitions and returns it.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
328
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
329 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
330 `ansi-color-map' for an example.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
331
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
332 The face definitions are based upon the variables
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
333 `ansi-color-faces-vector' and `ansi-color-names-vector'."
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
334 (let ((ansi-color-map (make-vector 50 nil))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
335 (index 0))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
336 ;; miscellaneous attributes
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
337 (mapcar
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
338 (function (lambda (e)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
339 (aset ansi-color-map index e)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
340 (setq index (1+ index)) ))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
341 ansi-color-faces-vector)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
342
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
343 ;; foreground attributes
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
344 (setq index 30)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
345 (mapcar
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
346 (function (lambda (e)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
347 (aset ansi-color-map index
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
348 (cons 'foreground-color e))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
349 (setq index (1+ index)) ))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
350 ansi-color-names-vector)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
351
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
352 ;; background attributes
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
353 (setq index 40)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
354 (mapcar
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
355 (function (lambda (e)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
356 (aset ansi-color-map index
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
357 (cons 'background-color e))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
358 (setq index (1+ index)) ))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
359 ansi-color-names-vector)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
360 ansi-color-map))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
361
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
362 (defvar ansi-color-map (ansi-color-make-color-map)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
363 "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
364
31595
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
365 The value of this variable is usually constructed by
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
366 `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
367 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
368 foreground or background colors.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
369
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
370 Example: The sequence \033[34m specifies a blue foreground. Therefore:
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
371 (aref ansi-color-map 34)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
372 => \(foreground-color . \"blue\")")
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
373
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
374 (defun ansi-color-map-update (symbol value)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
375 "Update `ansi-color-map'.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
376
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
377 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
378 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
379 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
380 (set-default symbol value)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
381 (setq ansi-color-map (ansi-color-make-color-map)))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
382
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
383 (defun ansi-color-get-face-1 (ansi-code)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
384 "Get face definition from `ansi-color-map'.
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
385 ANSI-CODE is used as an index into the vector."
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
386 (condition-case nil
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
387 (aref ansi-color-map ansi-code)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
388 ('args-out-of-range nil)))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
389
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
390 (defun ansi-color-get-face (escape-seq)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
391 "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
392
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
393 ESCAPE-SEQ is a SGR control sequences such as \033[34m. The parameter
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
394 34 is used by `ansi-color-get-face-1' to return a face definition."
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
395 (let ((ansi-color-r "[0-9][0-9]?")
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
396 (i 0)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
397 f)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
398 (while (string-match ansi-color-r escape-seq i)
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
399 (setq i (match-end 0))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
400 (add-to-list 'f
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
401 (ansi-color-get-face-1
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
402 (string-to-int (match-string 0 escape-seq) 10))))
5ad18c4ebe5c (ansi-colors): Doc change.
Gerd Moellmann <gerd@gnu.org>
parents: 26439
diff changeset
403 f))
25171
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (provide 'ansi-color)
b565998245c5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406
26092
8080bafbae4b Complete rewrite.
Gerd Moellmann <gerd@gnu.org>
parents: 25225
diff changeset
407 ;;; ansi-color.el ends here