Commits

Anonymous committed b592852

allow regexps to match on continuation header lines in 'color header' commands.

closes #3373

  • Participants
  • Parent commits 25e1286
  • Branches HEAD

Comments (0)

Files changed (1)

   struct syntax_t *syntax;
   struct syntax_t *search;
   struct q_class_t *quote;
+  unsigned int is_cont_hdr; /* this line is a continuation of the previous header line */
 };
 
 #define ANSI_OFF       (1<<0)
 
   if (n == 0 || ISHEADER (lineInfo[n-1].type))
   {
-    if (buf[0] == '\n') {
+    if (buf[0] == '\n') /* end of header */
+    {
       lineInfo[n].type = MT_COLOR_NORMAL;
       getyx(stdscr, brailleLine, brailleCol);
-    } else 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;
     }
     else
     {
-      lineInfo[n].type = MT_COLOR_HDEFAULT;
-      color_line = ColorHdrList;
-      while (color_line)
+      /* if this is a continuation of the previous line, use the previous
+       * line's color as default. */
+      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;
+      }
+      else
+      {
+	lineInfo[n].type = MT_COLOR_HDEFAULT;
+      }
+
+      for (color_line = ColorHdrList; color_line; color_line = color_line->next)
       {
 	if (REGEXEC (color_line->rx, buf) == 0)
 	{
 	  lineInfo[n].type = MT_COLOR_HEADER;
 	  lineInfo[n].syntax[0].color = color_line->pair;
+	  if (lineInfo[n].is_cont_hdr)
+	  {
+	    /* 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 */
+	  }
 	  break;
 	}
-	color_line = color_line->next;
       }
     }
   }