<<< Date Index >>>     <<< Thread Index >>>

Re: Multi-Line Color Highlighting



On 2008-02-03, Mun Johl <Mun.Johl@xxxxxxxxxx> wrote:
> (Sorry, I didn't provide a sufficient subject on the original post.)
> 
> Hi,
> 
> I was wondering if there is a way to highlight a mulit-line regex in the
> body of a message?  I am trying to use "color body ..." to highlight a
> multi-line description in our bug tracking tool but I'm not certain if
> mutt's highlighting feature even supports such an option.  And I didn't
> see anything one way or the other in the manual.

What I have done to achieve this is to create a display_filter using 
Perl to add ANSI color escape sequences around the text I wanted to 
highlight.  I also add "set allow_ansi" in my muttrc so that mutt 
will pass these escape sequences through to the terminal.  I use 
message-hooks to enable the various display_filters.  Here's part of 
one display_filter.

   perl -00 -pe 's/^(IN THIS ISSUE)/\e[1m\1\e[0m/s;
                 s/^(LOCAL NEWS)/\e[1m\1\e[0m/s;
                 if (m/^((\(.*\))?[^a-z]*?[a-z]?[^a-z]*?)(\s--\s.*)/s) {
                     $heading = $1;
                     $part2 = $3;                  # Save this for printing 
later.
                     $heading =~ s/^/\e[1m/s;      # Turn on highlighting at 
start of heading.
                     $heading =~ s/$/\e[0m/s;      # Turn off highlighting at 
end of heading.
                     $heading =~ s/\n/\n\e[1m/gs;  # Turn on highlighting at 
start of every line within heading.
                     $_ = $heading . $part2;
                 }'

This highlights a few section headings in a newsletter, including 
in-line headings from the start of a paragraph to the first 
occurrence of "--", provided there is no more than one lower-case 
letter in that interval.

I wrote this when I had built mutt with slang.  It seemed at the 
time that either mutt or slang turned off highlighting at the end of 
every line, so I had to turn it on at the start of every line within 
the highlighted region.  I now use ncurses instead of slang, and the 
script still works, but I haven't checked to see whether turning on 
highlighting at the start of every highlighted line is still 
necessary.

HTH,
Gary