From 333486572517d2e2084d66208de59085f21d8573 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 17 Nov 2009 20:52:09 -0800 Subject: notmuch search: Change default search order to be newest messages first. This is what most people want for a _search_ command. It's often different for actually reading mail in an inbox, (where it makes more sense to have results displayed in chronological order), but in such a case, ther user is likely using an interface that can simply pass the --sort=oldest-first option to "notmuch search". Here we're also change the sort enum from NOTMUCH_SORT_DATE and NOTMUCH_SORT_DATE_REVERSE to NOTMUCH_SORT_OLDEST_FIRST and NOTMUCH_SORT_NEWEST_FIRST. Similarly we replace the --reverse option to "notmuch search" with two options: --sort=oldest-first and --sort=newest-first. Finally, these changes are all tracked in the emacs interface, (which has no change in its behavior). --- notmuch-search.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'notmuch-search.c') diff --git a/notmuch-search.c b/notmuch-search.c index 59ffb038..91266c35 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -45,7 +45,7 @@ do_search_threads (const void *ctx, thread = notmuch_threads_get (threads); - if (sort == NOTMUCH_SORT_DATE) + if (sort == NOTMUCH_SORT_OLDEST_FIRST) date = notmuch_thread_get_oldest_date (thread); else date = notmuch_thread_get_newest_date (thread); @@ -85,7 +85,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) char *query_str; int i, first = 0, max_threads = -1; char *opt, *end; - notmuch_sort_t sort = NOTMUCH_SORT_DATE; + notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST; for (i = 0; i < argc && argv[i][0] == '-'; i++) { if (strcmp (argv[i], "--") == 0) { @@ -106,8 +106,16 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) fprintf (stderr, "Invalid value for --max-threads: %s\n", opt); return 1; } - } else if (strcmp (argv[i], "--reverse") == 0) { - sort = NOTMUCH_SORT_DATE_REVERSE; + } else if (STRNCMP_LITERAL (argv[i], "--sort=") == 0) { + opt = argv[i] + sizeof ("--sort=") - 1; + if (strcmp (opt, "oldest-first") == 0) { + sort = NOTMUCH_SORT_OLDEST_FIRST; + } else if (strcmp (opt, "newest-first") == 0) { + sort = NOTMUCH_SORT_NEWEST_FIRST; + } else { + fprintf (stderr, "Invalid value for --sort: %s\n", opt); + return 1; + } } else { fprintf (stderr, "Unrecognized option: %s\n", argv[i]); return 1; -- cgit v1.2.3