On Thu, Dec 02, 1999 at 04:05:49PM -0600, Jeremy Blosser wrote:
> >      Subject: this is the subject
> >               ^^^^^^^^^^^^^^^^^^^
> >               this is highlighted
> 
> This is yet another concept from the ones discussed above.  Just so we keep
> track of what's being talked about, there have been 3 color issues
> mentioned so far:
> 
> 1) Q: Can Mutt color different parts of the same line different colors in the
>       message index?
>    A: No.
> 
> 2) Q: Can Mutt color different headers different colors in the pager?
>    A: Yes.
> 
> and now we have:
> 
> 3) Q: Can Mutt color different parts of the same header line different
>       colors in the pager?
>    A: No.

Let's add another one:

  4) Q: Can Mutt color different parts of the header like it can do with
        the body (color body foo bar regexp)?
     A: No.

(3) is very similar to (4) and could be accomplished like this:

  color header color2 ... ^Subject:.*$
  color header-part color1 ... ^Subject:
  color header-part color3 ... my@email\.address  # to show it's more
                                                  # powerful ;)

Would result in this:

  Subject: foo bar [EMAIL PROTECTED] baz
  ^^^^^^^^         ^^^^^^^^^^^^^^^^
   color1           color3

Everything else is in color2.

It would be pretty easy to implement.  I think.  A patch is attached.

Well, maybe not that easy.  The problem is that MT_COLOR_HEADER
overloads syntax[0].color for its default color.  And continuation lines
use syntax[0].first/last for their own purposes.

I added a new field to the syntax_t structure (int def_color) to
overcome the first problem.  And I think the second is not really a
problem because continuation lines are already successfully used with
syntax chunks in the body.  However I'm not sure if these two lines are
needed for anything else besides providing default color for
MT_COLOR_HEADER:

pager.c line 306 (after applying my patch), function append_line:
  (lineInfo[n+1].syntax)[0].color = (lineInfo[n].syntax)[0].color;

pager.c line 713, function resolve_types:
      (lineInfo[n].syntax)[0].color = (lineInfo[n-1].syntax)[0].color;

A patch is included (against vanilla mutt-1.1.1i).  This is my first try
to hack mutt, so I'd appreciate comments.  I should have probably
subscribed to mutt-dev before sending patches, but this one was not
planned.  After writing "it would be pretty easy to implement", I
decided to check if this was really so ;)

Marius Gedminas
-- 
I doubt, therefore I might be.
diff -urN mutt-1.1.1.orig/color.c mutt-1.1.1/color.c
--- mutt-1.1.1.orig/color.c     Wed Jul  7 00:40:25 1999
+++ mutt-1.1.1/color.c  Fri Dec  3 12:47:47 1999
@@ -29,6 +29,7 @@
 int ColorQuoteUsed;
 int ColorDefs[MT_COLOR_MAX];
 COLOR_LINE *ColorHdrList = NULL;
+COLOR_LINE *ColorHdrPartList = NULL;
 COLOR_LINE *ColorBodyList = NULL;
 COLOR_LINE *ColorIndexList = NULL;
 
@@ -82,6 +83,7 @@
   { "tilde",           MT_COLOR_TILDE },
   { "markers",         MT_COLOR_MARKERS },
   { "header",          MT_COLOR_HEADER },
+  { "hdrpart",         MT_COLOR_HDRPART },
   { "body",            MT_COLOR_BODY },
   { "message",         MT_COLOR_MESSAGE },
   { "attachment",      MT_COLOR_ATTACHMENT },
@@ -679,7 +681,8 @@
 
   /* extract a regular expression if needed */
   
