mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-24 20:08:10 +01:00
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).
This commit is contained in:
parent
5dec429f45
commit
3334865725
5 changed files with 20 additions and 12 deletions
|
@ -299,8 +299,8 @@ notmuch_query_create (notmuch_database_t *database,
|
||||||
|
|
||||||
/* Sort values for notmuch_query_set_sort */
|
/* Sort values for notmuch_query_set_sort */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
NOTMUCH_SORT_DATE,
|
NOTMUCH_SORT_OLDEST_FIRST,
|
||||||
NOTMUCH_SORT_DATE_REVERSE,
|
NOTMUCH_SORT_NEWEST_FIRST,
|
||||||
NOTMUCH_SORT_MESSAGE_ID
|
NOTMUCH_SORT_MESSAGE_ID
|
||||||
} notmuch_sort_t;
|
} notmuch_sort_t;
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ notmuch_query_create (notmuch_database_t *notmuch,
|
||||||
|
|
||||||
query->query_string = talloc_strdup (query, query_string);
|
query->query_string = talloc_strdup (query, query_string);
|
||||||
|
|
||||||
query->sort = NOTMUCH_SORT_DATE;
|
query->sort = NOTMUCH_SORT_NEWEST_FIRST;
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
@ -109,10 +109,10 @@ notmuch_query_search_messages (notmuch_query_t *query,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (query->sort) {
|
switch (query->sort) {
|
||||||
case NOTMUCH_SORT_DATE:
|
case NOTMUCH_SORT_OLDEST_FIRST:
|
||||||
enquire.set_sort_by_value (NOTMUCH_VALUE_TIMESTAMP, FALSE);
|
enquire.set_sort_by_value (NOTMUCH_VALUE_TIMESTAMP, FALSE);
|
||||||
break;
|
break;
|
||||||
case NOTMUCH_SORT_DATE_REVERSE:
|
case NOTMUCH_SORT_NEWEST_FIRST:
|
||||||
enquire.set_sort_by_value (NOTMUCH_VALUE_TIMESTAMP, TRUE);
|
enquire.set_sort_by_value (NOTMUCH_VALUE_TIMESTAMP, TRUE);
|
||||||
break;
|
break;
|
||||||
case NOTMUCH_SORT_MESSAGE_ID:
|
case NOTMUCH_SORT_MESSAGE_ID:
|
||||||
|
|
|
@ -258,7 +258,7 @@ _notmuch_thread_create (void *ctx,
|
||||||
thread->oldest = 0;
|
thread->oldest = 0;
|
||||||
thread->newest = 0;
|
thread->newest = 0;
|
||||||
|
|
||||||
notmuch_query_set_sort (thread_id_query, NOTMUCH_SORT_DATE);
|
notmuch_query_set_sort (thread_id_query, NOTMUCH_SORT_OLDEST_FIRST);
|
||||||
|
|
||||||
for (messages = notmuch_query_search_messages (thread_id_query, 0, -1);
|
for (messages = notmuch_query_search_messages (thread_id_query, 0, -1);
|
||||||
notmuch_messages_has_more (messages);
|
notmuch_messages_has_more (messages);
|
||||||
|
|
|
@ -45,7 +45,7 @@ do_search_threads (const void *ctx,
|
||||||
|
|
||||||
thread = notmuch_threads_get (threads);
|
thread = notmuch_threads_get (threads);
|
||||||
|
|
||||||
if (sort == NOTMUCH_SORT_DATE)
|
if (sort == NOTMUCH_SORT_OLDEST_FIRST)
|
||||||
date = notmuch_thread_get_oldest_date (thread);
|
date = notmuch_thread_get_oldest_date (thread);
|
||||||
else
|
else
|
||||||
date = notmuch_thread_get_newest_date (thread);
|
date = notmuch_thread_get_newest_date (thread);
|
||||||
|
@ -85,7 +85,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
|
||||||
char *query_str;
|
char *query_str;
|
||||||
int i, first = 0, max_threads = -1;
|
int i, first = 0, max_threads = -1;
|
||||||
char *opt, *end;
|
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++) {
|
for (i = 0; i < argc && argv[i][0] == '-'; i++) {
|
||||||
if (strcmp (argv[i], "--") == 0) {
|
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);
|
fprintf (stderr, "Invalid value for --max-threads: %s\n", opt);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else if (strcmp (argv[i], "--reverse") == 0) {
|
} else if (STRNCMP_LITERAL (argv[i], "--sort=") == 0) {
|
||||||
sort = NOTMUCH_SORT_DATE_REVERSE;
|
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 {
|
} else {
|
||||||
fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
|
fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -874,8 +874,8 @@ This function advances point to the next line when finished."
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(if oldest-first
|
(if oldest-first
|
||||||
(call-process "notmuch" nil t nil "search" query)
|
(call-process "notmuch" nil t nil "search" "--sort=oldest-first" query)
|
||||||
(call-process "notmuch" nil t nil "search" "--reverse" query))
|
(call-process "notmuch" nil t nil "search" "--sort=newest-first" query))
|
||||||
(notmuch-search-markup-thread-ids)
|
(notmuch-search-markup-thread-ids)
|
||||||
))))
|
))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue