diff options
author | Chong Yidong <cyd@gnu.org> | 2012-02-19 21:59:42 +0800 |
---|---|---|
committer | Chong Yidong <cyd@gnu.org> | 2012-02-19 21:59:42 +0800 |
commit | 0fd40f8951f1aaa387e78999ecfbf6bc954ccf8a (patch) | |
tree | 48386211397064dd0eb1bc47fb0a292e3ad4e19f /lisp/ansi-color.el | |
parent | 2375c96a71874756c132de1d0508a224c0fea0ab (diff) | |
download | emacs-0fd40f8951f1aaa387e78999ecfbf6bc954ccf8a.tar.gz emacs-0fd40f8951f1aaa387e78999ecfbf6bc954ccf8a.tar.bz2 emacs-0fd40f8951f1aaa387e78999ecfbf6bc954ccf8a.zip |
Use text properties for color escape highlighting in Shell mode.
* ansi-color.el: Don't set comint-output-filter-functions; it is
now in the initial value defined in comint.el.
(ansi-color-apply-face-function): New variable.
(ansi-color-apply-on-region): Use it.
(ansi-color-apply-overlay-face): New function.
* comint.el: Require ansi-color.
(comint-output-filter-functions): Add ansi-color-process-output.
* shell.el (shell): No need to require ansi-color.
(shell-mode): Use ansi-color-apply-face-function to highlight
color escapes using font-lock-face property.
Fixes: debbugs:10835
Diffstat (limited to 'lisp/ansi-color.el')
-rw-r--r-- | lisp/ansi-color.el | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/lisp/ansi-color.el b/lisp/ansi-color.el index aaea903de56..15a543e9591 100644 --- a/lisp/ansi-color.el +++ b/lisp/ansi-color.el @@ -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." @@ -221,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") @@ -379,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))) @@ -395,22 +396,23 @@ 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 ;; useful in comint-buffers. Overlapping overlays should not happen! |