Subject: Re: [PATCH] Add option for handling SGR control sequences in compilation-mode

From: Jim Porter <[email-masked]>
Date: Sat, 17 Jul 2021 13:57:41 -0700

One issue I've seen with handling SGR control sequences in
compilation-mode is that it can sometimes cause issues with grep-mode
and other similar modes in third-party packages. `grep-filter' also
handles SGR control sequences, but only works with full lines; this is
a simplification to (mostly) ensure that both the start and end of a
"match" highlight are present at the same time, so that `grep-filter'
can just use a simple regexp.

However, as far as I understand it, `ansi-color-apply-on-region' has
no such limitation and can handle parsing the *start* of some
highlighted text in one call to the function, and then handle the end
of it in another call. If, when grep is printing results, the output
is flushed in the middle of a match highlight, this results in the SGR
sequence to start a highlight being stripped by the time `grep-filter'
runs, so it's not able to fontify the match.

It might be nice if `grep-filter' were smart enough to work with the
output as-is rather than only operating on whole lines. That would
probably be more robust. However, for this patch, maybe it would be
enough to locally set `ansi-color-for-compilation-mode' to nil for
grep-mode.