emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r111039: In Shell mode, reapply ansi


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111039: In Shell mode, reapply ansi colorization if the mode is re-enabled.
Date: Fri, 30 Nov 2012 16:24:53 +0800
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111039
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Fri 2012-11-30 16:24:53 +0800
message:
  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.
modified:
  lisp/ChangeLog
  lisp/shell.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-11-30 08:06:04 +0000
+++ b/lisp/ChangeLog    2012-11-30 08:24:53 +0000
@@ -2,6 +2,9 @@
 
        * shell.el (shell): For C-u M-x shell, use an inactive shell
        buffer as the default (Bug#1975).
+       (shell-apply-ansi-color, shell-reapply-ansi-color): New functions.
+       (shell-mode): Use them to reapply ansi colorization if Shell mode
+       is re-enabled.
 
 2012-11-30  Yuriy Vostrikov  <address@hidden>  (tiny change)
 

=== modified file 'lisp/shell.el'
--- a/lisp/shell.el     2012-11-30 08:06:04 +0000
+++ b/lisp/shell.el     2012-11-30 08:24:53 +0000
@@ -561,10 +561,8 @@
   ;; 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 @@
                   '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.
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]