Using skip-quoted the first unquoted line becomes the new top line
displayed in the pager. This leaves the user with no context to know
what the answer refers to.

Add an option to keep some lines of context when using skip-quoted.

With skip_quoted_context set to 5, skip-quoted will show at most 5 lines
of the previous quote. If the previous quote is shorter than 5 lines the
whole quote will be displayed.

Wrapped lines do not count towards skip_quoted_context. A line that is
wrapped once increases the number of displayed quoted lines in the pager
by one.

This option defaults to 0 to remain backwards compatible.

Signed-off-by: Rene Kita <m...@rkta.de>
---
 globals.h |  1 +
 init.h    |  8 +++++++
 pager.c   | 62 ++++++++++++++++++++++++++++++++++---------------------
 3 files changed, 48 insertions(+), 23 deletions(-)

diff --git a/globals.h b/globals.h
index 859732e6..8e5d708d 100644
--- a/globals.h
+++ b/globals.h
@@ -238,6 +238,7 @@ WHERE short ReadInc;
 WHERE short ReflowWrap;
 WHERE short SaveHist;
 WHERE short SendmailWait;
+WHERE short SkipQuotedContext;
 WHERE short SleepTime INITVAL (1);
 WHERE short TimeInc;
 WHERE short Timeout;
diff --git a/init.h b/init.h
index acc7d8b2..0cb527a5 100644
--- a/init.h
+++ b/init.h
@@ -3711,6 +3711,14 @@ struct option_t MuttVars[] = {
   ** If \fIset\fP, message sizes units will be displayed to the left of the 
number.
   ** See $formatstrings-size.
   */
+  { "skip_quoted_context",     DT_NUM, R_NONE, {.p=&SkipQuotedContext}, {.l=0} 
},
+  /*
+  ** .pp
+  ** Determines the number of lines of context to show before the unquoted text
+  ** when using skip-quoted. When set to a positive number at most that many 
lines
+  ** of the previous quote are displayed. If the previous quote is shorter the
+  ** whole quote is displayed.
+  */
   { "sleep_time",      DT_NUM, R_NONE, {.p=&SleepTime}, {.l=1} },
   /*
   ** .pp
diff --git a/pager.c b/pager.c
index 700af2d6..0eacf657 100644
--- a/pager.c
+++ b/pager.c
@@ -2571,35 +2571,51 @@ search_next:
       case OP_PAGER_SKIP_QUOTED:
        if (rd.has_types)
        {
+         int context;
          int dretval = 0;
+         int err = 0;
          int new_topline = rd.topline;
+         int num_quoted = 0;
 
-         while ((new_topline < rd.lastLine ||
-                 (0 == (dretval = display_line (rd.fp, &rd.last_pos, 
&rd.lineInfo,
-                        new_topline, &rd.lastLine, &rd.maxLine, MUTT_TYPES | 
(flags & MUTT_PAGER_NOWRAP),
-                         &rd.QuoteList, &rd.q_level, &rd.force_redraw, 
&rd.SearchRE, rd.pager_window))))
-                && rd.lineInfo[new_topline].type != MT_COLOR_QUOTED)
-           new_topline++;
+         while (!err && SkipQuotedContext > 0
+             && new_topline <= rd.topline + SkipQuotedContext
+             && new_topline != rd.lastLine){
+           num_quoted = 0;
+           while ((new_topline < rd.lastLine ||
+                   (0 == (dretval = display_line (rd.fp, &rd.last_pos, 
&rd.lineInfo,
+                          new_topline, &rd.lastLine, &rd.maxLine, MUTT_TYPES | 
(flags & MUTT_PAGER_NOWRAP),
+                          &rd.QuoteList, &rd.q_level, &rd.force_redraw, 
&rd.SearchRE, rd.pager_window))))
+                  && rd.lineInfo[new_topline].type != MT_COLOR_QUOTED)
+             new_topline++;
 
-         if (dretval < 0)
-         {
-           mutt_error _("No more quoted text.");
-           break;
+           if (dretval < 0)
+           {
+             mutt_error _("No more quoted text.");
+             err = 1;
+           }
+
+           while ((new_topline < rd.lastLine ||
+                   (0 == (dretval = display_line (rd.fp, &rd.last_pos, 
&rd.lineInfo,
+                          new_topline, &rd.lastLine, &rd.maxLine, MUTT_TYPES | 
(flags & MUTT_PAGER_NOWRAP),
+                          &rd.QuoteList, &rd.q_level, &rd.force_redraw, 
&rd.SearchRE, rd.pager_window))))
+                  && rd.lineInfo[new_topline].type == MT_COLOR_QUOTED)
+           {
+             new_topline++;
+             num_quoted++;
+           }
+
+           if (dretval < 0)
+           {
+             mutt_error _("No more unquoted text after quoted text.");
+             err = 1;
+           }
          }
-
-         while ((new_topline < rd.lastLine ||
-                 (0 == (dretval = display_line (rd.fp, &rd.last_pos, 
&rd.lineInfo,
-                        new_topline, &rd.lastLine, &rd.maxLine, MUTT_TYPES | 
(flags & MUTT_PAGER_NOWRAP),
-                         &rd.QuoteList, &rd.q_level, &rd.force_redraw, 
&rd.SearchRE, rd.pager_window))))
-                && rd.lineInfo[new_topline].type == MT_COLOR_QUOTED)
-           new_topline++;
-
-         if (dretval < 0)
-         {
-           mutt_error _("No more unquoted text after quoted text.");
+         if (err)
            break;
-         }
-         rd.topline = new_topline;
+         context = (SkipQuotedContext < num_quoted ? SkipQuotedContext : 
num_quoted);
+         if (new_topline - context < 0)
+                 context += new_topline - context;
+         rd.topline = new_topline - context;
        }
        break;
 
-- 
2.32.0

Reply via email to