diff options
author | Chong Yidong <cyd@gnu.org> | 2012-11-30 16:24:53 +0800 |
---|---|---|
committer | Chong Yidong <cyd@gnu.org> | 2012-11-30 16:24:53 +0800 |
commit | 276479fd709a6da85bbc6b267264db5c5a570f4e (patch) | |
tree | 2a69f3cbc4eab7fca9c04438e08b69de57e1711e /lisp/shell.el | |
parent | a813fe3fb8d13abe234169361ba2c5b0c747c5e9 (diff) | |
download | emacs-276479fd709a6da85bbc6b267264db5c5a570f4e.tar.gz |
In Shell mode, reapply ansi colorization if the mode is re-enabled.
* shell.el (shell-apply-ansi-color, shell-reapply-ansi-color): New functions.
(shell-mode): Use them to reapply ansi colorization if Shell mode is re-enabled.
Diffstat (limited to 'lisp/shell.el')
-rw-r--r-- | lisp/shell.el | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/lisp/shell.el b/lisp/shell.el index 38273311b61..fc8f3dfb940 100644 --- a/lisp/shell.el +++ b/lisp/shell.el @@ -561,10 +561,8 @@ buffer." ;; very inefficient in Shell buffers (e.g. Bug#10835). We use a ;; custom `ansi-color-apply-face-function' to convert color escape ;; sequences into `font-lock-face' properties. - (set (make-local-variable 'ansi-color-apply-face-function) - (lambda (beg end face) - (when face - (put-text-property beg end 'font-lock-face face)))) + (setq-local ansi-color-apply-face-function #'shell-apply-ansi-color) + (shell-reapply-ansi-color) ;; This is not really correct, since the shell buffer does not really ;; edit this directory. But it is useful in the buffer list and menus. @@ -603,6 +601,27 @@ buffer." 'shell-filter-ctrl-a-ctrl-b nil t))) (comint-read-input-ring t))) +(defun shell-apply-ansi-color (beg end face) + "Apply FACE as the ansi-color face for the text between BEG and END." + (when face + (put-text-property beg end 'ansi-color-face face) + (put-text-property beg end 'font-lock-face face))) + +(defun shell-reapply-ansi-color () + "Reapply ansi-color faces to the existing contents of the buffer." + (save-restriction + (widen) + (let* ((pos (point-min)) + (end (or (next-single-property-change pos 'ansi-color-face) + (point-max))) + face) + (while end + (if (setq face (get-text-property pos 'ansi-color-face)) + (put-text-property pos (or end (point-max)) + 'font-lock-face face)) + (setq pos end + end (next-single-property-change pos 'ansi-color-face)))))) + (defun shell-filter-ctrl-a-ctrl-b (string) "Remove `^A' and `^B' characters from comint output. |