aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2012-11-30 16:24:53 +0800
committerChong Yidong2012-11-30 16:24:53 +0800
commit276479fd709a6da85bbc6b267264db5c5a570f4e (patch)
tree2a69f3cbc4eab7fca9c04438e08b69de57e1711e
parenta813fe3fb8d13abe234169361ba2c5b0c747c5e9 (diff)
downloademacs-276479fd709a6da85bbc6b267264db5c5a570f4e.tar.gz
emacs-276479fd709a6da85bbc6b267264db5c5a570f4e.zip
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.
-rw-r--r--lisp/ChangeLog3
-rw-r--r--lisp/shell.el27
2 files changed, 26 insertions, 4 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 4a128e10925..7f908129afa 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -2,6 +2,9 @@
2 2
3 * shell.el (shell): For C-u M-x shell, use an inactive shell 3 * shell.el (shell): For C-u M-x shell, use an inactive shell
4 buffer as the default (Bug#1975). 4 buffer as the default (Bug#1975).
5 (shell-apply-ansi-color, shell-reapply-ansi-color): New functions.
6 (shell-mode): Use them to reapply ansi colorization if Shell mode
7 is re-enabled.
5 8
62012-11-30 Yuriy Vostrikov <delamonpansie@gmail.com> (tiny change) 92012-11-30 Yuriy Vostrikov <delamonpansie@gmail.com> (tiny change)
7 10
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."
561 ;; very inefficient in Shell buffers (e.g. Bug#10835). We use a 561 ;; very inefficient in Shell buffers (e.g. Bug#10835). We use a
562 ;; custom `ansi-color-apply-face-function' to convert color escape 562 ;; custom `ansi-color-apply-face-function' to convert color escape
563 ;; sequences into `font-lock-face' properties. 563 ;; sequences into `font-lock-face' properties.
564 (set (make-local-variable 'ansi-color-apply-face-function) 564 (setq-local ansi-color-apply-face-function #'shell-apply-ansi-color)
565 (lambda (beg end face) 565 (shell-reapply-ansi-color)
566 (when face
567 (put-text-property beg end 'font-lock-face face))))
568 566
569 ;; This is not really correct, since the shell buffer does not really 567 ;; This is not really correct, since the shell buffer does not really
570 ;; edit this directory. But it is useful in the buffer list and menus. 568 ;; edit this directory. But it is useful in the buffer list and menus.
@@ -603,6 +601,27 @@ buffer."
603 'shell-filter-ctrl-a-ctrl-b nil t))) 601 'shell-filter-ctrl-a-ctrl-b nil t)))
604 (comint-read-input-ring t))) 602 (comint-read-input-ring t)))
605 603
604(defun shell-apply-ansi-color (beg end face)
605 "Apply FACE as the ansi-color face for the text between BEG and END."
606 (when face
607 (put-text-property beg end 'ansi-color-face face)
608 (put-text-property beg end 'font-lock-face face)))
609
610(defun shell-reapply-ansi-color ()
611 "Reapply ansi-color faces to the existing contents of the buffer."
612 (save-restriction
613 (widen)
614 (let* ((pos (point-min))
615 (end (or (next-single-property-change pos 'ansi-color-face)
616 (point-max)))
617 face)
618 (while end
619 (if (setq face (get-text-property pos 'ansi-color-face))
620 (put-text-property pos (or end (point-max))
621 'font-lock-face face))
622 (setq pos end
623 end (next-single-property-change pos 'ansi-color-face))))))
624
606(defun shell-filter-ctrl-a-ctrl-b (string) 625(defun shell-filter-ctrl-a-ctrl-b (string)
607 "Remove `^A' and `^B' characters from comint output. 626 "Remove `^A' and `^B' characters from comint output.
608 627