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

[PATCH] Case-insensitive filename completion



First patch, so hopefully I got things mostly right...

Adds an option (case_insensitive_folder_complete) that makes folder name
completion case-insensitive.  It's working for me on both tip and
1.5.19, but does not support IMAP -- which is a protocol I know rather
little about, but the standard appears to leave case-sensitivity of the
LIST command to whatever the server implementer feels like.

-- 
Brad Ackerman
brad@xxxxxxxxxxxxx
diff -r f467353f5657 PATCHES
--- a/PATCHES   Sat Mar 31 18:50:39 2007 -0700
+++ b/PATCHES   Sun Jan 25 18:53:21 2009 +0000
@@ -0,0 +1,1 @@
+patch-1.5.19.bsa.case_insensitive_folder_complete.1
diff -r f467353f5657 complete.c
--- a/complete.c        Sat Mar 31 18:50:39 2007 -0700
+++ b/complete.c        Sun Jan 25 18:53:21 2009 +0000
@@ -46,6 +46,8 @@ int mutt_complete (char *s, size_t slen)
   size_t len;
   char dirpart[_POSIX_PATH_MAX], exp_dirpart[_POSIX_PATH_MAX];
   char filepart[_POSIX_PATH_MAX];
+  int (*strncmp_function)(const char*, const char*, size_t) = NULL;
+
 #ifdef USE_IMAP
   char imap_path[LONG_STRING];
 
@@ -68,6 +70,15 @@ int mutt_complete (char *s, size_t slen)
     return imap_complete (s, slen, imap_path);
 #endif
   
+  /* Choose function to use when comparing folder names.
+   * If case_insensitive_folder_complete is set, will
+   * compare ignoring case.
+   */
+  if (option (OPTCASEINSENSITIVEFOLDERCOMPLETE))
+    strncmp_function = &mutt_strncasecmp;
+  else
+    strncmp_function = &mutt_strncmp;
+
   if (*s == '=' || *s == '+' || *s == '!')
   {
     dirpart[0] = *s;
@@ -149,18 +160,21 @@ int mutt_complete (char *s, size_t slen)
 
   while ((de = readdir (dirp)) != NULL)
   {
-    if (mutt_strncmp (de->d_name, filepart, len) == 0)
+    /* Check if this candidate file matches the entered prefix */
+    if (strncmp_function (de->d_name, filepart, len) == 0)
     {
       if (init)
       {
        for (i=0; filepart[i] && de->d_name[i]; i++)
        {
-         if (filepart[i] != de->d_name[i])
+          if (strncmp_function(filepart+i, de->d_name+i, 1) != 0 )
          {
+            /* Truncate filepart to the shortest prefix
+             *   common with candidate */
            filepart[i] = 0;
            break;
          }
-       }
+       } 
        filepart[i] = 0;
       }
       else
diff -r f467353f5657 init.h
--- a/init.h    Sat Mar 31 18:50:39 2007 -0700
+++ b/init.h    Sun Jan 25 18:53:21 2009 +0000
@@ -301,6 +301,14 @@ struct option_t MuttVars[] = {
   ** is unset, making it easier for blind persons using Braille displays to 
   ** follow these menus.  The option is disabled by default because many 
   ** visual terminals don't permit making the cursor invisible.
+  */
+  { "case_insensitive_folder_complete", DT_BOOL, R_NONE, 
OPTCASEINSENSITIVEFOLDERCOMPLETE, 0},
+  /*
+  ** .pp
+  ** When this variable is set, the folder browser's complete function
+  ** will ignore case when completing folder names.
+  **
+  ** This option is not supported on IMAP mail folders.
   */
   { "check_mbox_size", DT_BOOL, R_NONE, OPTCHECKMBOXSIZE, 0 },
   /*
diff -r f467353f5657 mutt.h
--- a/mutt.h    Sat Mar 31 18:50:39 2007 -0700
+++ b/mutt.h    Sun Jan 25 18:53:21 2009 +0000
@@ -339,6 +339,7 @@ enum
   OPTBEEPNEW,
   OPTBOUNCEDELIVERED,
   OPTBRAILLEFRIENDLY,
+  OPTCASEINSENSITIVEFOLDERCOMPLETE,
   OPTCHECKMBOXSIZE,
   OPTCHECKNEW,
   OPTCOLLAPSEUNREAD,