Re: Error with contrib/notmuch-pick
[notmuch-archives.git] / e0 / 6741afe31804f8fb0a98dd08ee61c3f0cd5644
1 Return-Path: <amdragon@mit.edu>\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 E8234431FAF\r
6         for <notmuch@notmuchmail.org>; Sat, 21 Jan 2012 14:04:34 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id tRg74xEG--gV for <notmuch@notmuchmail.org>;\r
16         Sat, 21 Jan 2012 14:04:34 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
18         [18.7.68.34])\r
19         by olra.theworths.org (Postfix) with ESMTP id 3C86A431FAE\r
20         for <notmuch@notmuchmail.org>; Sat, 21 Jan 2012 14:04:34 -0800 (PST)\r
21 X-AuditID: 12074422-b7fd66d0000008f9-88-4f1b36712b86\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id D9.F9.02297.1763B1F4; Sat, 21 Jan 2012 17:04:33 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0LM4WG0005438; \r
27         Sat, 21 Jan 2012 17:04:33 -0500\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0LM4Up6017078\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Sat, 21 Jan 2012 17:04:31 -0500 (EST)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1Roj2d-0008Sa-4N; Sat, 21 Jan 2012 17:04:07 -0500\r
37 Date: Sat, 21 Jan 2012 17:04:07 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Peter Feigl <craven@gmx.net>\r
40 Subject: Re: [PATCH] rewriting notmuch-search for structured output to make\r
41         other output formats easier\r
42 Message-ID: <20120121220407.GK16740@mit.edu>\r
43 References: <1327180568-30385-1-git-send-email-craven@gmx.net>\r
44 MIME-Version: 1.0\r
45 Content-Type: text/plain; charset=us-ascii\r
46 Content-Disposition: inline\r
47 In-Reply-To: <1327180568-30385-1-git-send-email-craven@gmx.net>\r
48 User-Agent: Mutt/1.5.21 (2010-09-15)\r
49 X-Brightmail-Tracker:\r
50  H4sIAAAAAAAAA+NgFuphleLIzCtJLcpLzFFi42IRYrdT1y00k/Y3eHRf3mJvQzujxfWbM5kd\r
51         mDwWb9rP5vFs1S3mAKYoLpuU1JzMstQifbsErozuiz9ZCs6KVdx5MJexgXG9UBcjJ4eEgInE\r
52         p9vTWCBsMYkL99azgdhCAvsYJZ4ui+9i5AKyNzBKrNq1kh3COckk8WPSXTYIZwmjREfTftYu\r
53         Rg4OFgFVie5/wiDdbAIaEtv2L2cEsUUEFCSerWsCs5kFpCW+/W5mAikXFsiUuNgeBGLyCuhI\r
54         LFtqDbHXTmLf3L3MIDavgKDEyZlPWCA6tSRu/HsJ1gkyZfk/DpAwp4C9xPovu9lBbFEBFYkp\r
55         J7exTWAUmoWkexaS7lkI3QsYmVcxyqbkVunmJmbmFKcm6xYnJ+blpRbpmurlZpbopaaUbmIE\r
56         B7SL0g7GnweVDjEKcDAq8fAm7JP0F2JNLCuuzD3EKMnBpCTKm2Io7S/El5SfUpmRWJwRX1Sa\r
57         k1p8iFGCg1lJhLesC6icNyWxsiq1KB8mJc3BoiTOq671zk9IID2xJDU7NbUgtQgmK8PBoSTB\r
58         +9cUaKhgUWp6akVaZk4JQpqJgxNkOA/Q8HsgNbzFBYm5xZnpEPlTjLocX363nWcUYsnLz0uV\r
59         EufdA1IkAFKUUZoHNweWiF4xigO9Jcz7FaSKB5jE4Ca9AlrCBLSEI08KZElJIkJKqoHRJ/zc\r
60         9zy7d8XCkVOuuEYxV77+8eroU6kdzx8J5hg82cX267k1/wLLv0IBIZc/XhQV/3bN2ITv+9Un\r
61         huc5BWc/5n1fvMu24dn8D9c7a8Tz1yd86V/OXbX8HsuSw5fn9P41Uz71WNEy7xnPOtVtWgWO\r
62         sldufRZq/9UYJvHdR2LtX2E3jQf+/RqzlFiKMxINtZiLihMBg0hRsx8DAAA=\r
63 Cc: notmuch@notmuchmail.org\r
64 X-BeenThere: notmuch@notmuchmail.org\r
65 X-Mailman-Version: 2.1.13\r
66 Precedence: list\r
67 List-Id: "Use and development of the notmuch mail system."\r
68         <notmuch.notmuchmail.org>\r
69 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
71 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
72 List-Post: <mailto:notmuch@notmuchmail.org>\r
73 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
74 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
75         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
76 X-List-Received-Date: Sat, 21 Jan 2012 22:04:35 -0000\r
77 \r
78 Quoth Peter Feigl on Jan 21 at 10:16 pm:\r
79 > The output routines have been rewritten so that logical structure\r
80 > (objects with key/value pairs, arrays, strings and numbers) are\r
81 > written instead of ad-hoc printfs. This allows for easier adaptation\r
82 > of other output formats, as only the routines that start/end an object\r
83 > etc. have to be rewritten. The logic is the same for all formats.\r
84 > The default text output is handled differently, special cases are\r
85 > inserted at the proper places, as it differs too much from the\r
86 > structured output.\r
87 \r
88 I think this is a great idea and I'm a fan of having an S-expression\r
89 format, but I also think there's a much easier and more general way to\r
90 structure this.\r
91 \r
92 In particular, I don't think you should hijack search_format, since\r
93 you'll wind up repeating most of this work for anything else that\r
94 needs to output structured data (notmuch show, at least).  Rather, I'd\r
95 suggest creating a general "structure printer" struct that isn't tied\r
96 to search.  You've essentially already done this, you just called it\r
97 search_format.  Then, leave the existing format callbacks in place,\r
98 just use this new API instead of lots of printf calls.\r
99 \r
100 What about all of those annoying {tag,item}_{start,sep,end} fields?  I\r
101 think you can simultaneously get rid of those *and* simplify the\r
102 structure printer API.  If the structure printer is allowed to keep a\r
103 little state, it can automatically insert separators.  With a little\r
104 nesting state, it could even insert terminators by just saying "pop me\r
105 to this level".  This could probably be better, but I'm imagining\r
106 something like\r
107 \r
108 struct sprinter *\r
109 new_json_sprinter (const void *ctx, FILE *stream);\r
110 struct sprinter *\r
111 new_sexp_sprinter (const void *ctx, FILE *stream);\r
112 \r
113 /* Start a map (a JSON object or a S-expression alist/plist/whatever)\r
114  * and return the nesting level of the map. */\r
115 int\r
116 sprinter_map (struct sprinter *sp);\r
117 /* Start a list (aka array) and return the nesting level of the list. */\r
118 int\r
119 sprinter_list (struct sprinter *sp);\r
120 \r
121 /* Close maps and lists until reaching level. */\r
122 void\r
123 sprinter_pop (struct sprinter *sp, int level);\r
124 \r
125 void\r
126 sprinter_map_key (struct sprinter *sp, const char *key);\r
127 void\r
128 sprinter_number (struct sprinter *sp, int val);\r
129 void\r
130 sprinter_string (struct sprinter *sp, const char *val);\r
131 void\r
132 sprinter_bool (struct sprinter *sp, notmuch_bool_t val);\r
133 \r
134 and that's it.  This would also subsume your format_attribute_*\r
135 helpers.\r
136 \r
137 Unfortunately, it's a pain to pass things like a structure printer\r
138 object around formatters (too bad notmuch isn't written in C++, eh?).\r
139 I think it's better to address this than to structure around it.\r
140 Probably the simplest thing to do is to make a struct for formatter\r
141 state and pass that in to the callbacks.  You could also more\r
142 completely emulate classes, but that would probably be overkill for\r
143 this.\r