Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 1a / a3c6c8c5717fa15df0f2a7079ce48ce71979c4
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 626BB429E54\r
6         for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:16:08 -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 dgoCRNQkK+vK for <notmuch@notmuchmail.org>;\r
16         Mon, 23 Jan 2012 15:16:07 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU\r
18         [18.7.68.36])\r
19         by olra.theworths.org (Postfix) with ESMTP id 6A1B7429E21\r
20         for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:16:07 -0800 (PST)\r
21 X-AuditID: 12074424-b7fae6d000000906-91-4f1dea36b6df\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 1F.DA.02310.63AED1F4; Mon, 23 Jan 2012 18:16:06 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q0NNG68M018680; \r
27         Mon, 23 Jan 2012 18:16:06 -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 q0NNG5ox021965\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Mon, 23 Jan 2012 18:16:05 -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 1RpT6t-0004CR-93; Mon, 23 Jan 2012 18:15:35 -0500\r
37 Date: Mon, 23 Jan 2012 18:15:35 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
40 Subject: Re: [PATCH v2 1/3] mime node: Record depth-first part numbers\r
41 Message-ID: <20120123231535.GV16740@mit.edu>\r
42 References: <1326918507-28033-1-git-send-email-amdragon@mit.edu>\r
43         <1327285873-4713-1-git-send-email-amdragon@mit.edu>\r
44         <1327285873-4713-2-git-send-email-amdragon@mit.edu>\r
45         <8762g2njto.fsf@gmail.com>\r
46 MIME-Version: 1.0\r
47 Content-Type: text/plain; charset=us-ascii\r
48 Content-Disposition: inline\r
49 In-Reply-To: <8762g2njto.fsf@gmail.com>\r
50 User-Agent: Mutt/1.5.21 (2010-09-15)\r
51 X-Brightmail-Tracker:\r
52  H4sIAAAAAAAAA+NgFprIKsWRmVeSWpSXmKPExsUixCmqrGv2StbfYNs2M4urW/vZLa7fnMns\r
53         wOSxc9Zddo9nq24xBzBFcdmkpOZklqUW6dslcGVcXnSAveCyccWcjUvZGxjPqHUxcnJICJhI\r
54         zD5+mxHCFpO4cG89WxcjF4eQwD5GiROn1rJAOBsYJWbs+swE4Zxkkth3eypU2RJGiS2PZ4D1\r
55         swioSpxa3McCYrMJaEhs278cLC4iYChx6+IrZhCbWUBa4tvvZiYQW1jATWLfkQlgNq+AjkTn\r
56         /P8wGxgl5i59zAyREJQ4OfMJC0SzlsSNfy+BijjABi3/xwES5hRQlzjbdhOsRFRARWLKyW1s\r
57         ExiFZiHpnoWkexZC9wJG5lWMsim5Vbq5iZk5xanJusXJiXl5qUW65nq5mSV6qSmlmxhBoc3u\r
58         orKDsfmQ0iFGAQ5GJR7eA9Nk/YVYE8uKK3MPMUpyMCmJ8s5/CRTiS8pPqcxILM6ILyrNSS0+\r
59         xCjBwawkwqt2DijHm5JYWZValA+TkuZgURLn1dB65yckkJ5YkpqdmlqQWgSTleHgUJLgXQcy\r
60         VLAoNT21Ii0zpwQhzcTBCTKcB2j4CpAa3uKCxNzizHSI/ClGXY7ZnV3nGYVY8vLzUqXEeZeA\r
61         FAmAFGWU5sHNgaWkV4ziQG8J824GqeIBpjO4Sa+AljABLeHIkwJZUpKIkJJqYMx0eLT/6pU3\r
62         F16yFjEWFrAuqLiVMoGZt/JPeqBu8f2Z0dlXpr25wBv04uYPzudFrsv/5ap9K5Blvbtvi+Kk\r
63         1zEzLaqknI9bbXia8NHitvXuhcL/I+pTxE9elvok+uxsxsd5RlUmccm7Gaxt2QQ4jxxU2s77\r
64         yJHV7Rrn1MVTDnkKS2856TX73RclluKMREMt5qLiRABLpIjOJAMAAA==\r
65 Cc: notmuch@notmuchmail.org\r
66 X-BeenThere: notmuch@notmuchmail.org\r
67 X-Mailman-Version: 2.1.13\r
68 Precedence: list\r
69 List-Id: "Use and development of the notmuch mail system."\r
70         <notmuch.notmuchmail.org>\r
71 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
73 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
74 List-Post: <mailto:notmuch@notmuchmail.org>\r
75 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
76 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
77         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
78 X-List-Received-Date: Mon, 23 Jan 2012 23:16:08 -0000\r
79 \r
80 Quoth Dmitry Kurochkin on Jan 24 at  2:19 am:\r
81 > On Sun, 22 Jan 2012 21:31:11 -0500, Austin Clements <amdragon@MIT.EDU> wrote:\r
82 > > This makes the part numbers readily accessible to formatters.\r
83 > > Hierarchical part numbering would be a more natural and efficient fit\r
84 > > for MIME and may be the way to go in the future, but depth-first\r
85 > > numbering maintains compatibility with what we currently do.\r
86\r
87 > The patch looks good except for few minor comments below.  I do not\r
88 > think that we need another review for the next patch version.\r
89\r
90 > > ---\r
91 > >  mime-node.c      |   37 ++++++++++++++++++++++++++++++++++---\r
92 > >  notmuch-client.h |   14 +++++++++++++-\r
93 > >  2 files changed, 47 insertions(+), 4 deletions(-)\r
94 > > \r
95 > > diff --git a/mime-node.c b/mime-node.c\r
96 > > index 27077f7..025c537 100644\r
97 > > --- a/mime-node.c\r
98 > > +++ b/mime-node.c\r
99 > > @@ -112,6 +112,10 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
100 > >      root->nchildren = 1;\r
101 > >      root->ctx = mctx;\r
102 > >  \r
103 > > +    root->part_num = 0;\r
104 > > +    root->next_child = 0;\r
105 > > +    root->next_part_num = 1;\r
106 > > +\r
107\r
108 > For consistency, we should either initialize root->parent to NULL\r
109 > explicitly or remove part_num and next_child initialization.\r
110\r
111 > >      *root_out = root;\r
112 > >      return NOTMUCH_STATUS_SUCCESS;\r
113 > >  \r
114 > > @@ -137,7 +141,7 @@ _signature_validity_free (GMimeSignatureValidity **proxy)\r
115 > >  #endif\r
116 > >  \r
117 > >  static mime_node_t *\r
118 > > -_mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
119 > > +_mime_node_create (mime_node_t *parent, GMimeObject *part)\r
120 > >  {\r
121 > >      mime_node_t *node = talloc_zero (parent, mime_node_t);\r
122 > >      GError *err = NULL;\r
123 > > @@ -150,6 +154,8 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
124 > >     talloc_free (node);\r
125 > >     return NULL;\r
126 > >      }\r
127 > > +    node->parent = parent;\r
128 > > +    node->part_num = node->next_part_num = -1;\r
129\r
130 > Same here: if we initialize next_child to zero explicitly in\r
131 > mime_node_open(), we should do it here as well.\r
132 \r
133 Both done.\r
134 \r
135 > >  \r
136 > >      /* Deal with the different types of parts */\r
137 > >      if (GMIME_IS_PART (part)) {\r
138 > > @@ -267,9 +273,10 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
139 > >  }\r
140 > >  \r
141 > >  mime_node_t *\r
142 > > -mime_node_child (const mime_node_t *parent, int child)\r
143 > > +mime_node_child (mime_node_t *parent, int child)\r
144 > >  {\r
145 > >      GMimeObject *sub;\r
146 > > +    mime_node_t *node;\r
147 > >  \r
148 > >      if (!parent || child < 0 || child >= parent->nchildren)\r
149 > >     return NULL;\r
150 > > @@ -287,7 +294,31 @@ mime_node_child (const mime_node_t *parent, int child)\r
151 > >     INTERNAL_ERROR ("Unexpected GMimeObject type: %s",\r
152 > >                     g_type_name (G_OBJECT_TYPE (parent->part)));\r
153 > >      }\r
154 > > -    return _mime_node_create (parent, sub);\r
155 > > +    node = _mime_node_create (parent, sub);\r
156 > > +\r
157 > > +    if (child == parent->next_child && parent->next_part_num != -1) {\r
158 > > +   /* We're traversing in depth-first order.  Record the child's\r
159 > > +    * depth-first numbering. */\r
160 > > +   node->part_num = parent->next_part_num;\r
161 > > +   node->next_part_num = node->part_num + 1;\r
162 > > +\r
163 > > +   /* Drop the const qualifier because these are internal fields\r
164 > > +    * whose mutability doesn't affect the interface. */\r
165\r
166 > The comment is no longer relevant, please remove.\r
167\r
168 > > +   parent->next_child++;\r
169 > > +   parent->next_part_num = -1;\r
170 > > +\r
171 > > +   if (node->nchildren == 0) {\r
172 > > +       /* We've reached a leaf, so find the parent that has more\r
173 > > +        * children and set it up to number its next child. */\r
174 > > +       mime_node_t *it = node;\r
175 > > +       while (it && it->next_child == it->nchildren)\r
176\r
177 > It seems that it should be initialized to node->parent, because\r
178 > node->next_child is always 0.\r
179 \r
180 Either works.  I started at node because it seemed like a more\r
181 fundamental base case, but perhaps that just makes this code even more\r
182 obtuse.\r
183 \r
184 > Just curious, does "it" stands for "iterator"?  I would prefer just "i"\r
185 > or "iter" :)\r
186 \r
187 "it" is a C++ habit.  I changed it to "iter".\r
188 \r
189 > > +           it = it->parent;\r
190 > > +       if (it)\r
191 > > +           it->next_part_num = node->part_num + 1;\r
192 > > +   }\r
193 > > +    }\r
194\r
195 > Austin, I trust you that this code works :)  Though I hope we will get\r
196 > to hierarchical part numbering one day and it would simplify this code.\r
197 \r
198 It would simplify it down to one line, in fact.  Code simplification\r
199 aside, I think hierarchical numbering is the right thing to do.  But\r
200 that's for another day.\r
201 \r
202 > Regards,\r
203 >   Dmitry\r
204\r
205 > > +\r
206 > > +    return node;\r
207 > >  }\r
208 > >  \r
209 > >  static mime_node_t *\r
210 > > diff --git a/notmuch-client.h b/notmuch-client.h\r
211 > > index 9c1d383..abfe5d3 100644\r
212 > > --- a/notmuch-client.h\r
213 > > +++ b/notmuch-client.h\r
214 > > @@ -297,6 +297,13 @@ typedef struct mime_node {\r
215 > >      /* The number of children of this part. */\r
216 > >      int nchildren;\r
217 > >  \r
218 > > +    /* The parent of this node or NULL if this is the root node. */\r
219 > > +    struct mime_node *parent;\r
220 > > +\r
221 > > +    /* The depth-first part number of this child if the MIME tree is\r
222 > > +     * being traversed in depth-first order, or -1 otherwise. */\r
223 > > +    int part_num;\r
224 > > +\r
225 > >      /* True if decryption of this part was attempted. */\r
226 > >      notmuch_bool_t decrypt_attempted;\r
227 > >      /* True if decryption of this part's child succeeded.  In this\r
228 > > @@ -324,6 +331,11 @@ typedef struct mime_node {\r
229 > >      /* Internal: For successfully decrypted multipart parts, the\r
230 > >       * decrypted part to substitute for the second child. */\r
231 > >      GMimeObject *decrypted_child;\r
232 > > +\r
233 > > +    /* Internal: The next child for depth-first traversal and the part\r
234 > > +     * number to assign it (or -1 if unknown). */\r
235 > > +    int next_child;\r
236 > > +    int next_part_num;\r
237 > >  } mime_node_t;\r
238 > >  \r
239 > >  /* Construct a new MIME node pointing to the root message part of\r
240 > > @@ -356,7 +368,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
241 > >   * an error message on stderr).\r
242 > >   */\r
243 > >  mime_node_t *\r
244 > > -mime_node_child (const mime_node_t *parent, int child);\r
245 > > +mime_node_child (mime_node_t *parent, int child);\r
246 > >  \r
247 > >  /* Return the nth child of node in a depth-first traversal.  If n is\r
248 > >   * 0, returns node itself.  Returns NULL if there is no such part. */\r
249\r
250 \r
251 -- \r
252 Austin Clements                                      MIT/'06/PhD/CSAIL\r
253 amdragon@mit.edu                           http://web.mit.edu/amdragon\r
254        Somewhere in the dream we call reality you will find me,\r
255               searching for the reality we call dreams.\r