[notmuch] [PATCH -V3] notmuch.el: Support for customizing search result display
[notmuch-archives.git] / 53 / 1c484418cd1ea89dd00cb5140a5d66f168ba21
1 Return-Path: <jan@ryngle.com>\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 A659C431FBC\r
6         for <notmuch@notmuchmail.org>; Thu, 19 Nov 2009 03:52:52 -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 5Lxw47OPei1z for <notmuch@notmuchmail.org>;\r
11         Thu, 19 Nov 2009 03:52:51 -0800 (PST)\r
12 Received: from mail-bw0-f224.google.com (mail-bw0-f224.google.com\r
13         [209.85.218.224])\r
14         by olra.theworths.org (Postfix) with ESMTP id 1BCB0431FAE\r
15         for <notmuch@notmuchmail.org>; Thu, 19 Nov 2009 03:52:50 -0800 (PST)\r
16 Received: by bwz24 with SMTP id 24so1174476bwz.30\r
17         for <notmuch@notmuchmail.org>; Thu, 19 Nov 2009 03:52:50 -0800 (PST)\r
18 MIME-Version: 1.0\r
19 Received: by 10.204.160.73 with SMTP id m9mr6106300bkx.214.1258631569649; Thu,\r
20         19 Nov 2009 03:52:49 -0800 (PST)\r
21 In-Reply-To: <1258630481-5133-2-git-send-email-jan@ryngle.com>\r
22 References: <1258630481-5133-1-git-send-email-jan@ryngle.com>\r
23         <1258630481-5133-2-git-send-email-jan@ryngle.com>\r
24 Date: Thu, 19 Nov 2009 12:52:49 +0100\r
25 Message-ID: <f35dbb950911190352q2dcd041fr83a2f722f3231f44@mail.gmail.com>\r
26 From: Jan Janak <jan@ryngle.com>\r
27 To: notmuch@notmuchmail.org\r
28 Content-Type: text/plain; charset=UTF-8\r
29 Content-Transfer-Encoding: quoted-printable\r
30 Subject: Re: [notmuch] [PATCH 2/2] notmuch list: A new command to produce\r
31         various lists.\r
32 X-BeenThere: notmuch@notmuchmail.org\r
33 X-Mailman-Version: 2.1.12\r
34 Precedence: list\r
35 List-Id: "Use and development of the notmuch mail system."\r
36         <notmuch.notmuchmail.org>\r
37 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
38         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
39 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
40 List-Post: <mailto:notmuch@notmuchmail.org>\r
41 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
42 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
43         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
44 X-List-Received-Date: Thu, 19 Nov 2009 11:52:52 -0000\r
45 \r
46 Carl and others,\r
47 \r
48 I implemented a new notmuch command that can be used to list all tags\r
49 present in the database:\r
50 \r
51   $ notmuch list tags\r
52 \r
53 If you run this, you'll get an alphabetically sorted list of all\r
54 tags--one tag per line.\r
55 \r
56 The main reason why I implemented this is because I am also working on\r
57 adding the tag completion feature to the Emacs mode. This is very\r
58 useful if you have a large collection of tags--it can save you some\r
59 typing and, perhaps more importantly, it minimizes the risk of having\r
60 typos in tag names. I'll send a patch for that later too.\r
61 \r
62 Let me know what do you think.\r
63 \r
64   -- Jan\r
65 \r
66 On Thu, Nov 19, 2009 at 12:34 PM, Jan Janak <jan@ryngle.com> wrote:\r
67 > Here we create a new notmuch command called list. The purpose of the\r
68 > command is to produce various lists from the notmuch database.\r
69 >\r
70 > At the moment we support only one command, notmuch list tags. This\r
71 > command creates a list of all tags found in the database.\r
72 >\r
73 > Signed-off-by: Jan Janak <jan@ryngle.com>\r
74 > ---\r
75 > =C2=A0Makefile.local =C2=A0 | =C2=A0 =C2=A01 +\r
76 > =C2=A0notmuch-client.h | =C2=A0 =C2=A03 ++\r
77 > =C2=A0notmuch-list.c =C2=A0 | =C2=A0 98 +++++++++++++++++++++++++++++++++=\r
78 +++++++++++++++++++++\r
79 > =C2=A0notmuch.c =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 10 +++++\r
80 > =C2=A04 files changed, 112 insertions(+), 0 deletions(-)\r
81 > =C2=A0create mode 100644 notmuch-list.c\r
82 >\r
83 > diff --git a/Makefile.local b/Makefile.local\r
84 > index 27e42ba..fb6d5c3 100644\r
85 > --- a/Makefile.local\r
86 > +++ b/Makefile.local\r
87 > @@ -12,6 +12,7 @@ notmuch_client_srcs =3D =C2=A0 =C2=A0 =C2=A0 =C2=A0 \\r
88 > =C2=A0 =C2=A0 =C2=A0 =C2=A0notmuch-show.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=\r
89 =A0\\r
90 > =C2=A0 =C2=A0 =C2=A0 =C2=A0notmuch-tag.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=\r
91 =A0 \\r
92 > =C2=A0 =C2=A0 =C2=A0 =C2=A0notmuch-time.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=\r
93 =A0\\r
94 > + =C2=A0 =C2=A0notmuch-list.c =C2=A0 =C2=A0 =C2=A0\\r
95 > =C2=A0 =C2=A0 =C2=A0 =C2=A0gmime-filter-reply.c =C2=A0 =C2=A0\\r
96 > =C2=A0 =C2=A0 =C2=A0 =C2=A0query-string.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=\r
97 =A0\\r
98 > =C2=A0 =C2=A0 =C2=A0 =C2=A0show-message.c\r
99 > diff --git a/notmuch-client.h b/notmuch-client.h\r
100 > index b65aa77..ae876b5 100644\r
101 > --- a/notmuch-client.h\r
102 > +++ b/notmuch-client.h\r
103 > @@ -114,6 +114,9 @@ notmuch_show_command (void *ctx, int argc, char *argv=\r
104 []);\r
105 > =C2=A0int\r
106 > =C2=A0notmuch_tag_command (void *ctx, int argc, char *argv[]);\r
107 >\r
108 > +int\r
109 > +notmuch_list_command (void *ctx, int argc, char *argv[]);\r
110 > +\r
111 > =C2=A0const char *\r
112 > =C2=A0notmuch_time_relative_date (const void *ctx, time_t then);\r
113 >\r
114 > diff --git a/notmuch-list.c b/notmuch-list.c\r
115 > new file mode 100644\r
116 > index 0000000..fe71108\r
117 > --- /dev/null\r
118 > +++ b/notmuch-list.c\r
119 > @@ -0,0 +1,98 @@\r
120 > +/* notmuch - Not much of an email program, (just index and search)\r
121 > + *\r
122 > + * Copyright =C2=A9 2009 Carl Worth\r
123 > + * Copyright =C2=A9 2009 Jan Janak\r
124 > + *\r
125 > + * This program is free software: you can redistribute it and/or modify\r
126 > + * it under the terms of the GNU General Public License as published by\r
127 > + * the Free Software Foundation, either version 3 of the License, or\r
128 > + * (at your option) any later version.\r
129 > + *\r
130 > + * This program is distributed in the hope that it will be useful,\r
131 > + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
132 > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =C2=A0See the\r
133 > + * GNU General Public License for more details.\r
134 > + *\r
135 > + * You should have received a copy of the GNU General Public License\r
136 > + * along with this program. =C2=A0If not, see http://www.gnu.org/license=\r
137 s/ .\r
138 > + *\r
139 > + * Authors: Carl Worth <cworth@cworth.org>\r
140 > + * =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Jan Janak <jan@ryngle.com>\r
141 > + */\r
142 > +\r
143 > +#include "notmuch-client.h"\r
144 > +\r
145 > +enum list_cmd {\r
146 > + =C2=A0 =C2=A0 =C2=A0 LIST_TAGS\r
147 > +};\r
148 > +\r
149 > +\r
150 > +static int\r
151 > +list_all_tags(notmuch_database_t* db)\r
152 > +{\r
153 > + =C2=A0 =C2=A0 =C2=A0 notmuch_tags_t* tags;\r
154 > + =C2=A0 =C2=A0 =C2=A0 const char* t;\r
155 > +\r
156 > + =C2=A0 =C2=A0 =C2=A0 if ((tags =3D notmuch_database_get_tags(db)) =3D=\r
157 =3D NULL) {\r
158 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(stderr, "Error=\r
159  while obtaining tags from the database.\n");\r
160 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return 1;\r
161 > + =C2=A0 =C2=A0 =C2=A0 }\r
162 > +\r
163 > + =C2=A0 =C2=A0 =C2=A0 while((t =3D notmuch_tags_get(tags))) {\r
164 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf("%s\n", t);\r
165 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 notmuch_tags_advance(t=\r
166 ags);\r
167 > + =C2=A0 =C2=A0 =C2=A0 }\r
168 > +\r
169 > + =C2=A0 =C2=A0 =C2=A0 notmuch_tags_destroy(tags);\r
170 > + =C2=A0 =C2=A0 =C2=A0 return 0;\r
171 > +}\r
172 > +\r
173 > +int\r
174 > +notmuch_list_command (void *ctx, int argc, char *argv[])\r
175 > +{\r
176 > + =C2=A0 =C2=A0notmuch_config_t *config;\r
177 > + =C2=A0 =C2=A0notmuch_database_t *db;\r
178 > + =C2=A0 =C2=A0 =C2=A0 enum list_cmd cmd;\r
179 > +\r
180 > + =C2=A0 =C2=A0 =C2=A0 config =3D NULL;\r
181 > + =C2=A0 =C2=A0 =C2=A0 db =3D NULL;\r
182 > +\r
183 > + =C2=A0 =C2=A0 =C2=A0 if (argc < 1) {\r
184 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(stderr, "Error=\r
185 : notmuch list requires at least one parameter.\n");\r
186 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(stderr, "(See =\r
187 notmuch help list)\n");\r
188 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto error;\r
189 > + =C2=A0 =C2=A0 =C2=A0 }\r
190 > +\r
191 > + =C2=A0 =C2=A0 =C2=A0 if (!strcmp(argv[0], "tags")) {\r
192 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cmd =3D LIST_TAGS;\r
193 > + =C2=A0 =C2=A0 =C2=A0 } else {\r
194 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(stderr, "Sub-c=\r
195 ommand '%s' not supported.\n", argv[0]);\r
196 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto error;\r
197 > + =C2=A0 =C2=A0 =C2=A0 }\r
198 > +\r
199 > + =C2=A0 =C2=A0if ((config =3D notmuch_config_open (ctx, NULL, NULL)) =3D=\r
200 =3D NULL) {\r
201 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto error;\r
202 > + =C2=A0 =C2=A0 =C2=A0 }\r
203 > +\r
204 > + =C2=A0 =C2=A0db =3D notmuch_database_open (notmuch_config_get_database_=\r
205 path (config));\r
206 > + =C2=A0 =C2=A0if (db =3D=3D NULL) {\r
207 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto error;\r
208 > + =C2=A0 =C2=A0 =C2=A0 }\r
209 > +\r
210 > + =C2=A0 =C2=A0 =C2=A0 switch(cmd) {\r
211 > + =C2=A0 =C2=A0 =C2=A0 case LIST_TAGS:\r
212 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (list_all_tags(db) =\r
213 !=3D 0) goto error;\r
214 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break;\r
215 > +\r
216 > + =C2=A0 =C2=A0 =C2=A0 default:\r
217 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(stderr, "Unsup=\r
218 ported command: bug in notmuch_list_command.\n");\r
219 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto error;\r
220 > + =C2=A0 =C2=A0 =C2=A0 }\r
221 > +\r
222 > + =C2=A0 =C2=A0notmuch_database_close (db);\r
223 > + =C2=A0 =C2=A0return 0;\r
224 > +\r
225 > +error:\r
226 > + =C2=A0 =C2=A0 =C2=A0 if (db) notmuch_database_close(db);\r
227 > + =C2=A0 =C2=A0 =C2=A0 return 1;\r
228 > +}\r
229 > diff --git a/notmuch.c b/notmuch.c\r
230 > index 5cc8e4c..1baa22d 100644\r
231 > --- a/notmuch.c\r
232 > +++ b/notmuch.c\r
233 > @@ -230,6 +230,16 @@ command_t commands[] =3D {\r
234 > =C2=A0 =C2=A0 =C2=A0 "\t\tSo if you've previously been using sup for mail=\r
235 , then the\n"\r
236 > =C2=A0 =C2=A0 =C2=A0 "\t\t\"notmuch restore\" command provides you a way =\r
237 to import\n"\r
238 > =C2=A0 =C2=A0 =C2=A0 "\t\tall of your tags (or labels as sup calls them).=\r
239 " },\r
240 > + =C2=A0 =C2=A0 =C2=A0 { "list", notmuch_list_command,\r
241 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "<what>",\r
242 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\t\tShow additional information about the =\r
243 database.",\r
244 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\t\tThe following sub-commands are support=\r
245 ed:"\r
246 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\n\n"\r
247 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\t\ttags\n"\r
248 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\n"\r
249 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\t\t\tGenerate a list of all tags availabl=\r
250 e in the database.\n"\r
251 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\t\t\tThe list will be sorted alphabetical=\r
252 ly."\r
253 > + =C2=A0 =C2=A0 =C2=A0 },\r
254 > =C2=A0 =C2=A0 { "help", notmuch_help_command,\r
255 > =C2=A0 =C2=A0 =C2=A0 "[<command>]",\r
256 > =C2=A0 =C2=A0 =C2=A0 "\t\tThis message, or more detailed help for the nam=\r
257 ed command.",\r
258 > --\r
259 > 1.6.3.3\r
260 >\r
261 >\r
262 > _______________________________________________\r
263 > notmuch mailing list\r
264 > notmuch@notmuchmail.org\r
265 > http://notmuchmail.org/mailman/listinfo/notmuch\r
266 >\r
267 >\r