unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH 1/4] cli: show: allow sort order to be specified
Date: Fri, 26 Jun 2015 23:50:32 +0100	[thread overview]
Message-ID: <1435359035-6767-2-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1435359035-6767-1-git-send-email-markwalters1009@gmail.com>

This allows the sort to be specified in the notmuch show command with
a --sort option.

Note that individual threads are still displayed in oldest first
order, but if the search has multiple threads then these are ordered
according to this option. This should mean that most callers won't
notice the option (e.g. the emacs show mode) as they only call show on
individual threads, but other users, particularly the emacs tree view,
can use it.
---
 doc/man1/notmuch-show.rst | 17 +++++++++++++++++
 notmuch-show.c            |  8 ++++++++
 2 files changed, 25 insertions(+)

diff --git a/doc/man1/notmuch-show.rst b/doc/man1/notmuch-show.rst
index 9eb5198..7717b08 100644
--- a/doc/man1/notmuch-show.rst
+++ b/doc/man1/notmuch-show.rst
@@ -97,6 +97,23 @@ Supported options for **show** include
         intended for programs that invoke **notmuch(1)** internally. If
         omitted, the latest supported version will be used.
 
+    ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)
+        This option can be used to present results in either
+        chronological order (**oldest-first**) or reverse chronological
+        order (**newest-first**).
+
+        Note: This only affects the order of messages in different
+        threads: messages inside a thread will always be presented in
+        thread order.  However, the order of the threads will be distinct
+        between these two options (beyond being simply reversed). When
+        sorting by **oldest-first** the threads will be sorted by the
+        oldest message in each thread, but when sorting by
+        **newest-first** the threads will be sorted by the newest
+        message in each thread.
+
+        By default, results will be displayed in reverse chronological
+        order, (that is, the newest results will be displayed first).
+
     ``--part=N``
         Output the single decoded MIME part N of a single message. The
         search terms must match only a single message. Message parts are
diff --git a/notmuch-show.c b/notmuch-show.c
index b80933a..ec9a915 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1090,6 +1090,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
     int exclude = EXCLUDE_TRUE;
     int entire_thread = ENTIRE_THREAD_DEFAULT;
+    notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST;
 
     notmuch_opt_desc_t options[] = {
 	{ NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',
@@ -1100,10 +1101,15 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 				  { "raw", NOTMUCH_FORMAT_RAW },
 				  { 0, 0 } } },
 	{ NOTMUCH_OPT_INT, &notmuch_format_version, "format-version", 0, 0 },
+	{ NOTMUCH_OPT_KEYWORD, &sort, "sort", 's',
+	  (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
+				  { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
+				  { 0, 0 } } },
 	{ NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',
 	  (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
 				  { "false", EXCLUDE_FALSE },
 				  { 0, 0 } } },
+
 	{ NOTMUCH_OPT_KEYWORD, &entire_thread, "entire-thread", 't',
 	  (notmuch_keyword_t []){ { "true", ENTIRE_THREAD_TRUE },
 				  { "false", ENTIRE_THREAD_FALSE },
@@ -1233,6 +1239,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 	size_t search_exclude_tags_length;
 	unsigned int i;
 
+	notmuch_query_set_sort (query, sort);
+
 	search_exclude_tags = notmuch_config_get_search_exclude_tags
 	    (config, &search_exclude_tags_length);
 	for (i = 0; i < search_exclude_tags_length; i++)
-- 
2.1.4

  reply	other threads:[~2015-06-26 22:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-26 22:50 [PATCH 0/4] Allow oldest-first view in tree view Mark Walters
2015-06-26 22:50 ` Mark Walters [this message]
2015-07-31 19:11   ` [PATCH 1/4] cli: show: allow sort order to be specified David Bremner
2015-06-26 22:50 ` [PATCH 2/4] emacs: tree: bind o to toggle sort order Mark Walters
2015-07-31 19:39   ` David Bremner
2015-06-26 22:50 ` [PATCH 3/4] emacs: tree: add sort argument to notmuch-tree Mark Walters
2015-08-01  5:49   ` David Bremner
2015-06-26 22:50 ` [PATCH 4/4] test: tree: fix and a test for tree sort order changes Mark Walters

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1435359035-6767-2-git-send-email-markwalters1009@gmail.com \
    --to=markwalters1009@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).