-  if (object == MT_COLOR_HEADER || object == MT_COLOR_BODY || object == 
MT_COLOR_INDEX)
+  if (object == MT_COLOR_HEADER || object == MT_COLOR_HDRPART || 
+      object == MT_COLOR_BODY || object == MT_COLOR_INDEX)
   {
     if (!MoreArgs (s))
     {
@@ -714,6 +717,8 @@
   
   if (object == MT_COLOR_HEADER)
     r = add_pattern (&ColorHdrList, buf->data, 0, fg, bg, attr, err,0);
+  else if (object == MT_COLOR_HDRPART)
+    r = add_pattern (&ColorHdrPartList, buf->data, 1, fg, bg, attr, err, 0);
   else if (object == MT_COLOR_BODY)
     r = add_pattern (&ColorBodyList, buf->data, 1, fg, bg, attr, err, 0);
   else if (object == MT_COLOR_INDEX)
diff -urN mutt-1.1.1.orig/doc/manual.sgml.head mutt-1.1.1/doc/manual.sgml.head
--- mutt-1.1.1.orig/doc/manual.sgml.head        Thu Sep 23 23:01:43 1999
+++ mutt-1.1.1/doc/manual.sgml.head     Fri Dec  3 12:47:37 1999
@@ -949,8 +949,9 @@
 <item>body (match <em/regexp/ in the body of messages)
 <item>bold (hiliting bold patterns in the body of messages)
 <item>error (error messages printed by Mutt)
-<item>header (match <em/regexp/ in the message header)
+<item>header (match <em/regexp/ in the message header; highlight whole line)
 <item>hdrdefault (default color of the message header in the pager)
+<item>hdrpart (match <em/regexp/ in the message header)
 <item>index (match <em/pattern/ in the message index)
 <item>indicator (arrow or bar used to indicate the current item in a menu)
 <item>markers (the ``+'' markers at the beginning of wrapped lines in the pager)
diff -urN mutt-1.1.1.orig/doc/muttrc.man.head mutt-1.1.1/doc/muttrc.man.head
--- mutt-1.1.1.orig/doc/muttrc.man.head Wed Aug 18 08:54:13 1999
+++ mutt-1.1.1/doc/muttrc.man.head      Fri Dec  3 12:47:47 1999
@@ -132,8 +132,8 @@
 If your terminal supports color, these commands can be used to
 assign \fIforeground\fP/\fIbackgound\fP combinations to certain
 objects.  Valid objects are:
-.BR attachment ", " body ", " bold ", " header ", "
-.BR hdrdefault ", " index ", " indicator ", " markers ", "
+.BR attachment ", " body ", " bold ", " header ", " hdrdefaukt ", "
+.BR hdrpart ", " index ", " indicator ", " markers ", "
 .BR message ", " normal ", " quoted ", " quoted\fIN\fP ", "
 .BR search ", " signature ", " status ", " tilde ", " tree ", "
 .BR underline .
diff -urN mutt-1.1.1.orig/mutt_curses.h mutt-1.1.1/mutt_curses.h
--- mutt-1.1.1.orig/mutt_curses.h       Thu Jan  7 10:55:51 1999
+++ mutt-1.1.1/mutt_curses.h    Fri Dec  3 12:47:47 1999
@@ -109,6 +109,7 @@
   MT_COLOR_MARKERS,
   MT_COLOR_BODY,
   MT_COLOR_HEADER,
+  MT_COLOR_HDRPART,
   MT_COLOR_MESSAGE,
   MT_COLOR_ATTACHMENT,
   MT_COLOR_SEARCH,
@@ -134,6 +135,7 @@
 extern int ColorQuoteUsed;
 extern int ColorDefs[];
 extern COLOR_LINE *ColorHdrList;
+extern COLOR_LINE *ColorHdrPartList;
 extern COLOR_LINE *ColorBodyList;
 extern COLOR_LINE *ColorIndexList;
 
diff -urN mutt-1.1.1.orig/pager.c mutt-1.1.1/pager.c
--- mutt-1.1.1.orig/pager.c     Sun Nov  7 22:34:57 1999
+++ mutt-1.1.1/pager.c  Fri Dec  3 12:46:39 1999
@@ -106,6 +106,7 @@
   struct syntax_t *syntax;
   struct syntax_t *search;
   struct q_class_t *quote;
+  int def_color;
 };
 
 #define ANSI_OFF       (1<<0)
@@ -193,7 +194,7 @@
   if (!(flags & M_SHOWCOLOR))
     def_color = ColorDefs[MT_COLOR_NORMAL];
   else if (lineInfo[m].type == MT_COLOR_HEADER)
-    def_color = (lineInfo[m].syntax)[0].color;
+    def_color = lineInfo[m].def_color;
   else
     def_color = ColorDefs[lineInfo[m].type];
 
@@ -303,6 +304,7 @@
 
   lineInfo[n+1].type = lineInfo[n].type;
   (lineInfo[n+1].syntax)[0].color = (lineInfo[n].syntax)[0].color;
+  lineInfo[n+1].def_color = lineInfo[n].def_color;
   lineInfo[n+1].continuation = 1;
 
   /* find the real start of the line */
@@ -709,6 +711,7 @@
     {
       lineInfo[n].type = lineInfo[n-1].type; /* wrapped line */
       (lineInfo[n].syntax)[0].color = (lineInfo[n-1].syntax)[0].color;
+      lineInfo[n].def_color = lineInfo[n-1].def_color;
     }
     else
     {
@@ -719,7 +722,7 @@
        if (REGEXEC (color_line->rx, buf) == 0)
        {
          lineInfo[n].type = MT_COLOR_HEADER;
-         lineInfo[n].syntax[0].color = color_line->pair;
+         lineInfo[n].def_color = color_line->pair;
          break;
        }
        color_line = color_line->next;
@@ -793,7 +796,9 @@
 
   /* body patterns */
   if (lineInfo[n].type == MT_COLOR_NORMAL || 
-      lineInfo[n].type == MT_COLOR_QUOTED)
+      lineInfo[n].type == MT_COLOR_QUOTED ||
+      lineInfo[n].type == MT_COLOR_HDEFAULT ||
+      lineInfo[n].type == MT_COLOR_HEADER)
   {
     i = 0;
 
@@ -806,7 +811,9 @@
 
       found = 0;
       null_rx = 0;
-      color_line = ColorBodyList;
+      color_line = lineInfo[n].type == MT_COLOR_NORMAL || 
+                   lineInfo[n].type == MT_COLOR_QUOTED ? ColorBodyList 
+                                                      : ColorHdrPartList;
       while (color_line)
       {
        if (regexec (&color_line->rx, buf + offset, 1, pmatch,
@@ -1220,7 +1227,7 @@
   {
     m = ((*lineInfo)[n].continuation) ? ((*lineInfo)[n].syntax)[0].first : n;
     if ((*lineInfo)[m].type == MT_COLOR_HEADER)
-      def_color = ((*lineInfo)[m].syntax)[0].color;
+      def_color = (*lineInfo)[m].def_color;
     else
       def_color = (*lineInfo)[m].type;
 

Reply via email to