]> granicus.if.org Git - neomutt/commitdiff
Add $header_color_partial to allow partial coloring of headers.
authorKevin McCarthy <kevin@8t8.us>
Tue, 9 May 2017 01:48:25 +0000 (18:48 -0700)
committerRichard Russon <rich@flatcap.org>
Fri, 12 May 2017 13:08:59 +0000 (14:08 +0100)
When set, a regexp match will color only the matched text in the
header.  When unset (the default), the entire header will have color
applied.

With appropriate regexps, this allows coloring of just the header
field name.  Of course, it can also be used to highlight arbitrary
phrases in the headers too.

doc/manual.xml.head
init.h
mutt.h
pager.c

index 2eb6616c7a1dd6cc58b91fc4a449b82383216761..39658c0f8093412d5ab2d4ab7511b389aa9baf5b 100644 (file)
@@ -3928,6 +3928,13 @@ folder-hook mutt "set sort=threads"
       <xref linkend="patterns" />) in the message index. Note that IMAP
       server-side searches (=b, =B, =h) are not supported for color index
       patterns.</para>
+      <para>When
+      <link linkend="header-color-partial">$header_color_partial</link>is unset
+      (the default), a
+      <emphasis>header</emphasis>matched by
+      <emphasis>regexp</emphasis>will have color applied to the entire header.
+      When set, color is applied only to the exact text matched by
+      <emphasis>regexp</emphasis>.</para>
       <para>
       <emphasis>object</emphasis>can be one of:</para>
       <itemizedlist>
diff --git a/init.h b/init.h
index b581340507a4222a797d623a194e25f01d9d4c43..4199d5c09aebb56cc009d54f0a0e1c2405671b74 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1130,6 +1130,17 @@ struct option_t MuttVars[] = {
   */
 #endif /* HAVE_GDBM || HAVE_BDB */
 #endif /* USE_HCACHE */
+  { "header_color_partial", DT_BOOL, R_PAGER | R_REFLOW, OPTHEADERCOLORPARTIAL, 0 },
+  /*
+  ** .pp
+  ** When \fIset\fP, color header regexps behave like color body regexps:
+  ** color is applied to the exact text matched by the regexp.  When
+  ** \fIunset\fP, color is applied to the entire header.
+  ** .pp
+  ** One use of this option might be to apply color to just the header labels.
+  ** .pp
+  ** See ``$color'' for more details.
+  */
   { "help",             DT_BOOL, R_REFLOW, OPTHELP, 1 },
   /*
   ** .pp
diff --git a/mutt.h b/mutt.h
index 527047f2a092e22041617178268991351d5e0f78..6a59d50da8e8ab17fa7f1f9f470848201f9dcc80 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -377,6 +377,7 @@ enum
 #endif
   OPTHDRS,
   OPTHEADER,
+  OPTHEADERCOLORPARTIAL,
   OPTHELP,
   OPTHIDDENHOST,
   OPTHIDELIMITED,
diff --git a/pager.c b/pager.c
index 8356bbd6e199f90bd17c782bb8a593df979aae66..48832cc21236ac1fb470095be998717f97d85b63 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -733,38 +733,48 @@ static void resolve_types(char *buf, char *raw, struct line_t *lineInfo, int n,
       if (n > 0 && (buf[0] == ' ' || buf[0] == '\t'))
       {
         lineInfo[n].type = lineInfo[n - 1].type; /* wrapped line */
-        (lineInfo[n].syntax)[0].color = (lineInfo[n - 1].syntax)[0].color;
-        lineInfo[n].is_cont_hdr = 1;
+        if (!option(OPTHEADERCOLORPARTIAL))
+        {
+          (lineInfo[n].syntax)[0].color = (lineInfo[n - 1].syntax)[0].color;
+          lineInfo[n].is_cont_hdr = 1;
+        }
       }
       else
       {
         lineInfo[n].type = MT_COLOR_HDEFAULT;
       }
 
-      for (color_line = ColorHdrList; color_line; color_line = color_line->next)
+      /* When this option is unset, we color the entire header the
+       * same color.  Otherwise, we handle the header patterns just
+       * like body patterns (further below).
+       */
+      if (!option(OPTHEADERCOLORPARTIAL))
       {
-        if (REGEXEC(color_line->rx, buf) == 0)
+        for (color_line = ColorHdrList; color_line; color_line = color_line->next)
         {
-          lineInfo[n].type = MT_COLOR_HEADER;
-          lineInfo[n].syntax[0].color = color_line->pair;
-          if (lineInfo[n].is_cont_hdr)
+          if (REGEXEC(color_line->rx, buf) == 0)
           {
-            /* adjust the previous continuation lines to reflect the color of this continuation line */
-            int j;
-            for (j = n - 1; j >= 0 && lineInfo[j].is_cont_hdr; --j)
-            {
-              lineInfo[j].type = lineInfo[n].type;
-              lineInfo[j].syntax[0].color = lineInfo[n].syntax[0].color;
-            }
-            /* now adjust the first line of this header field */
-            if (j >= 0)
+            lineInfo[n].type = MT_COLOR_HEADER;
+            lineInfo[n].syntax[0].color = color_line->pair;
+            if (lineInfo[n].is_cont_hdr)
             {
-              lineInfo[j].type = lineInfo[n].type;
-              lineInfo[j].syntax[0].color = lineInfo[n].syntax[0].color;
+              /* adjust the previous continuation lines to reflect the color of this continuation line */
+              int j;
+              for (j = n - 1; j >= 0 && lineInfo[j].is_cont_hdr; --j)
+              {
+                lineInfo[j].type = lineInfo[n].type;
+                lineInfo[j].syntax[0].color = lineInfo[n].syntax[0].color;
+              }
+              /* now adjust the first line of this header field */
+              if (j >= 0)
+              {
+                lineInfo[j].type = lineInfo[n].type;
+                lineInfo[j].syntax[0].color = lineInfo[n].syntax[0].color;
+              }
+              *force_redraw = 1; /* the previous lines have already been drawn on the screen */
             }
-            *force_redraw = 1; /* the previous lines have already been drawn on the screen */
+            break;
           }
-          break;
         }
       }
     }
@@ -834,7 +844,8 @@ static void resolve_types(char *buf, char *raw, struct line_t *lineInfo, int n,
     lineInfo[n].type = MT_COLOR_NORMAL;
 
   /* body patterns */
-  if (lineInfo[n].type == MT_COLOR_NORMAL || lineInfo[n].type == MT_COLOR_QUOTED)
+  if (lineInfo[n].type == MT_COLOR_NORMAL || lineInfo[n].type == MT_COLOR_QUOTED ||
+      (lineInfo[n].type == MT_COLOR_HDEFAULT && option(OPTHEADERCOLORPARTIAL)))
   {
     size_t nl;
 
@@ -853,7 +864,10 @@ static void resolve_types(char *buf, char *raw, struct line_t *lineInfo, int n,
 
       found = 0;
       null_rx = 0;
-      color_line = ColorBodyList;
+      if (lineInfo[n].type == MT_COLOR_HDEFAULT)
+        color_line = ColorHdrList;
+      else
+        color_line = ColorBodyList;
       while (color_line)
       {
         if (regexec(&color_line->rx, buf + offset, 1, pmatch, (offset ? REG_NOTBOL : 0)) == 0)