On Mon, Jun 14, 2021 at 05:49:50AM -0700, Kevin J. McCarthy wrote:
I'll take a closer look at the patch in the next couple days.
While looking it over again, I noticed the patch had a few more issues.
The outer while loop shouldn't be really needed, because we shouldn't be looping repeatedly over those inner scans.
Its test 'SkipQuotedContext > 0' disabled <skip-quoted> when the context was 0 (as I noted before).
Also the test 'new_topline <= rd.topline + SkipQuotedContext' didn't quite make sense, because a large SkipQuotedContext could cause the function to skip one or more initial quotes and responses, if they were short.
I'm attaching a modified version of your patch that: - renames the variable to $pager_skip_quoted_context.- adds an initial scan for quoted lines if $pager_skip_quoted_context is greater than 0. If it finds more than $pager_skip_quoted_context initial quote lines it just recomputes context and redisplays. Otherwise it continues with the original <skip-quoted> scan, and recomputes context at the end of that.
- since num_quoted will be less than new_topline, removes the context variable and just subtracts MIN(PagerSkipQuotedContext, num_quoted).
- removes the commit comment about wrapped lines (they do in fact count, because display_line() is computing a single output line, not input line).
As with your patch, the change looks bigger than it is because of the indent changes. It's easier to see the change when diff ignores whitespace. I've pasted that version for pager.c below.
Since this is your idea and your work, I've purposely left you as Author in the commit.
I still need to test more when I have time tomorrow, so please let me know if there are problems with this version.
Thank you! modified pager.c @@ -2573,7 +2573,28 @@ search_next: { int dretval = 0; int new_topline = rd.topline; + int num_quoted = 0; + if (PagerSkipQuotedContext < 0) + PagerSkipQuotedContext = 0; + + /* Skip past previous "context" quoted lines */ + if (PagerSkipQuotedContext > 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++; + num_quoted++; + } + } + + if (num_quoted <= PagerSkipQuotedContext) + { + 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), @@ -2592,14 +2613,19 @@ search_next: 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."); break; } - rd.topline = new_topline; + } + + rd.topline = new_topline - MIN (PagerSkipQuotedContext, num_quoted); } break; -- Kevin J. McCarthy GPG Fingerprint: 8975 A9B3 3AA3 7910 385C 5308 ADEF 7684 8031 6BDA
From 4d382f133dc5196bf9972be6768069e40aa4b9e8 Mon Sep 17 00:00:00 2001 From: Rene Kita <m...@rkta.de> Date: Sun, 13 Jun 2021 15:56:58 +0200 Subject: [PATCH] Add skip_quoted_context option. 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. This option defaults to 0 to remain backwards compatible. --- globals.h | 1 + init.h | 9 +++++++ pager.c | 70 ++++++++++++++++++++++++++++++++++++++----------------- 3 files changed, 58 insertions(+), 22 deletions(-) diff --git a/globals.h b/globals.h index 859732e6..06ce410e 100644 --- a/globals.h +++ b/globals.h @@ -234,6 +234,7 @@ WHERE short HistSize; WHERE short MenuContext; WHERE short PagerContext; WHERE short PagerIndexLines; +WHERE short PagerSkipQuotedContext; WHERE short ReadInc; WHERE short ReflowWrap; WHERE short SaveHist; diff --git a/init.h b/init.h index acc7d8b2..26784882 100644 --- a/init.h +++ b/init.h @@ -2386,6 +2386,15 @@ struct option_t MuttVars[] = { ** is less than $$pager_index_lines, then the index will only use as ** many lines as it needs. */ + { "pager_skip_quoted_context", DT_NUM, R_NONE, {.p=&PagerSkipQuotedContext}, {.l=0} }, + /* + ** .pp + ** Determines the number of lines of context to show before the + ** unquoted text when using \fC$<skip-quoted>\fP. 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. + */ { "pager_stop", DT_BOOL, R_NONE, {.l=OPTPAGERSTOP}, {.l=0} }, /* ** .pp diff --git a/pager.c b/pager.c index 700af2d6..e65567f7 100644 --- a/pager.c +++ b/pager.c @@ -2573,33 +2573,59 @@ search_next: { int dretval = 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++; + if (PagerSkipQuotedContext < 0) + PagerSkipQuotedContext = 0; - if (dretval < 0) - { - mutt_error _("No more quoted text."); - break; - } + /* Skip past previous "context" quoted lines */ + if (PagerSkipQuotedContext > 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++; + num_quoted++; + } + } - 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 (num_quoted <= PagerSkipQuotedContext) + { + 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 unquoted text after quoted text."); - break; + 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."); + break; + } } - rd.topline = new_topline; + + rd.topline = new_topline - MIN (PagerSkipQuotedContext, num_quoted); } break; -- 2.30.2
signature.asc
Description: PGP signature