--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 84A446DE0274\r
+ for <notmuch@notmuchmail.org>; Fri, 26 Jun 2015 15:50:52 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.183\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.183 tagged_above=-999 required=5 tests=[AWL=0.753, \r
+ DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001,\r
+ RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01,\r
+ RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 9LJjDHS6SHIE for <notmuch@notmuchmail.org>;\r
+ Fri, 26 Jun 2015 15:50:51 -0700 (PDT)\r
+Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com\r
+ [209.85.212.169])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 8CF306DE1390\r
+ for <notmuch@notmuchmail.org>; Fri, 26 Jun 2015 15:50:50 -0700 (PDT)\r
+Received: by wicnd19 with SMTP id nd19so28679530wic.1\r
+ for <notmuch@notmuchmail.org>; Fri, 26 Jun 2015 15:50:47 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
+ bh=/0dh4q60v0Remj4lrIjV2Qy8GDgZv5qjHjVzsIV+VsM=;\r
+ b=UQLjNdnSI27KBD6ICZJNjO7vgZ0RA/xXmGdlSJv+yrkW8tTTE/yOzMowSwfgOO5hMm\r
+ pfpN5CbZA4du3lSCyPq0szTxvgMpt/MuNObZ8hoCNj4VA+wWd4vOtlxrID997jHR7pKY\r
+ OkuydTBs6qPMHiMRBdsicH39W878X1LplqM614WSFmTUyiD06A687dX9LEBsaIrXbw+z\r
+ oxhhvX6v80YKRt5yTUJQjf+iJAwuWXDLezYvG1b1Qlb2WUKD/wciJD/GVPqdPshJjOeq\r
+ qulbdOWkRXRHFMH+P/WcbuJ195950SUgGmbWW+YD/sgE7uj4dmeqBq4z8E8vE7dW+iPD\r
+ l/Ig==\r
+X-Received: by 10.181.11.129 with SMTP id ei1mr711298wid.90.1435359047828;\r
+ Fri, 26 Jun 2015 15:50:47 -0700 (PDT)\r
+Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
+ by mx.google.com with ESMTPSA id ck18sm43758964wjb.47.2015.06.26.15.50.46\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Fri, 26 Jun 2015 15:50:47 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/4] cli: show: allow sort order to be specified\r
+Date: Fri, 26 Jun 2015 23:50:32 +0100\r
+Message-Id: <1435359035-6767-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1435359035-6767-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1435359035-6767-1-git-send-email-markwalters1009@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 26 Jun 2015 22:50:52 -0000\r
+\r
+This allows the sort to be specified in the notmuch show command with\r
+a --sort option.\r
+\r
+Note that individual threads are still displayed in oldest first\r
+order, but if the search has multiple threads then these are ordered\r
+according to this option. This should mean that most callers won't\r
+notice the option (e.g. the emacs show mode) as they only call show on\r
+individual threads, but other users, particularly the emacs tree view,\r
+can use it.\r
+---\r
+ doc/man1/notmuch-show.rst | 17 +++++++++++++++++\r
+ notmuch-show.c | 8 ++++++++\r
+ 2 files changed, 25 insertions(+)\r
+\r
+diff --git a/doc/man1/notmuch-show.rst b/doc/man1/notmuch-show.rst\r
+index 9eb5198..7717b08 100644\r
+--- a/doc/man1/notmuch-show.rst\r
++++ b/doc/man1/notmuch-show.rst\r
+@@ -97,6 +97,23 @@ Supported options for **show** include\r
+ intended for programs that invoke **notmuch(1)** internally. If\r
+ omitted, the latest supported version will be used.\r
+ \r
++ ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)\r
++ This option can be used to present results in either\r
++ chronological order (**oldest-first**) or reverse chronological\r
++ order (**newest-first**).\r
++\r
++ Note: This only affects the order of messages in different\r
++ threads: messages inside a thread will always be presented in\r
++ thread order. However, the order of the threads will be distinct\r
++ between these two options (beyond being simply reversed). When\r
++ sorting by **oldest-first** the threads will be sorted by the\r
++ oldest message in each thread, but when sorting by\r
++ **newest-first** the threads will be sorted by the newest\r
++ message in each thread.\r
++\r
++ By default, results will be displayed in reverse chronological\r
++ order, (that is, the newest results will be displayed first).\r
++\r
+ ``--part=N``\r
+ Output the single decoded MIME part N of a single message. The\r
+ search terms must match only a single message. Message parts are\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index b80933a..ec9a915 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -1090,6 +1090,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])\r
+ int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;\r
+ int exclude = EXCLUDE_TRUE;\r
+ int entire_thread = ENTIRE_THREAD_DEFAULT;\r
++ notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST;\r
+ \r
+ notmuch_opt_desc_t options[] = {\r
+ { NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',\r
+@@ -1100,10 +1101,15 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])\r
+ { "raw", NOTMUCH_FORMAT_RAW },\r
+ { 0, 0 } } },\r
+ { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 },\r
++ { NOTMUCH_OPT_KEYWORD, &sort, "sort", 's',\r
++ (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },\r
++ { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },\r
++ { 0, 0 } } },\r
+ { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',\r
+ (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },\r
+ { "false", EXCLUDE_FALSE },\r
+ { 0, 0 } } },\r
++\r
+ { NOTMUCH_OPT_KEYWORD, &entire_thread, "entire-thread", 't',\r
+ (notmuch_keyword_t []){ { "true", ENTIRE_THREAD_TRUE },\r
+ { "false", ENTIRE_THREAD_FALSE },\r
+@@ -1233,6 +1239,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])\r
+ size_t search_exclude_tags_length;\r
+ unsigned int i;\r
+ \r
++ notmuch_query_set_sort (query, sort);\r
++\r
+ search_exclude_tags = notmuch_config_get_search_exclude_tags\r
+ (config, &search_exclude_tags_length);\r
+ for (i = 0; i < search_exclude_tags_length; i++)\r
+-- \r
+2.1.4\r
+\r