<<< Date Index >>>     <<< Thread Index >>>

[PATCH] display search progress with $search_inc



Hi,

* Vincent Lefevre [06-11-13 15:30:28 +0100] wrote:
On 2006-11-13 12:06:55 +0000, Rocco Rutte wrote:

The attached patch prints some progress for both cases. The second part for the "plain" search looks a little strange when messing with the 'msg' variable and mutt_clear_error() in case we have a match. But I didn't really find another way to not loose the 'wrapped to top|bottom' messages which are composed even before matching a single message.

This could be a nice patch, but it makes the limit function very slow,
at least when applying it on headers, e.g. ~ffoo: instead of being
immediate, the limit now takes about 6 seconds on my 52500-message
mailbox.

I know, but the pattern is quite trivial. The problem are more those cases where do you limit on ~bfoo for a 52k maildir folder (where mutt needs to perform lots of I/O for looking at 52k files with regex).

* Vincent Lefevre [06-11-13 15:37:42 +0100] wrote:
On 2006-11-13 12:06:55 +0000, Rocco Rutte wrote:

Another thing I'm not sure about: should we add something like $search_inc analogous to $read_inc and $write_inc? On fast systems with totally trivial searches it can be quite expensive to update the search progress for each single message...

Hmm... I now understand what you mean by that (my terminal doesn't
display everything, so I was wondering...). IMHO, the update of the
search progress should be time-based, e.g. every second should be
sufficient.

I don't think time-based is a good alternative to $search_inc. The reason is quite simple: when you have 52k messages then mutt needs to query the time 52k times. And if the search is trivial so that search/limit is done in <1 second, it will slow things down drastically. And then mutt will display progress even if there's no need to since getting the time takes so long. And working around this with alarm() or friends is no option, IMHO.

Anyway, thanks for quick feedback!

Attached is take #2 which adds $search_inc along with an entry in UPDATING. The default is 0 which means no progress. Compared to the first patch one more message is gone... so that with the default value the behaviour is exactly as it was before (...which is mutt policy if I recall correctly).

As some first tests showed, a value of 10 looks okay so that could be another option if the patch gets accepted...

  bye, Rocco
--
:wq!
diff --git a/UPDATING b/UPDATING
index 2eff364..0915341 100644
--- a/UPDATING
+++ b/UPDATING
@@ -4,6 +4,10 @@ mutt. Please read this file carefully wh
 The keys used are:
   !: modified feature, -: deleted feature, +: new feature
 
+CVS HEAD:
+
+ + $search_inc added to indicate search progress, defaults to 0
+
 1.5.13 (2006-08-14):
 
  + thread patterns.  Use ~(...) to match all threads that
diff --git a/globals.h b/globals.h
index fa89fdb..0e81c46 100644
--- a/globals.h
+++ b/globals.h
@@ -198,6 +198,7 @@ WHERE short MenuContext;
 WHERE short PagerContext;
 WHERE short PagerIndexLines;
 WHERE short ReadInc;
+WHERE short SearchInc;
 WHERE short SendmailWait;
 WHERE short SleepTime INITVAL (1);
 WHERE short Timeout;
