Saturday, February 21, 2009

Addendum and bugfix

In my last post, I had this code that would give colorful output in compilation mode. Well, it turns out that only works if your test output is very short and comes very quickly. For the toy Ruby spec I was using to develop it, that's true. For real specs, it's very much not.

Here's the original code:

(defadvice compilation-filter (before ansify-compilation-output activate)
(with-current-buffer (process-buffer (ad-get-arg 0))
(font-lock-mode -1)
(ad-set-arg 1 (ansi-color-apply (ad-get-arg 1))))


The problem is that turning off font-lock-mode strips all the colors from the current buffer's text. If your process produces multiple pieces of output, you get this effect sort of like a line of sparks. The rightmost few are bright and colorful, but they quickly fade out and become dull gray.

The fix is to turn off font-lock-mode only when it's on. That is, like so:

(defadvice compilation-filter (before ansify-compilation-output activate)
(with-current-buffer (process-buffer (ad-get-arg 0))
(if font-lock-mode (font-lock-mode -1))
(ad-set-arg 1 (ansi-color-apply (ad-get-arg 1)))))


Now the compilation process's output starts out and stays colorful.

No comments:

Post a Comment