--- /dev/null
+Return-Path: <bart@jukie.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 63096431FC3\r
+ for <notmuch@notmuchmail.org>; Fri, 27 Nov 2009 18:50:34 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id WpuLtgmAkKha for <notmuch@notmuchmail.org>;\r
+ Fri, 27 Nov 2009 18:50:33 -0800 (PST)\r
+Received: from tau.jukie.net (tau.jukie.net [216.239.93.128])\r
+ by olra.theworths.org (Postfix) with ESMTP id 25FBE431FAE\r
+ for <notmuch@notmuchmail.org>; Fri, 27 Nov 2009 18:50:33 -0800 (PST)\r
+Received: from localhost.localdomain (oxygen.jukie.net [10.10.10.8])\r
+ by tau.jukie.net (Postfix) with ESMTP id 936BBC008F5;\r
+ Fri, 27 Nov 2009 21:50:32 -0500 (EST)\r
+From: Bart Trojanowski <bart@jukie.net>\r
+To: notmuch@notmuchmail.org\r
+Date: Fri, 27 Nov 2009 21:49:39 -0500\r
+Message-Id: <1259376580-934-1-git-send-email-bart@jukie.net>\r
+X-Mailer: git-send-email 1.6.4.4.2.gc2f148\r
+In-Reply-To: <20091128022115.662B62053465E@oxygen.jukie.net>\r
+References: <20091128022115.662B62053465E@oxygen.jukie.net>\r
+Cc: Bart Trojanowski <bart@jukie.net>\r
+Subject: [notmuch] [PATCH 1/2] notmuch-show: limit display to only matching\r
+ messages\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.12\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: Sat, 28 Nov 2009 02:50:34 -0000\r
+\r
+This patch changes the default behaviour of notmuch show to display only\r
+messages that match the search expression. However, --entire-thread\r
+option is provided to display all messages in threads that matched the\r
+search expression.\r
+\r
+It is deemed that will be more useful for human users on the command line.\r
+Scripts can be modified to include the --entire-thread option so that they\r
+can display all messages once more.\r
+\r
+Example:\r
+\r
+$ notmuch search subject:git AND thread:23d99d0f364f93e90e15df8b42eddb5b\r
+thread:23d99d0f364f93e90e15df8b42eddb5b July 31 [4/12] Johan Herland; [RFCv2 00/12] Foreign VCS helper program for CVS repositories (inbox unread)\r
+\r
+Note that in this thread 4 out of 12 messages matched. The default show\r
+behaviour is to show only those messages that match:\r
+\r
+$ notmuch show subject:git AND thread:23d99d0f364f93e90e15df8b42eddb5b | grep 'message{' | wc -l\r
+4\r
+\r
+With the --only-matching-messages option the output will contain all dozen\r
+messages:\r
+\r
+$ notmuch show --entire-thread subject:git AND thread:23d99d0f364f93e90e15df8b42eddb5b | grep 'message{' | wc -l\r
+12\r
+\r
+Signed-off-by: Bart Trojanowski <bart@jukie.net>\r
+---\r
+ notmuch-show.c | 48 +++++++++++++++++++++++++++++++++++++-----------\r
+ notmuch.c | 8 ++++++++\r
+ 2 files changed, 45 insertions(+), 11 deletions(-)\r
+\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 13c91e4..60339d0 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -212,6 +212,24 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+ notmuch_thread_t *thread;\r
+ notmuch_messages_t *messages;\r
+ char *query_string;\r
++ int entire_thread = 0;\r
++ int i;\r
++\r
++ for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
++ if (strcmp (argv[i], "--") == 0) {\r
++ i++;\r
++ break;\r
++ }\r
++ if (strcmp(argv[i], "--entire-thread") == 0) {\r
++ entire_thread = 1;\r
++ } else {\r
++ fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
++ return 1;\r
++ }\r
++ }\r
++\r
++ argc -= i;\r
++ argv += i;\r
+ \r
+ config = notmuch_config_open (ctx, NULL, NULL);\r
+ if (config == NULL)\r
+@@ -239,21 +257,29 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+ return 1;\r
+ }\r
+ \r
+- for (threads = notmuch_query_search_threads (query);\r
+- notmuch_threads_has_more (threads);\r
+- notmuch_threads_advance (threads))\r
+- {\r
+- thread = notmuch_threads_get (threads);\r
++ if (!entire_thread) {\r
++ messages = notmuch_query_search_messages (query);\r
++ if (messages == NULL)\r
++ INTERNAL_ERROR ("No messages.\n");\r
++ show_messages (ctx, messages, 0);\r
+ \r
+- messages = notmuch_thread_get_toplevel_messages (thread);\r
++ } else {\r
++ for (threads = notmuch_query_search_threads (query);\r
++ notmuch_threads_has_more (threads);\r
++ notmuch_threads_advance (threads))\r
++ {\r
++ thread = notmuch_threads_get (threads);\r
+ \r
+- if (messages == NULL)\r
+- INTERNAL_ERROR ("Thread %s has no toplevel messages.\n",\r
+- notmuch_thread_get_thread_id (thread));\r
++ messages = notmuch_thread_get_toplevel_messages (thread);\r
+ \r
+- show_messages (ctx, messages, 0);\r
++ if (messages == NULL)\r
++ INTERNAL_ERROR ("Thread %s has no toplevel messages.\n",\r
++ notmuch_thread_get_thread_id (thread));\r
++\r
++ show_messages (ctx, messages, 0);\r
+ \r
+- notmuch_thread_destroy (thread);\r
++ notmuch_thread_destroy (thread);\r
++ }\r
+ }\r
+ \r
+ notmuch_query_destroy (query);\r
+diff --git a/notmuch.c b/notmuch.c\r
+index 5b0284c..ea67b4f 100644\r
+--- a/notmuch.c\r
++++ b/notmuch.c\r
+@@ -177,6 +177,14 @@ command_t commands[] = {\r
+ "\t\t(all replies to a particular message appear immediately\n"\r
+ "\t\tafter that message in date order).\n"\r
+ "\n"\r
++ "\t\tSupported options for show include:\n"\r
++ "\n"\r
++ "\t\t--entire-thread\n"\r
++ "\n"\r
++ "\t\t\tBy default only messages strictly matching the\n"\r
++ "\t\t\tsearch expression will be displayed. With this\n"\r
++ "\t\t\toption all messages in matching threads are shown.\n"\r
++ "\n"\r
+ "\t\tThe output format is plain-text, with all text-content\n"\r
+ "\t\tMIME parts decoded. Various components in the output,\n"\r
+ "\t\t('message', 'header', 'body', 'attachment', and MIME 'part')\n"\r
+-- \r
+1.6.4.4.2.gc2f148\r
+\r