]> granicus.if.org Git - mutt/commitdiff
Completion fixes from Gero Treuner <gero@faveve.uni-stuttgart.de>.
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 14 Jun 1999 18:11:15 +0000 (18:11 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 14 Jun 1999 18:11:15 +0000 (18:11 +0000)
alias.c
enter.c

diff --git a/alias.c b/alias.c
index 794b206919cddf7d1086fff39fa4764977a9324f..c37f93ee177c20cca70cf189dbe6023f0b0cb28c 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -319,7 +319,8 @@ ADDRESS *alias_reverse_lookup (ADDRESS *a)
 /* alias_complete() -- alias completion routine
  *
  * given a partial alias, this routine attempts to fill in the alias
- * from the alias list as much as possible
+ * from the alias list as much as possible. if given empty search string
+ * or found nothing, present all aliases
  */
 int mutt_alias_complete (char *s, size_t buflen)
 {
@@ -328,36 +329,38 @@ int mutt_alias_complete (char *s, size_t buflen)
   char bestname[STRING];
   int i;
 
-  memset (bestname, 0, sizeof (bestname));
-
 #define min(a,b)        ((a<b)?a:b)
 
-  while (a)
+  if (s[0] != 0) /* avoid empty string as strstr argument */
   {
-    if (a->name && strstr (a->name, s) == a->name)
+    memset (bestname, 0, sizeof (bestname));
+
+    while (a)
     {
-      if (!bestname[0]) /* init */
-       strfcpy (bestname, a->name, min (mutt_strlen (a->name) + 1, sizeof (bestname)));
-      else
+      if (a->name && strstr (a->name, s) == a->name)
       {
-       for (i = 0 ; a->name[i] && a->name[i] == bestname[i] ; i++)
-         ;
-       bestname[i] = 0;
+       if (!bestname[0]) /* init */
+         strfcpy (bestname, a->name,
+                  min (mutt_strlen (a->name) + 1, sizeof (bestname)));
+       else
+       {
+         for (i = 0 ; a->name[i] && a->name[i] == bestname[i] ; i++)
+           ;
+         bestname[i] = 0;
+       }
       }
+      a = a->next;
     }
-    a = a->next;
-  }
 
-  if ((bestname[0] == 0) || /* if we didn't find anything */
-      (s[0] == 0))          /* or we weren't given anything */
-  {
-    mutt_alias_menu (s, buflen, Aliases);
-    return 0;
-  }
-  else
-  {
-    if (mutt_strcmp (bestname, s) == 0) /* add anything to the completion? */
+    if (bestname[0] != 0)
     {
+      if (mutt_strcmp (bestname, s) != 0)
+      {
+       /* we are adding something to the completion */
+       strfcpy (s, bestname, mutt_strlen (bestname) + 1);
+       return 1;
+      }
+
       /* build alias list and show it */
       a = Aliases;
       while (a)
@@ -376,25 +379,23 @@ int mutt_alias_complete (char *s, size_t buflen)
        }
        a = a->next;
       }
+    }
+  }
 
-      s[0] = 0; /* reset string before passing to alias_menu */
-      mutt_alias_menu (s, buflen, a_list);
-
-      /* free the alias list */
-      while (a_list)
-      {
-       a_cur = a_list;
-       a_list = a_list->next;
-       safe_free ((void **) &a_cur);
-      }
+  bestname[0] = 0;
+  mutt_alias_menu (bestname, sizeof(bestname), a_list ? a_list : Aliases);
+  if (bestname[0] != 0)
+    strfcpy (s, bestname, buflen);
 
-      return 0;
-    }
-    else /* we are adding something to the completion */
-      strfcpy (s, bestname, mutt_strlen (bestname) + 1);
+  /* free the alias list */
+  while (a_list)
+  {
+    a_cur = a_list;
+    a_list = a_list->next;
+    safe_free ((void **) &a_cur);
   }
 
-  return 1;
+  return 0;
 }
 
 static int string_is_address(const char *str, const char *u, const char *d)
diff --git a/enter.c b/enter.c
index b85bf3d0c40c173828a1ea3a94addd59a2724a3e..337bb0bd1feebc722cea8b06575e07465e120d70 100644 (file)
--- a/enter.c
+++ b/enter.c
@@ -336,19 +336,14 @@ int _mutt_enter_string (unsigned char *buf, size_t buflen, int y, int x,
          {
            /* invoke the alias-menu to get more addresses */
            buf[curpos] = 0;
-           if (curpos)
+           for (j = curpos - 1 ; j >= 0 && buf[j] != ',' ; j--);
+           for (++j; buf[j] == ' '; j++)
+             ;
+           if (mutt_alias_complete ((char *) buf + j, buflen - j))
            {
-             for (j = curpos - 1 ; j >= 0 && buf[j] != ',' ; j--);
-             for (++j; buf[j] == ' '; j++)
-               ;
-             if (mutt_alias_complete ((char *) buf + j, buflen - j))
-             {
-               redraw = M_REDRAW_INIT;
-               continue;
-             }
+             redraw = M_REDRAW_INIT;
+             continue;
            }
-           else
-             mutt_alias_menu ((char *) buf, buflen, Aliases);
            return (1);
          }
          else if (flags & M_COMMAND)