I have a buffer with terminal escape codes in it and I want them to be colored:
I was able to do this with (ansi-color-apply-on-region (point-min) (point-max))
:
However, my file is really big and that command is really slow. Is there any mode that colors terminal escape codes with font lock? I imagine that would be much faster.
NOTE: What I am looking at is a log file, not a shell buffer, so solutions involving M-x shell
output are irrelevant to me.
font-lock-face
properties so that font-lock will show the colours is precisely whatansi-color-apply
is doing.ansi-color-apply
? In the question it looks like the entire buffer is converted at once, which is time consuming for large buffers. Normally, font-lock rules are only applied to the visible part of a buffer which makes them much faster.ansi-color-apply
deletes the ansi escape code characters from the text and adds text properties in their place. I didn't think that was a task for which font-lock was suitable, but you'll know much better than I do.invisible
text property without altering the actual text. In addition, ANSI sequences stretching over multiple lines may be problematic, since font-lock only highlights one or a few lines at a time.ansi-color-apply
andansi-color-apply-on-region
do things very differently! The former putsfont-lock-face
text properties on the string, while the latter creates overlays and placesface
properties on those.