[PATCH 1/2] WIP: groundwork for new sorting API

William Casarin jb55 at jb55.com
Mon Oct 8 13:51:20 PDT 2018


David Bremner <david at tethera.net> writes:

> --- a/lib/notmuch.h
> +++ b/lib/notmuch.h
> @@ -773,6 +773,10 @@ notmuch_query_create (notmuch_database_t *database,
>   * Sort values for notmuch_query_set_sort.
>   */
>  typedef enum {
> +    /**
> +     * Value was not set
> +     */
> +    NOTMUCH_SORT_UNSET = -1,
>      /**
>       * Oldest first.
>       */
> @@ -791,6 +795,42 @@ typedef enum {
>      NOTMUCH_SORT_UNSORTED
>  } notmuch_sort_t;


I'm adding a few new keys (from, subject, etc). I don't want to
duplicate them in the old notmuch_sort_t enum, I assume to move to the
new API there should be something like this as well?


diff --git a/lib/notmuch.h b/lib/notmuch.h
index d26cc09b..81a9d72f 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -787,10 +787,14 @@ typedef enum {
     NOTMUCH_SORT_NEWEST_FIRST,
     /**
      * Sort by message-id.
      */
     NOTMUCH_SORT_MESSAGE_ID,
+    /**
+     * Sort by keys.
+     */
+    NOTMUCH_SORT_KEYS,
     /**
      * Do not sort.
      */
     NOTMUCH_SORT_UNSORTED
 } notmuch_sort_t;


I've been wanting to sort by multiple keys recently so I figured
generalizing this to multiple (key, order) pairs might be a good idea
now that we're rethinking the sort api.

so then if I wanted to add my current changes I could just add a few
more keys like so:


diff --git a/lib/notmuch.h b/lib/notmuch.h
index a035bdb2..d26cc09b 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -809,10 +809,18 @@ typedef enum {
     NOTMUCH_SORT_KEY_TIMESTAMP,
     /**
      * Sort by message-id.
      */
     NOTMUCH_SORT_KEY_MESSAGE_ID,
+    /**
+     * Sort by subject.
+     */
+    NOTMUCH_SORT_KEY_SUBJECT,
+    /**
+     * Sort by from.
+     */
+    NOTMUCH_SORT_KEY_FROM,
 } notmuch_sort_key_t;
 

Then we could eventually do something like:

  --sort date:desc,from:asc

Which would mean: sort by date, and then by from.

Perhaps it could do something sensible by default without order
qualifiers as well:

  --sort date,from

LMK what you think


Will


More information about the notmuch mailing list