X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/51751aa26f9935609630f04e781a954b54ecc82e..4b2addb7e377f9a7601d78381025e343f776083c:/lisp/ansi-color.el diff --git a/lisp/ansi-color.el b/lisp/ansi-color.el index ff7edf40dc..6a82f17667 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. @@ -183,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." @@ -212,8 +217,12 @@ The comint output is assumed to lie between the marker `comint-last-output-start' and the process-mark. This is a good function to put in `comint-output-filter-functions'." - (let ((start-marker (or comint-last-output-start - (point-min-marker))) + (let ((start-marker (if (and (markerp comint-last-output-start) + (eq (marker-buffer comint-last-output-start) + (current-buffer)) + (marker-position comint-last-output-start)) + comint-last-output-start + (point-min-marker))) (end-marker (process-mark (get-buffer-process (current-buffer))))) (cond ((eq ansi-color-for-comint-mode nil)) ((eq ansi-color-for-comint-mode 'filter) @@ -221,9 +230,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") @@ -379,10 +385,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))) @@ -395,25 +400,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 @@ -585,7 +591,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."