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

[PATCH] xlabel_sort.1



This patch implementes index sorting by X-Label. I'm not sure what else
needs to be said about it, really -- I believe it's a complete sort key.
I feel that it's overdue, and should be considered an integral part of
the basic x-label functionality, rather than an extension. I wish I'd
thought of it in the beginning. Thanks to Caleb Maclennan for suggesting
it.

I'd like to propose this for 1.5.10, but I know it's not ready. I intend
to maintain it regardless of whether it goes into 1.5.10, though, so
I'm soliciting feedback from the development community in either case.

Caveats from previous message:

> rather than "(k)ey", it presents "Key" with the keystroke
> capitalized. This has some drawbacks, particularly that it's
> non-intuitive. I keep wanting to press the capitals, and so does at
> least one of my testers. I chose not to make it case-insensitive because
> it's a translated string, and perhaps it's appropriate to use capitals
> in some translations. But that just amplifies the problem with this
> solution.

-- 
 -D.                          "Neque  porro  quisquam  est qui  dolorem
 dgc@xxxxxxxxxxxx             ipsum quia  dolor  sit amet, consectetur,
 NSIT->ENSS                   adipisci  velit."
 "Quia dolor sit."            -- Cicero, De Finibus Bonorum et Malorum.
--- mutt-1.5.8/PATCHES~ never
+++ mutt-1.5.8/PATCHES  Thu Mar 10 16:12:33 CST 2005
@@ -1,0 +1 @@
+patch-1.5.8.dgc.xlabel_sort.1
diff -Pur mutt-1.5.8-base/commands.c mutt-1.5.8/commands.c
--- mutt-1.5.8-base/commands.c  Sat Feb 12 13:22:15 2005
+++ mutt-1.5.8/commands.c       Wed Mar 16 23:29:14 2005
@@ -505,9 +505,9 @@
   int method = Sort; /* save the current method in case of abort */
 
   switch (mutt_multi_choice (reverse ?
-                            _("Rev-Sort 
(d)ate/(f)rm/(r)ecv/(s)ubj/t(o)/(t)hread/(u)nsort/si(z)e/s(c)ore/s(p)am?: ") :
-                            _("Sort 
(d)ate/(f)rm/(r)ecv/(s)ubj/t(o)/(t)hread/(u)nsort/si(z)e/s(c)ore/s(p)am?: "),
-                            _("dfrsotuzcp")))
+                            _("Rev-Sort 
Date/Frm/Recv/Subj/tO/Thread/Unsort/siZe/sCore/sPam/Label?: ") :
+                            _("Sort 
Date/Frm/Recv/Subj/tO/Thread/Unsort/siZe/sCore/sPam/Label?: "),
+                            _("dfrsotuzcpl")))
   {
   case -1: /* abort - don't resort */
     return -1;
@@ -550,6 +550,10 @@
 
   case 10: /* s(p)am */
     Sort = SORT_SPAM;
+    break;
+
+  case 11: /* (l)abel */
+    Sort = SORT_LABEL;
     break;
   }
   if (reverse)
diff -Pur mutt-1.5.8-base/init.h mutt-1.5.8/init.h
--- mutt-1.5.8-base/init.h      Sat Feb 12 14:01:10 2005
+++ mutt-1.5.8/init.h   Thu Mar 17 00:14:50 2005
@@ -2828,6 +2828,7 @@
   { "to",              SORT_TO },
   { "score",           SORT_SCORE },
   { "spam",            SORT_SPAM },
+  { "label",           SORT_LABEL },
   { NULL,              0 }
 };
 
@@ -2847,6 +2848,7 @@
   { "to",              SORT_TO },
   { "score",           SORT_SCORE },
   { "spam",            SORT_SPAM },
+  { "label",           SORT_LABEL },
   { NULL,              0 }
 };
   
diff -Pur mutt-1.5.8-base/sort.c mutt-1.5.8/sort.c
--- mutt-1.5.8-base/sort.c      Thu Feb  3 12:47:53 2005
+++ mutt-1.5.8/sort.c   Thu Mar 17 00:27:35 2005
@@ -204,6 +204,36 @@
   return (SORTCODE(result));
 }
 
+int compare_label (const void *a, const void *b)
+{
+  HEADER **ppa = (HEADER **) a;
+  HEADER **ppb = (HEADER **) b;
+  int     ahas, bhas, result;
+
+  /* As with compare_spam, not all messages will have the x-label
+   * property.  Blank X-Labels are treated as null in the index
+   * display, so we'll consider them as null for sort, too.       */
+  ahas = (*ppa)->env && (*ppa)->env->x_label && *((*ppa)->env->x_label);
+  bhas = (*ppb)->env && (*ppb)->env->x_label && *((*ppb)->env->x_label);
+
+  /* First we bias toward a message with a label, if the other does not. */
+  if (ahas && !bhas)
+    return (SORTCODE(-1));
+  if (!ahas && bhas)
+    return (SORTCODE(1));
+
+  /* If neither has a label, use aux sort. */
+  if (!ahas && !bhas)
+  {
+    AUXSORT(result, a, b);
+    return (SORTCODE(result));
+  }
+
+  /* If both have a label, we just do a lexical compare. */
+  result = mutt_strcasecmp((*ppa)->env->x_label, (*ppb)->env->x_label);
+  return (SORTCODE(result));
+}
+
 sort_t *mutt_get_sort_func (int method)
 {
   switch (method & SORT_MASK)
@@ -226,6 +256,8 @@
       return (compare_score);
     case SORT_SPAM:
       return (compare_spam);
+    case SORT_LABEL:
+      return (compare_label);
     default:
       return (NULL);
   }
diff -Pur mutt-1.5.8-base/sort.h mutt-1.5.8/sort.h
--- mutt-1.5.8-base/sort.h      Tue Jul 13 23:52:49 2004
+++ mutt-1.5.8/sort.h   Wed Mar 16 23:29:22 2005
@@ -31,6 +31,7 @@
 #define SORT_KEYID     12
 #define SORT_TRUST     13
 #define SORT_SPAM      14
+#define SORT_LABEL     15
 /* dgc: Sort & SortAux are shorts, so I'm bumping these bitflags up from
  * bits 4 & 5 to bits 8 & 9 to make room for more sort keys in the future. */
 #define SORT_MASK      0xff