[PATCH] Add skip_quoted_context option

2021-06-13 Thread Rene Kita
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 
---
 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)
+ 

Re: [PATCH] Add skip_quoted_context option

2021-06-13 Thread Kevin J. McCarthy

On Sun, Jun 13, 2021 at 03:56:58PM +0200, Rene Kita wrote:

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.


I need to get through a backlog of other things before I look too 
closely at this.  However, I'd like others' opinions on the usefulness 
of the option.  My initial impression is that it's not generally useful 
(i.e., if you need context then don't ) but I'd appreciate 
others take.


Just glancing quickly, please watch the coding style.  e.g.
  while (test)
  {
  }
not
  while (test){
  }


+ while (!err && SkipQuotedContext > 0


It looks like the patch disables  if $skip_quoted_context 
is left at 0?



+ if (new_topline - context < 0)
+ context += new_topline - context;


Could that just be:
  if (context > new_topline)
context = new_topline;

Lastly, I'd prefer the config var have "pager_" in front to give it 
context.  (Pun intended).  e.e.  $pager_skip_quoted_context.


--
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA


signature.asc
Description: PGP signature


Re: [PATCH] Add skip_quoted_context option

2021-06-13 Thread Aaron Schrab

At 10:06 -0700 13 Jun 2021, "Kevin J. McCarthy"  wrote:
I need to get through a backlog of other things before I look too 
closely at this.  However, I'd like others' opinions on the usefulness 
of the option.  My initial impression is that it's not generally useful 
(i.e., if you need context then don't ) but I'd appreciate 
others take.


I'd definitely find this useful. I'll often use  to skip 
over large amounts (sometimes several pages) of quoted content, but then 
end up needing to scroll back up a few lines to get at least a bit of 
context.


signature.asc
Description: PGP signature


Re: GPG list keys search strings

2021-06-13 Thread Kevin J. McCarthy

On Wed, Jun 02, 2021 at 05:53:25PM +0200, Werner Koch wrote:

On Mon, 31 May 2021 15:08, Kevin J. McCarthy said:


Both the classic and GPGME code perform a strtok(" ,.:\"()<>\n") call
on the email address and personal name fields and discard parts
smaller than 4.  So searching for john@example.com will generate


I really don't know the origin.  I don't have old versions of Mutt or my
old mail archives online anymore and thus can't check easily.  I am
pretty sure it has always been there and I copied it only over to the
gpgme code.


Thank you Werner.  I think the strtok() makes some sense when searching 
against the personal field (to allow for missing middle names or 
initials etc).  But I can't think of any reason why this would be 
desirable for matching against the email address.


Since I've just released 2.1, I think now is a good time to try somewhat 
risky changes.  I'm going to change it to directly add the email address 
to the hints list.


--
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA


signature.asc
Description: PGP signature