Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / f1 / 5570a49071ba698c6ab2d9c914d2749082d965
1 Return-Path: <craven@gmx.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 29153431FC9\r
6         for <notmuch@notmuchmail.org>; Thu, 12 Jul 2012 00:42:21 -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: 0.001\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.001 tagged_above=-999 required=5\r
12         tests=[FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001]\r
13         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 kH1GQ0bvk8eU for <notmuch@notmuchmail.org>;\r
17         Thu, 12 Jul 2012 00:42:19 -0700 (PDT)\r
18 Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.22])\r
19         by olra.theworths.org (Postfix) with SMTP id E8F5B429E4B\r
20         for <notmuch@notmuchmail.org>; Thu, 12 Jul 2012 00:42:15 -0700 (PDT)\r
21 Received: (qmail invoked by alias); 12 Jul 2012 07:42:03 -0000\r
22 Received: from gw.arelion.cust.net.lagis.at (EHLO dodekanex.arelion.at)\r
23         [83.164.197.182]\r
24         by mail.gmx.net (mp030) with SMTP; 12 Jul 2012 09:42:03 +0200\r
25 X-Authenticated: #201305\r
26 X-Provags-ID: V01U2FsdGVkX1/sUeJEZpbsAZ2RhLXfCrmVKmhokI92GbzUxdJC3b\r
27         1C2Le4WrIjDPca\r
28 Received: by dodekanex.arelion.at (Postfix, from userid 1000)\r
29         id 1F6593011A8; Thu, 12 Jul 2012 09:43:30 +0200 (CEST)\r
30 From: <craven@gmx.net>\r
31 To: notmuch@notmuchmail.org\r
32 Subject: [PATCH v4 1/3] Add support for structured output formatters.\r
33 Date: Thu, 12 Jul 2012 09:43:22 +0200\r
34 Message-Id: <1342079004-5300-2-git-send-email-craven@gmx.net>\r
35 X-Mailer: git-send-email 1.7.11.1\r
36 In-Reply-To: <1342079004-5300-1-git-send-email-craven@gmx.net>\r
37 References: <87d34hsdx8.fsf@awakening.csail.mit.edu>\r
38         <1342079004-5300-1-git-send-email-craven@gmx.net>\r
39 X-Y-GMX-Trusted: 0\r
40 X-BeenThere: notmuch@notmuchmail.org\r
41 X-Mailman-Version: 2.1.13\r
42 Precedence: list\r
43 List-Id: "Use and development of the notmuch mail system."\r
44         <notmuch.notmuchmail.org>\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
48 List-Post: <mailto:notmuch@notmuchmail.org>\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
52 X-List-Received-Date: Thu, 12 Jul 2012 07:42:21 -0000\r
53 \r
54 This patch adds a new type sprinter_t, which is used for structured\r
55 formatting, e.g. JSON or S-Expressions. The structure printer is the\r
56 code from Austin Clements (id:87d34hsdx8.fsf@awakening.csail.mit.edu).\r
57 \r
58 The structure printer contains the following function pointers:\r
59 \r
60 /* start a new map/dictionary structure.\r
61  */\r
62 void (*begin_map) (struct sprinter *);\r
63 \r
64 /* start a new list/array structure\r
65  */\r
66 void (*begin_list) (struct sprinter *);\r
67 \r
68 /* end the last opened list or map structure\r
69  */\r
70 void (*end) (struct sprinter *);\r
71 \r
72 /* print one string/integer/boolean/null element (possibly inside a\r
73  * list or map\r
74  */\r
75 void (*string) (struct sprinter *, const char *);\r
76 void (*integer) (struct sprinter *, int);\r
77 void (*boolean) (struct sprinter *, notmuch_bool_t);\r
78 void (*null) (struct sprinter *);\r
79 \r
80 /* print the key of a map's key/value pair.\r
81  */\r
82 void (*map_key) (struct sprinter *, const char *);\r
83 \r
84 /* print a frame delimiter (such as a newline or extra whitespace)\r
85  */\r
86 void (*frame) (struct sprinter *);\r
87 \r
88 The printer can (and should) use internal state to insert delimiters and\r
89 syntax at the correct places.\r
90 \r
91 Example:\r
92 \r
93 format->begin_map(format);\r
94 format->map_key(format, "foo");\r
95 format->begin_list(format);\r
96 format->integer(format, 1);\r
97 format->integer(format, 2);\r
98 format->integer(format, 3);\r
99 format->end(format);\r
100 format->map_key(format, "bar");\r
101 format->begin_map(format);\r
102 format->map_key(format, "baaz");\r
103 format->string(format, "hello world");\r
104 format->end(format);\r
105 format->end(format);\r
106 \r
107 would output JSON as follows:\r
108 \r
109 {"foo": [1, 2, 3], "bar": { "baaz": "hello world"}}\r
110 ---\r
111  sprinter.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++\r
112  1 file changed, 49 insertions(+)\r
113  create mode 100644 sprinter.h\r
114 \r
115 diff --git a/sprinter.h b/sprinter.h\r
116 new file mode 100644\r
117 index 0000000..1dad9a0\r
118 --- /dev/null\r
119 +++ b/sprinter.h\r
120 @@ -0,0 +1,49 @@\r
121 +#ifndef NOTMUCH_SPRINTER_H\r
122 +#define NOTMUCH_SPRINTER_H\r
123 +\r
124 +/* for notmuch_bool_t */\r
125 +#include "notmuch-client.h"\r
126 +\r
127 +/* Structure printer interface */\r
128 +typedef struct sprinter\r
129 +{\r
130 +    /* start a new map/dictionary structure.\r
131 +     */\r
132 +    void (*begin_map) (struct sprinter *);\r
133 +\r
134 +    /* start a new list/array structure\r
135 +     */\r
136 +    void (*begin_list) (struct sprinter *);\r
137 +\r
138 +    /* end the last opened list or map structure\r
139 +     */\r
140 +    void (*end) (struct sprinter *);\r
141 +\r
142 +    /* print one string/integer/boolean/null element (possibly inside a\r
143 +     * list or map\r
144 +     */\r
145 +    void (*string) (struct sprinter *, const char *);\r
146 +    void (*integer) (struct sprinter *, int);\r
147 +    void (*boolean) (struct sprinter *, notmuch_bool_t);\r
148 +    void (*null) (struct sprinter *);\r
149 +\r
150 +    /* print the key of a map's key/value pair.\r
151 +     */\r
152 +    void (*map_key) (struct sprinter *, const char *);\r
153 +\r
154 +    /* print a frame delimiter (such as a newline or extra whitespace)\r
155 +     */\r
156 +    void (*frame) (struct sprinter *);\r
157 +} sprinter_t;\r
158 +\r
159 +/* Create a new structure printer that emits JSON */\r
160 +struct sprinter *\r
161 +sprinter_json_new(const void *ctx, FILE *stream);\r
162 +\r
163 +/* A dummy structure printer that signifies that standard text output is\r
164 + * to be used instead of any structured format.\r
165 + */\r
166 +struct sprinter *\r
167 +sprinter_text;\r
168 +\r
169 +#endif // NOTMUCH_SPRINTER_H\r
170 -- \r
171 1.7.11.1\r
172 \r