diff --git a/init.h b/init.h
index 0cf79b3..136baaf 100644
--- a/init.h
+++ b/init.h
@@ -2440,6 +2440,15 @@ struct option_t MuttVars[] = {
   ** .pp
   ** Also see the ``$$force_name'' variable.
   */
+  { "search_inc",      DT_NUM,  R_NONE, UL &SearchInc, 0 },
+  /*
+  ** .pp
+  ** If set to a value greater than 0, Mutt will display which message it
+  ** is currently searching on when performing either a search or a limit
+  ** request. The message is printed after \fIsearch_inc\fP messages have
+  ** been considered. When set to 0, only a single message will appear
+  ** when starting to search.
+  */
   { "score",           DT_BOOL, R_NONE, OPTSCORE, 1 },
   /*
   ** .pp
diff --git a/pattern.c b/pattern.c
index 1ce81f2..133ced5 100644
--- a/pattern.c
+++ b/pattern.c
@@ -1262,6 +1262,7 @@ int mutt_pattern_func (int op, char *pro
   char buf[LONG_STRING] = "", *simple, error[STRING];
   BUFFER err;
   int i;
+  CONTEXT *ctx = Context;
 
   strfcpy (buf, NONULL (Context->pattern), sizeof (buf));
   if (mutt_get_field (prompt, buf, sizeof (buf), M_PATTERN | M_CLEAR) != 0 || 
!buf[0])
@@ -1298,6 +1299,9 @@ int mutt_pattern_func (int op, char *pro
 
     for (i = 0; i < Context->msgcount; i++)
     {
+      if ((!ctx || !ctx->quiet) && SearchInc && ((i % SearchInc) == 0 || i == 
0))
+       mutt_message (_("Executing command on matching messages (%d/%d)..."),
+                     i+1, Context->msgcount);
       /* new limit pattern implicitly uncollapses all threads */
       Context->hdrs[i]->virtual = -1;
       Context->hdrs[i]->limited = 0;
@@ -1318,6 +1322,9 @@ int mutt_pattern_func (int op, char *pro
   {
     for (i = 0; i < Context->vcount; i++)
     {
+      if ((!ctx || !ctx->quiet) && SearchInc && ((i % SearchInc) == 0 || i == 
0))
+       mutt_message (_("Executing command on matching messages (%d/%d)..."),
+                     i+1, Context->vcount);
       if (mutt_pattern_exec (pat, M_MATCH_FULL_ADDRESS, Context, 
Context->hdrs[Context->v2r[i]]))
       {
        switch (op)
@@ -1375,7 +1382,9 @@ int mutt_search_command (int cur, int op
   BUFFER err;
   int incr;
   HEADER *h;
-  
+  const char *msg = NULL;
+  CONTEXT *ctx = Context;
+
   if (op != OP_SEARCH_NEXT && op != OP_SEARCH_OPPOSITE)
   {
     strfcpy (buf, LastSearch, sizeof (buf));
@@ -1433,11 +1442,14 @@ int mutt_search_command (int cur, int op
 
   for (i = cur + incr, j = 0 ; j != Context->vcount; j++)
   {
+    if ((!ctx || !ctx->quiet) && SearchInc && ((j % SearchInc) == 0 || j == 0))
+      mutt_message(_("Searching (%d/%d)..."), i+1, Context->vcount);
+
     if (i > Context->vcount - 1)
     {
       i = 0;
       if (option (OPTWRAPSEARCH))
-        mutt_message _("Search wrapped to top.");
+       msg = _("Search wrapped to top.");
       else 
       {
         mutt_message _("Search hit bottom without finding match");
@@ -1448,7 +1460,7 @@ int mutt_search_command (int cur, int op
     {
       i = Context->vcount - 1;
       if (option (OPTWRAPSEARCH))
-        mutt_message _("Search wrapped to bottom.");
+       msg = _("Search wrapped to bottom.");
       else 
       {
         mutt_message _("Search hit top without finding match");
@@ -1461,14 +1473,24 @@ int mutt_search_command (int cur, int op
     {
       /* if we've already evaulated this message, use the cached value */
       if (h->matched)
+      {
+       mutt_clear_error();
+       if (msg && *msg)
+         mutt_message (msg);
        return i;
+      }
     }
     else
     {
       /* remember that we've already searched this message */
       h->searched = 1;
       if ((h->matched = (mutt_pattern_exec (SearchPattern, 
M_MATCH_FULL_ADDRESS, Context, h) > 0)))
+      {
+       mutt_clear_error();
+       if (msg && *msg)
+         mutt_message (msg);
        return i;
+      }
     }
 
     if (SigInt)