Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / b9 / fb91f2fe9a4c7b7624e0007c5862c562c147c4
1 Return-Path: <bart@jukie.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id C9087431FC2\r
6         for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 18:04:27 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id vAaZmgqEaqpA for <notmuch@notmuchmail.org>;\r
11         Tue, 24 Nov 2009 18:04:27 -0800 (PST)\r
12 Received: from tau.jukie.net (tau.jukie.net [216.239.93.128])\r
13         by olra.theworths.org (Postfix) with ESMTP id AE219431FC0\r
14         for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 18:04:26 -0800 (PST)\r
15 Received: from localhost.localdomain (oxygen.jukie.net [10.10.10.8])\r
16         by tau.jukie.net (Postfix) with ESMTP id 3A63AC00F84;\r
17         Tue, 24 Nov 2009 21:04:26 -0500 (EST)\r
18 From: Bart Trojanowski <bart@jukie.net>\r
19 To: notmuch@notmuchmail.org\r
20 Date: Tue, 24 Nov 2009 21:03:29 -0500\r
21 Message-Id: <1259114609-15959-2-git-send-email-bart@jukie.net>\r
22 X-Mailer: git-send-email 1.6.4.4.2.gc2f148\r
23 In-Reply-To: <1259114609-15959-1-git-send-email-bart@jukie.net>\r
24 References: <1259114609-15959-1-git-send-email-bart@jukie.net>\r
25 Cc: Bart Trojanowski <bart@jukie.net>\r
26 Subject: [notmuch] [PATCH] notmuch-show: add option to limit display to only\r
27         matching messages\r
28 X-BeenThere: notmuch@notmuchmail.org\r
29 X-Mailman-Version: 2.1.12\r
30 Precedence: list\r
31 List-Id: "Use and development of the notmuch mail system."\r
32         <notmuch.notmuchmail.org>\r
33 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
34         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
35 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
36 List-Post: <mailto:notmuch@notmuchmail.org>\r
37 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
38 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
39         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
40 X-List-Received-Date: Wed, 25 Nov 2009 02:04:28 -0000\r
41 \r
42 This patch adds support for notmuch show --only-matching-messages\r
43 which limits the output to only the top level messages matching\r
44 the search terms provides.\r
45 \r
46 Example:\r
47 \r
48 $ notmuch search subject:git AND thread:23d99d0f364f93e90e15df8b42eddb5b\r
49 thread:23d99d0f364f93e90e15df8b42eddb5b      July 31 [4/12] Johan Herland; [RFCv2 00/12] Foreign VCS helper program for CVS repositories (inbox unread)\r
50 \r
51 Note that in this thread 4 out of 12 messages matched.  The default show\r
52 behaviour is to show all messages in the thread:\r
53 \r
54 $ notmuch show subject:git AND thread:23d99d0f364f93e90e15df8b42eddb5b | grep 'message{' | wc -l\r
55 12\r
56 \r
57 With the --only-matching-messages option the output is limited to the\r
58 matching messages only:\r
59 \r
60 $ notmuch show --only-matching-messages subject:git AND thread:23d99d0f364f93e90e15df8b42eddb5b | grep 'message{' | wc -l\r
61 4\r
62 \r
63 Signed-off-by: Bart Trojanowski <bart@jukie.net>\r
64 ---\r
65  notmuch-show.c |   48 +++++++++++++++++++++++++++++++++++++-----------\r
66  notmuch.c      |    7 +++++++\r
67  2 files changed, 44 insertions(+), 11 deletions(-)\r
68 \r
69 diff --git a/notmuch-show.c b/notmuch-show.c\r
70 index edebaca..8599c6c 100644\r
71 --- a/notmuch-show.c\r
72 +++ b/notmuch-show.c\r
73 @@ -211,6 +211,24 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
74      notmuch_thread_t *thread;\r
75      notmuch_messages_t *messages;\r
76      char *query_string;\r
77 +    int only_matching = 0;\r
78 +    int i;\r
79 +\r
80 +    for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
81 +       if (strcmp (argv[i], "--") == 0) {\r
82 +           i++;\r
83 +           break;\r
84 +       }\r
85 +        if (strcmp(argv[i], "--only-matching-messages") == 0) {\r
86 +           only_matching = 1;\r
87 +       } else {\r
88 +           fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
89 +           return 1;\r
90 +       }\r
91 +    }\r
92 +\r
93 +    argc -= i;\r
94 +    argv += i;\r
95  \r
96      config = notmuch_config_open (ctx, NULL, NULL);\r
97      if (config == NULL)\r
98 @@ -238,21 +256,29 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
99         return 1;\r
100      }\r
101  \r
102 -    for (threads = notmuch_query_search_threads (query);\r
103 -        notmuch_threads_has_more (threads);\r
104 -        notmuch_threads_advance (threads))\r
105 -    {\r
106 -       thread = notmuch_threads_get (threads);\r
107 +    if (only_matching) {\r
108 +       messages = notmuch_query_search_messages (query);\r
109 +       if (messages == NULL)\r
110 +           INTERNAL_ERROR ("No messages.\n");\r
111 +       show_messages (ctx, messages, 0);\r
112  \r
113 -       messages = notmuch_thread_get_toplevel_messages (thread);\r
114 +    } else {\r
115 +       for (threads = notmuch_query_search_threads (query);\r
116 +               notmuch_threads_has_more (threads);\r
117 +               notmuch_threads_advance (threads))\r
118 +       {\r
119 +           thread = notmuch_threads_get (threads);\r
120  \r
121 -       if (messages == NULL)\r
122 -           INTERNAL_ERROR ("Thread %s has no toplevel messages.\n",\r
123 -                           notmuch_thread_get_thread_id (thread));\r
124 +           messages = notmuch_thread_get_toplevel_messages (thread);\r
125  \r
126 -       show_messages (ctx, messages, 0);\r
127 +           if (messages == NULL)\r
128 +               INTERNAL_ERROR ("Thread %s has no toplevel messages.\n",\r
129 +                       notmuch_thread_get_thread_id (thread));\r
130 +\r
131 +           show_messages (ctx, messages, 0);\r
132  \r
133 -       notmuch_thread_destroy (thread);\r
134 +           notmuch_thread_destroy (thread);\r
135 +       }\r
136      }\r
137  \r
138      notmuch_query_destroy (query);\r
139 diff --git a/notmuch.c b/notmuch.c\r
140 index f45b692..a817ae3 100644\r
141 --- a/notmuch.c\r
142 +++ b/notmuch.c\r
143 @@ -177,6 +177,13 @@ command_t commands[] = {\r
144        "\t\t(all replies to a particular message appear immediately\n"\r
145        "\t\tafter that message in date order).\n"\r
146        "\n"\r
147 +      "\t\tSupported options for show include:\n"\r
148 +      "\n"\r
149 +      "\t\t--only-matching-messages\n"\r
150 +      "\n"\r
151 +      "\t\t\tUsing this option will prevent output of any messages\n"\r
152 +      "\t\t\tthat do not match the search terms.\n"\r
153 +      "\n"\r
154        "\t\tThe output format is plain-text, with all text-content\n"\r
155        "\t\tMIME parts decoded. Various components in the output,\n"\r
156        "\t\t('message', 'header', 'body', 'attachment', and MIME 'part')\n"\r
157 -- \r
158 1.6.4.4.2.gc2f148\r
159 \r