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

[PATCH] display search progress



Hi,

on slow systems especially with huge folders (>10k messages), it's annoying to have mutt print no feedback when searching.

When doying "plain" searches, it says nothing at all. When doing "limit" searches, it just says it's executing commands on matching messages.

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.

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...

  bye, Rocco
--
:wq!
diff --git a/pattern.c b/pattern.c
index 1ce81f2..ec8b64a 100644
--- a/pattern.c
+++ b/pattern.c
@@ -116,7 +116,6 @@ static char LastSearchExpn[LONG_STRING]
 #define M_PDR_ERROR    0x0100
 #define M_PDR_ERRORDONE        (M_PDR_ERROR | M_PDR_DONE)
 
-
 int mutt_getvaluebychar (char ch, struct mapping_t *table)
 {
   int i;
@@ -1285,8 +1284,6 @@ int mutt_pattern_func (int op, char *pro
   if (Context->magic == M_IMAP && imap_search (Context, pat) < 0)
     return -1;
 #endif
-  
-  mutt_message _("Executing command on matching messages...");
 
 #define THIS_BODY Context->hdrs[i]->content
 
@@ -1298,6 +1295,8 @@ int mutt_pattern_func (int op, char *pro
 
     for (i = 0; i < Context->msgcount; i++)
     {
+      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 +1317,8 @@ int mutt_pattern_func (int op, char *pro
   {
     for (i = 0; i < Context->vcount; i++)
     {
+      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 +1376,8 @@ int mutt_search_command (int cur, int op
   BUFFER err;
   int incr;
   HEADER *h;
-  
+  const char *msg = NULL;
+
   if (op != OP_SEARCH_NEXT && op != OP_SEARCH_OPPOSITE)
   {
     strfcpy (buf, LastSearch, sizeof (buf));
@@ -1433,11 +1435,13 @@ int mutt_search_command (int cur, int op
 
   for (i = cur + incr, j = 0 ; j != Context->vcount; j++)
   {
+    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 +1452,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");
@@ -1460,15 +1464,23 @@ int mutt_search_command (int cur, int op
     if (h->searched)
     {
       /* if we've already evaulated this message, use the cached value */
-      if (h->matched)
+      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)))
+      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)