;;; ansi-color.el --- translate ANSI escape sequences into faces
-;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
-;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2012 Free Software Foundation, Inc.
;; Author: Alex Schroeder <alex@gnu.org>
;; Maintainer: Alex Schroeder <alex@gnu.org>
;;
;; Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk> for pointing me to ECMA-48.
;;
-;; Stefan Monnier <foo@acm.com> explaing obscure font-lock stuff and
+;; Stefan Monnier <foo@acm.com> for explaining obscure font-lock stuff and for
;; code suggestions.
\f
37 47 white
This vector is used by `ansi-color-make-color-map' to create a color
-map. This color map is stored in the variable `ansi-color-map'."
- :type '(vector string string string string string string string string)
+map. This color map is stored in the variable `ansi-color-map'.
+
+Each element may also be a cons cell where the car and cdr specify the
+foreground and background colors, respectively."
+ :type '(vector (choice color (cons color color))
+ (choice color (cons color color))
+ (choice color (cons color color))
+ (choice color (cons color color))
+ (choice color (cons color color))
+ (choice color (cons color color))
+ (choice color (cons color color))
+ (choice color (cons color color)))
:set 'ansi-color-map-update
:initialize 'custom-initialize-default
:group 'ansi-colors)
:group 'ansi-colors
:version "23.2")
+(defvar ansi-color-apply-face-function 'ansi-color-apply-overlay-face
+ "Function for applying an Ansi Color face to text in a buffer.
+This function should accept three arguments: BEG, END, and FACE,
+and it should apply face FACE to the text between BEG and END.")
+
;;;###autoload
(defun ansi-color-for-comint-mode-on ()
"Set `ansi-color-for-comint-mode' to t."
(t
(ansi-color-apply-on-region start-marker end-marker)))))
-(add-hook 'comint-output-filter-functions
- 'ansi-color-process-output)
-
(defalias 'ansi-color-unfontify-region 'font-lock-default-unfontify-region)
(make-obsolete 'ansi-color-unfontify-region "not needed any more" "24.1")
;; Find the next SGR sequence.
(while (re-search-forward ansi-color-regexp end-marker t)
;; Colorize the old block from start to end using old face.
- (when face
- (ansi-color-set-extent-face
- (ansi-color-make-extent start-marker (match-beginning 0))
- face))
+ (funcall ansi-color-apply-face-function
+ start-marker (match-beginning 0)
+ face)
;; store escape sequence and new start position
(setq escape-sequence (match-string 1)
start-marker (copy-marker (match-end 0)))
(if (re-search-forward "\033" end-marker t)
(progn
;; if the rest of the region should have a face, put it there
- (when face
- (ansi-color-set-extent-face
- (ansi-color-make-extent start-marker (point))
- face))
+ (funcall ansi-color-apply-face-function
+ start-marker (point) face)
;; save face and point
(setq ansi-color-context-region
(list face (copy-marker (match-beginning 0)))))
;; if the rest of the region should have a face, put it there
- (if face
- (progn
- (ansi-color-set-extent-face
- (ansi-color-make-extent start-marker end-marker)
- face)
- (setq ansi-color-context-region (list face)))
- ;; reset context
- (setq ansi-color-context-region nil))))))
+ (funcall ansi-color-apply-face-function
+ start-marker end-marker face)
+ (setq ansi-color-context-region (if face (list face)))))))
+
+(defun ansi-color-apply-overlay-face (beg end face)
+ "Make an overlay from BEG to END, and apply face FACE.
+If FACE is nil, do nothing."
+ (when face
+ (ansi-color-set-extent-face
+ (ansi-color-make-extent beg end)
+ face)))
;; This function helps you look for overlapping overlays. This is
-;; usefull in comint-buffers. Overlapping overlays should not happen!
+;; useful in comint-buffers. Overlapping overlays should not happen!
;; A possible cause for bugs are the markers. If you create an overlay
;; up to the end of the region, then that end might coincide with the
;; process-mark. As text is added BEFORE the process-mark, the overlay
(mapc
(function (lambda (e)
(aset ansi-color-map index
- (ansi-color-make-face 'foreground e))
+ (ansi-color-make-face 'foreground
+ (if (consp e) (car e) e)))
(setq index (1+ index)) ))
ansi-color-names-vector)
;; background attributes
(mapc
(function (lambda (e)
(aset ansi-color-map index
- (ansi-color-make-face 'background e))
+ (ansi-color-make-face 'background
+ (if (consp e) (cdr e) e)))
(setq index (1+ index)) ))
ansi-color-names-vector)
ansi-color-map))
"Create a new face by applying all the parameters in ESCAPE-SEQ.
Should any of the parameters result in the default face (usually this is
-the parameter 0), then the effect of all previous parameters is cancelled.
+the parameter 0), then the effect of all previous parameters is canceled.
ESCAPE-SEQ is a SGR control sequences such as \\033[34m. The parameter
34 is used by `ansi-color-get-face-1' to return a face definition."