Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 7f / e49b5935ce5fcd72b58173e0b35a065fa6639e
1 Return-Path: <m.walters@qmul.ac.uk>\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 4EDB7431FC2\r
6         for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 00:57:32 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.098\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
12         tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
13         NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id yzYOKyUeujCO for <notmuch@notmuchmail.org>;\r
17         Thu, 30 Oct 2014 00:57:24 -0700 (PDT)\r
18 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id CD92D431FB6\r
22         for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 00:57:23 -0700 (PDT)\r
23 Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
24         by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
25         (envelope-from <m.walters@qmul.ac.uk>)\r
26         id 1Xjkbc-0002Co-7F; Thu, 30 Oct 2014 07:57:18 +0000\r
27 Received: from 5751dfa2.skybroadband.com ([87.81.223.162] helo=localhost)\r
28         by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71)\r
29         (envelope-from <m.walters@qmul.ac.uk>)\r
30         id 1Xjkbb-0006HX-Ao; Thu, 30 Oct 2014 07:57:15 +0000\r
31 From: Mark Walters <markwalters1009@gmail.com>\r
32 To: Michal Sojka <sojkam1@fel.cvut.cz>, notmuch@notmuchmail.org\r
33 Subject: Re: [PATCH v4 1/6] cli: search: Refactor passing of command line\r
34         options\r
35 In-Reply-To: <1414421455-3037-2-git-send-email-sojkam1@fel.cvut.cz>\r
36 References: <1414421455-3037-1-git-send-email-sojkam1@fel.cvut.cz>\r
37         <1414421455-3037-2-git-send-email-sojkam1@fel.cvut.cz>\r
38 User-Agent: Notmuch/0.18.1+86~gef5e66a (http://notmuchmail.org) Emacs/23.4.1\r
39         (x86_64-pc-linux-gnu)\r
40 Date: Thu, 30 Oct 2014 07:57:13 +0000\r
41 Message-ID: <87k33iuh0m.fsf@qmul.ac.uk>\r
42 MIME-Version: 1.0\r
43 Content-Type: text/plain; charset=us-ascii\r
44 X-Sender-Host-Address: 87.81.223.162\r
45 X-QM-Geographic: According to ripencc,\r
46         this message was delivered by a machine in Britain (UK) (GB).\r
47 X-QM-SPAM-Info: Sender has good ham record.  :)\r
48 X-QM-Body-MD5: 437f328dfd942f72761fd2e8207125bd (of first 20000 bytes)\r
49 X-SpamAssassin-Score: -0.1\r
50 X-SpamAssassin-SpamBar: /\r
51 X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
52         determine if it is\r
53         spam. We require at least 5.0 points to mark a message as spam.\r
54         This message scored -0.1 points.\r
55         Summary of the scoring: \r
56         * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
57         provider *      (markwalters1009[at]gmail.com)\r
58         * -0.1 AWL AWL: From: address is in the auto white-list\r
59 X-QM-Scan-Virus: ClamAV says the message is clean\r
60 X-BeenThere: notmuch@notmuchmail.org\r
61 X-Mailman-Version: 2.1.13\r
62 Precedence: list\r
63 List-Id: "Use and development of the notmuch mail system."\r
64         <notmuch.notmuchmail.org>\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
68 List-Post: <mailto:notmuch@notmuchmail.org>\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
72 X-List-Received-Date: Thu, 30 Oct 2014 07:57:32 -0000\r
73 \r
74 \r
75 Hi\r
76 \r
77 On Mon, 27 Oct 2014, Michal Sojka <sojkam1@fel.cvut.cz> wrote:\r
78 > Many functions that implement the search command need to access command\r
79 > line options. Instead of passing each option in a separate variable, put\r
80 > them in a structure and pass only this structure.\r
81 >\r
82 > This will become handy in the following patches.\r
83 > ---\r
84 >  notmuch-search.c | 125 ++++++++++++++++++++++++++++---------------------------\r
85 >  1 file changed, 64 insertions(+), 61 deletions(-)\r
86 >\r
87 > diff --git a/notmuch-search.c b/notmuch-search.c\r
88 > index bc9be45..0c3e972 100644\r
89 > --- a/notmuch-search.c\r
90 > +++ b/notmuch-search.c\r
91 > @@ -30,6 +30,16 @@ typedef enum {\r
92 >      OUTPUT_TAGS\r
93 >  } output_t;\r
94 >  \r
95 > +typedef struct {\r
96 > +    sprinter_t *format;\r
97 > +    notmuch_query_t *query;\r
98 > +    notmuch_sort_t sort;\r
99 > +    output_t output;\r
100 > +    int offset;\r
101 > +    int limit;\r
102 > +    int dupe;\r
103 > +} search_options_t;\r
104 > +\r
105 >  /* Return two stable query strings that identify exactly the matched\r
106 >   * and unmatched messages currently in thread.  If there are no\r
107 >   * matched or unmatched messages, the returned buffers will be\r
108 > @@ -70,43 +80,39 @@ get_thread_query (notmuch_thread_t *thread,\r
109 >  }\r
110 >  \r
111 >  static int\r
112 > -do_search_threads (sprinter_t *format,\r
113 > -                notmuch_query_t *query,\r
114 > -                notmuch_sort_t sort,\r
115 > -                output_t output,\r
116 > -                int offset,\r
117 > -                int limit)\r
118 > +do_search_threads (search_options_t *opt)\r
119 >  {\r
120 >      notmuch_thread_t *thread;\r
121 >      notmuch_threads_t *threads;\r
122 >      notmuch_tags_t *tags;\r
123 > +    sprinter_t *format = opt->format;\r
124 >      time_t date;\r
125 >      int i;\r
126 >  \r
127 > -    if (offset < 0) {\r
128 > -     offset += notmuch_query_count_threads (query);\r
129 > -     if (offset < 0)\r
130 > -         offset = 0;\r
131 > +    if (opt->offset < 0) {\r
132 > +     opt->offset += notmuch_query_count_threads (opt->query);\r
133 > +     if (opt->offset < 0)\r
134 > +         opt->offset = 0;\r
135 >      }\r
136 >  \r
137 > -    threads = notmuch_query_search_threads (query);\r
138 > +    threads = notmuch_query_search_threads (opt->query);\r
139 >      if (threads == NULL)\r
140 >       return 1;\r
141 >  \r
142 >      format->begin_list (format);\r
143 >  \r
144 >      for (i = 0;\r
145 > -      notmuch_threads_valid (threads) && (limit < 0 || i < offset + limit);\r
146 > +      notmuch_threads_valid (threads) && (opt->limit < 0 || i < opt->offset + opt->limit);\r
147 >        notmuch_threads_move_to_next (threads), i++)\r
148 >      {\r
149 >       thread = notmuch_threads_get (threads);\r
150 >  \r
151 > -     if (i < offset) {\r
152 > +     if (i < opt->offset) {\r
153 >           notmuch_thread_destroy (thread);\r
154 >           continue;\r
155 >       }\r
156 >  \r
157 > -     if (output == OUTPUT_THREADS) {\r
158 > +     if (opt->output == OUTPUT_THREADS) {\r
159 >           format->set_prefix (format, "thread");\r
160 >           format->string (format,\r
161 >                           notmuch_thread_get_thread_id (thread));\r
162 > @@ -123,7 +129,7 @@ do_search_threads (sprinter_t *format,\r
163 >  \r
164 >           format->begin_map (format);\r
165 >  \r
166 > -         if (sort == NOTMUCH_SORT_OLDEST_FIRST)\r
167 > +         if (opt->sort == NOTMUCH_SORT_OLDEST_FIRST)\r
168 >               date = notmuch_thread_get_oldest_date (thread);\r
169 >           else\r
170 >               date = notmuch_thread_get_newest_date (thread);\r
171 > @@ -215,40 +221,36 @@ do_search_threads (sprinter_t *format,\r
172 >  }\r
173 >  \r
174 >  static int\r
175 > -do_search_messages (sprinter_t *format,\r
176 > -                 notmuch_query_t *query,\r
177 > -                 output_t output,\r
178 > -                 int offset,\r
179 > -                 int limit,\r
180 > -                 int dupe)\r
181 > +do_search_messages (search_options_t *opt)\r
182 >  {\r
183 >      notmuch_message_t *message;\r
184 >      notmuch_messages_t *messages;\r
185 >      notmuch_filenames_t *filenames;\r
186 > +    sprinter_t *format = opt->format;\r
187 >      int i;\r
188 >  \r
189 > -    if (offset < 0) {\r
190 > -     offset += notmuch_query_count_messages (query);\r
191 > -     if (offset < 0)\r
192 > -         offset = 0;\r
193 > +    if (opt->offset < 0) {\r
194 > +     opt->offset += notmuch_query_count_messages (opt->query);\r
195 > +     if (opt->offset < 0)\r
196 > +         opt->offset = 0;\r
197 >      }\r
198 >  \r
199 > -    messages = notmuch_query_search_messages (query);\r
200 > +    messages = notmuch_query_search_messages (opt->query);\r
201 >      if (messages == NULL)\r
202 >       return 1;\r
203 >  \r
204 >      format->begin_list (format);\r
205 >  \r
206 >      for (i = 0;\r
207 > -      notmuch_messages_valid (messages) && (limit < 0 || i < offset + limit);\r
208 > +      notmuch_messages_valid (messages) && (opt->limit < 0 || i < opt->offset + opt->limit);\r
209 >        notmuch_messages_move_to_next (messages), i++)\r
210 >      {\r
211 > -     if (i < offset)\r
212 > +     if (i < opt->offset)\r
213 >           continue;\r
214 >  \r
215 >       message = notmuch_messages_get (messages);\r
216 >  \r
217 > -     if (output == OUTPUT_FILES) {\r
218 > +     if (opt->output == OUTPUT_FILES) {\r
219 >           int j;\r
220 >           filenames = notmuch_message_get_filenames (message);\r
221 >  \r
222 > @@ -256,7 +258,7 @@ do_search_messages (sprinter_t *format,\r
223 >                notmuch_filenames_valid (filenames);\r
224 >                notmuch_filenames_move_to_next (filenames), j++)\r
225 >           {\r
226 > -             if (dupe < 0 || dupe == j) {\r
227 > +             if (opt->dupe < 0 || opt->dupe == j) {\r
228 >                   format->string (format, notmuch_filenames_get (filenames));\r
229 >                   format->separator (format);\r
230 >               }\r
231 > @@ -283,12 +285,13 @@ do_search_messages (sprinter_t *format,\r
232 >  \r
233 >  static int\r
234 >  do_search_tags (notmuch_database_t *notmuch,\r
235 > -             sprinter_t *format,\r
236 > -             notmuch_query_t *query)\r
237 > +             const search_options_t *opt)\r
238 >  {\r
239 \r
240 What about leaving out the *notmuch argument and getting that from the\r
241 query (query->notmuch I think)? \r
242 \r
243 Otherwise this looks good to me.\r
244 \r
245 Best wishes\r
246 \r
247 Mark\r
248 \r
249 >      notmuch_messages_t *messages = NULL;\r
250 >      notmuch_tags_t *tags;\r
251 >      const char *tag;\r
252 > +    sprinter_t *format = opt->format;\r
253 > +    notmuch_query_t *query = opt->query;\r
254 >  \r
255 >      /* should the following only special case if no excluded terms\r
256 >       * specified? */\r
257 > @@ -333,16 +336,16 @@ int\r
258 >  notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
259 >  {\r
260 >      notmuch_database_t *notmuch;\r
261 > -    notmuch_query_t *query;\r
262 > +    search_options_t opt = {\r
263 > +     .sort = NOTMUCH_SORT_NEWEST_FIRST,\r
264 > +     .output = OUTPUT_SUMMARY,\r
265 > +     .offset = 0,\r
266 > +     .limit = -1, /* unlimited */\r
267 > +     .dupe = -1,\r
268 > +    };\r
269 >      char *query_str;\r
270 > -    notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST;\r
271 > -    sprinter_t *format = NULL;\r
272 >      int opt_index, ret;\r
273 > -    output_t output = OUTPUT_SUMMARY;\r
274 > -    int offset = 0;\r
275 > -    int limit = -1; /* unlimited */\r
276 >      notmuch_exclude_t exclude = NOTMUCH_EXCLUDE_TRUE;\r
277 > -    int dupe = -1;\r
278 >      unsigned int i;\r
279 >  \r
280 >      enum {\r
281 > @@ -353,7 +356,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
282 >      } format_sel = NOTMUCH_FORMAT_TEXT;\r
283 >  \r
284 >      notmuch_opt_desc_t options[] = {\r
285 > -     { NOTMUCH_OPT_KEYWORD, &sort, "sort", 's',\r
286 > +     { NOTMUCH_OPT_KEYWORD, &opt.sort, "sort", 's',\r
287 >         (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },\r
288 >                                 { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },\r
289 >                                 { 0, 0 } } },\r
290 > @@ -364,7 +367,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
291 >                                 { "text0", NOTMUCH_FORMAT_TEXT0 },\r
292 >                                 { 0, 0 } } },\r
293 >       { NOTMUCH_OPT_INT, &notmuch_format_version, "format-version", 0, 0 },\r
294 > -     { NOTMUCH_OPT_KEYWORD, &output, "output", 'o',\r
295 > +     { NOTMUCH_OPT_KEYWORD, &opt.output, "output", 'o',\r
296 >         (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },\r
297 >                                 { "threads", OUTPUT_THREADS },\r
298 >                                 { "messages", OUTPUT_MESSAGES },\r
299 > @@ -377,9 +380,9 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
300 >                                    { "flag", NOTMUCH_EXCLUDE_FLAG },\r
301 >                                    { "all", NOTMUCH_EXCLUDE_ALL },\r
302 >                                    { 0, 0 } } },\r
303 > -     { NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 },\r
304 > -     { NOTMUCH_OPT_INT, &limit, "limit", 'L', 0  },\r
305 > -     { NOTMUCH_OPT_INT, &dupe, "duplicate", 'D', 0  },\r
306 > +     { NOTMUCH_OPT_INT, &opt.offset, "offset", 'O', 0 },\r
307 > +     { NOTMUCH_OPT_INT, &opt.limit, "limit", 'L', 0  },\r
308 > +     { NOTMUCH_OPT_INT, &opt.dupe, "duplicate", 'D', 0  },\r
309 >       { 0, 0, 0, 0, 0 }\r
310 >      };\r
311 >  \r
312 > @@ -389,20 +392,20 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
313 >  \r
314 >      switch (format_sel) {\r
315 >      case NOTMUCH_FORMAT_TEXT:\r
316 > -     format = sprinter_text_create (config, stdout);\r
317 > +     opt.format = sprinter_text_create (config, stdout);\r
318 >       break;\r
319 >      case NOTMUCH_FORMAT_TEXT0:\r
320 > -     if (output == OUTPUT_SUMMARY) {\r
321 > +     if (opt.output == OUTPUT_SUMMARY) {\r
322 >           fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n");\r
323 >           return EXIT_FAILURE;\r
324 >       }\r
325 > -     format = sprinter_text0_create (config, stdout);\r
326 > +     opt.format = sprinter_text0_create (config, stdout);\r
327 >       break;\r
328 >      case NOTMUCH_FORMAT_JSON:\r
329 > -     format = sprinter_json_create (config, stdout);\r
330 > +     opt.format = sprinter_json_create (config, stdout);\r
331 >       break;\r
332 >      case NOTMUCH_FORMAT_SEXP:\r
333 > -     format = sprinter_sexp_create (config, stdout);\r
334 > +     opt.format = sprinter_sexp_create (config, stdout);\r
335 >       break;\r
336 >      default:\r
337 >       /* this should never happen */\r
338 > @@ -425,15 +428,15 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
339 >       return EXIT_FAILURE;\r
340 >      }\r
341 >  \r
342 > -    query = notmuch_query_create (notmuch, query_str);\r
343 > -    if (query == NULL) {\r
344 > +    opt.query = notmuch_query_create (notmuch, query_str);\r
345 > +    if (opt.query == NULL) {\r
346 >       fprintf (stderr, "Out of memory\n");\r
347 >       return EXIT_FAILURE;\r
348 >      }\r
349 >  \r
350 > -    notmuch_query_set_sort (query, sort);\r
351 > +    notmuch_query_set_sort (opt.query, opt.sort);\r
352 >  \r
353 > -    if (exclude == NOTMUCH_EXCLUDE_FLAG && output != OUTPUT_SUMMARY) {\r
354 > +    if (exclude == NOTMUCH_EXCLUDE_FLAG && opt.output != OUTPUT_SUMMARY) {\r
355 >       /* If we are not doing summary output there is nowhere to\r
356 >        * print the excluded flag so fall back on including the\r
357 >        * excluded messages. */\r
358 > @@ -448,29 +451,29 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
359 >       search_exclude_tags = notmuch_config_get_search_exclude_tags\r
360 >           (config, &search_exclude_tags_length);\r
361 >       for (i = 0; i < search_exclude_tags_length; i++)\r
362 > -         notmuch_query_add_tag_exclude (query, search_exclude_tags[i]);\r
363 > -     notmuch_query_set_omit_excluded (query, exclude);\r
364 > +         notmuch_query_add_tag_exclude (opt.query, search_exclude_tags[i]);\r
365 > +     notmuch_query_set_omit_excluded (opt.query, exclude);\r
366 >      }\r
367 >  \r
368 > -    switch (output) {\r
369 > +    switch (opt.output) {\r
370 >      default:\r
371 >      case OUTPUT_SUMMARY:\r
372 >      case OUTPUT_THREADS:\r
373 > -     ret = do_search_threads (format, query, sort, output, offset, limit);\r
374 > +     ret = do_search_threads (&opt);\r
375 >       break;\r
376 >      case OUTPUT_MESSAGES:\r
377 >      case OUTPUT_FILES:\r
378 > -     ret = do_search_messages (format, query, output, offset, limit, dupe);\r
379 > +     ret = do_search_messages (&opt);\r
380 >       break;\r
381 >      case OUTPUT_TAGS:\r
382 > -     ret = do_search_tags (notmuch, format, query);\r
383 > +     ret = do_search_tags (notmuch, &opt);\r
384 >       break;\r
385 >      }\r
386 >  \r
387 > -    notmuch_query_destroy (query);\r
388 > +    notmuch_query_destroy (opt.query);\r
389 >      notmuch_database_destroy (notmuch);\r
390 >  \r
391 > -    talloc_free (format);\r
392 > +    talloc_free (opt.format);\r
393 >  \r
394 >      return ret ? EXIT_FAILURE : EXIT_SUCCESS;\r
395 >  }\r
396 > -- \r
397 > 2.1.1\r
398 >\r
399 > _______________________________________________\r
400 > notmuch mailing list\r
401 > notmuch@notmuchmail.org\r
402 > http://notmuchmail.org/mailman/listinfo/notmuch\r