]> granicus.if.org Git - neomutt/commitdiff
Fix non-threaded $sort_aux "reverse-" sorting.
authorKevin McCarthy <kevin@8t8.us>
Wed, 26 Sep 2018 02:03:56 +0000 (19:03 -0700)
committerRichard Russon <rich@flatcap.org>
Wed, 26 Sep 2018 02:03:56 +0000 (19:03 -0700)
The secondary sort was looking at (Sort & SORT_REVERSE) instead
of (SortAux & SORT_REVERSE), so wasn't even performing the reverse
based on the correct flag.

Additionally, afterwards, the primary sort was improperly applying a
reverse when the secondary sort returned non-zero.

Change SORTCODE() to look at SortAux when we are inside a secondary
sort.

Change AUXSORT() to return the result if the secondary sort returns
non-zero.  It is ugly to put a return inside the macro, but the check
for non-zero needs to be performed inside the AUXSORT if branch.

If the secondary sort returns 0, then the primary sort can still
compare index and apply a reverse as needed.

init.h
sort.c
sort.h

diff --git a/init.h b/init.h
index 0323bc06e8bc28006da55da5a5a8657729089c01..69263e1bf5dc3acb1e07a73b7ac6793d45e0d3f8 100644 (file)
--- a/init.h
+++ b/init.h
@@ -3922,6 +3922,9 @@ struct ConfigDef MuttVars[] = {
   { "sort_aux",         DT_SORT|DT_SORT_AUX, R_INDEX|R_RESORT_BOTH, &SortAux, SORT_DATE },
   /*
   ** .pp
+  ** This provides a secondary sort for messages in the ``index'' menu, used
+  ** when the $$sort value is equal for two messages.
+  ** .pp
   ** When sorting by threads, this variable controls how threads are sorted
   ** in relation to other threads, and how the branches of the thread trees
   ** are sorted.  This can be set to any value that $$sort can, except
@@ -3938,8 +3941,8 @@ struct ConfigDef MuttVars[] = {
   ** thread, that thread becomes the last one displayed (or the first, if
   ** you have ``\fCset sort=reverse-threads\fP''.)
   ** .pp
-  ** Note: For reversed $$sort
-  ** order $$sort_aux is reversed again (which is not the right thing to do,
+  ** Note: For reversed-threads $$sort
+  ** order, $$sort_aux is reversed again (which is not the right thing to do,
   ** but kept to not break any existing configuration setting).
   */
   { "sort_browser",     DT_SORT|DT_SORT_BROWSER, R_NONE, &SortBrowser, SORT_ALPHA },
diff --git a/sort.c b/sort.c
index 02b817c9e38c1be149a26eee70474b48ae15b5f3..8ea5d295bc9845402460187fbaf29b3505ca3a3e 100644 (file)
--- a/sort.c
+++ b/sort.c
@@ -64,6 +64,8 @@ int perform_auxsort(int retval, const void *a, const void *b)
     OptAuxSort = true;
     retval = AuxSort(a, b);
     OptAuxSort = false;
+    if (retval != 0)
+      return retval;
   }
   /* If the items still match, use their index positions
    * to maintain a stable sort order */
diff --git a/sort.h b/sort.h
index cd262d0b722139992fc2fe1595a5e0dffd001de8..7873a08a438493168a97ed361a614df800874178 100644 (file)
--- a/sort.h
+++ b/sort.h
@@ -26,6 +26,7 @@
 #include <stdbool.h>
 #include "mutt/mutt.h"
 #include "config/lib.h"
+#include "options.h"
 #include "where.h"
 
 struct Address;
@@ -34,7 +35,7 @@ struct Context;
 /* These Config Variables are only used in sort.c */
 extern bool ReverseAlias;
 
-#define SORTCODE(x) (Sort & SORT_REVERSE) ? -(x) : x
+#define SORTCODE(x) ((OptAuxSort ? SortAux : Sort) & SORT_REVERSE) ? -(x) : x
 
 /**
  * typedef sort_t - Prototype for a function to compare two emails