X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/233ba4d924933cb56129bd7511e6137b7c0b8e3e..9805f81dda38cd541ba8043f44e720e06adf6492:/lisp/ansi-color.el diff --git a/lisp/ansi-color.el b/lisp/ansi-color.el index 2b43940c1b..15a543e959 100644 --- a/lisp/ansi-color.el +++ b/lisp/ansi-color.el @@ -1,6 +1,6 @@ ;;; ansi-color.el --- translate ANSI escape sequences into faces -;; Copyright (C) 1999-2011 Free Software Foundation, Inc. +;; Copyright (C) 1999-2012 Free Software Foundation, Inc. ;; Author: Alex Schroeder ;; Maintainer: Alex Schroeder @@ -68,7 +68,7 @@ ;; ;; Markus Kuhn for pointing me to ECMA-48. ;; -;; Stefan Monnier explaing obscure font-lock stuff and +;; Stefan Monnier for explaining obscure font-lock stuff and for ;; code suggestions. @@ -132,8 +132,18 @@ Parameter Color 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) @@ -173,6 +183,11 @@ in shell buffers. You set this variable by calling one of: :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." @@ -211,9 +226,6 @@ This is a good function to put in `comint-output-filter-functions'." (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") @@ -369,10 +381,9 @@ start of the region and set the face with which to start. Set ;; 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))) @@ -385,25 +396,26 @@ start of the region and set the face with which to start. Set (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 @@ -528,7 +540,8 @@ The face definitions are based upon the variables (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 @@ -536,7 +549,8 @@ The face definitions are based upon the variables (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)) @@ -573,7 +587,7 @@ ANSI-CODE is used as an index into the vector." "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."