Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 22 / 0fe3bb6b0557b31c133d82a2999eb3849ca9ce
1 Return-Path: <tomi.ollila@iki.fi>\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 95822431FDD\r
6         for <notmuch@notmuchmail.org>; Sun, 18 Aug 2013 11:09:25 -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\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 A8itxHlr638i for <notmuch@notmuchmail.org>;\r
16         Sun, 18 Aug 2013 11:09:21 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id D198A431FDB\r
19         for <notmuch@notmuchmail.org>; Sun, 18 Aug 2013 11:09:20 -0700 (PDT)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 07228100086;\r
22         Sun, 18 Aug 2013 21:09:16 +0300 (EEST)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH 2/2] cli: define config getters and setters using a macro\r
26 In-Reply-To: <1376839205-5115-2-git-send-email-jani@nikula.org>\r
27 References: <1376839205-5115-1-git-send-email-jani@nikula.org>\r
28         <1376839205-5115-2-git-send-email-jani@nikula.org>\r
29 User-Agent: Notmuch/0.16+3~g340c058 (http://notmuchmail.org) Emacs/24.3.1\r
30         (x86_64-unknown-linux-gnu)\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
32         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
33         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
34 Date: Sun, 18 Aug 2013 21:09:15 +0300\r
35 Message-ID: <m2zjse7tx0.fsf@guru.guru-group.fi>\r
36 MIME-Version: 1.0\r
37 Content-Type: text/plain\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Sun, 18 Aug 2013 18:09:25 -0000\r
51 \r
52 On Sun, Aug 18 2013, Jani Nikula <jani@nikula.org> wrote:\r
53 \r
54 > There's plenty of duplicated code in defining the functions for config\r
55 > get/set. Add macros to define the functions.\r
56 >\r
57 > ---\r
58 >\r
59 > This might be a bit too tricky for some people's tastes... let's see!\r
60 > ;)\r
61 \r
62 Yes, a bit tricky. Nevertheless I like these...\r
63 \r
64 Additionally id:1376839205-5115-1-git-send-email-jani@nikula.org LGTM.\r
65 \r
66 Tomi\r
67 \r
68 \r
69 > ---\r
70 >  notmuch-config.c |  141 ++++++++++++++----------------------------------------\r
71 >  1 file changed, 37 insertions(+), 104 deletions(-)\r
72 >\r
73 > diff --git a/notmuch-config.c b/notmuch-config.c\r
74 > index 305d213..fcee0fc 100644\r
75 > --- a/notmuch-config.c\r
76 > +++ b/notmuch-config.c\r
77 > @@ -520,6 +520,18 @@ _config_set (notmuch_config_t *config, char **field,\r
78 >      *field = NULL;\r
79 >  }\r
80 >  \r
81 > +#define DEFINE_CONFIG_GET(group, key) \\r
82 > +    const char *                                                     \\r
83 > +    notmuch_config_get_ ## group ## _ ## key (notmuch_config_t *config) { \\r
84 > +     return _config_get (config, &config->group ## _ ## key, #group, #key); \\r
85 > +    }\r
86 > +\r
87 > +#define DEFINE_CONFIG_SET(group, key)                                \\r
88 > +    void                                                             \\r
89 > +    notmuch_config_set_ ## group ## _ ## key (notmuch_config_t *config, const char *value) { \\r
90 > +     _config_set (config, &config->group ## _ ## key, #group, #key, value); \\r
91 > +    }\r
92 > +\r
93 >  static const char **\r
94 >  _config_get_list (notmuch_config_t *config,\r
95 >                 const char *section, const char *key,\r
96 > @@ -562,112 +574,33 @@ _config_set_list (notmuch_config_t *config,\r
97 >      *config_var = NULL;\r
98 >  }\r
99 >  \r
100 > -const char *\r
101 > -notmuch_config_get_database_path (notmuch_config_t *config)\r
102 > -{\r
103 > -    return _config_get (config, &config->database_path, "database", "path");\r
104 > -}\r
105 > -\r
106 > -void\r
107 > -notmuch_config_set_database_path (notmuch_config_t *config,\r
108 > -                               const char *database_path)\r
109 > -{\r
110 > -    _config_set (config, &config->database_path, "database", "path", database_path);\r
111 > -}\r
112 > -\r
113 > -const char *\r
114 > -notmuch_config_get_user_name (notmuch_config_t *config)\r
115 > -{\r
116 > -    return _config_get (config, &config->user_name, "user", "name");\r
117 > -}\r
118 > -\r
119 > -void\r
120 > -notmuch_config_set_user_name (notmuch_config_t *config,\r
121 > -                           const char *user_name)\r
122 > -{\r
123 > -    _config_set (config, &config->user_name, "user", "name", user_name);\r
124 > -}\r
125 > -\r
126 > -const char *\r
127 > -notmuch_config_get_user_primary_email (notmuch_config_t *config)\r
128 > -{\r
129 > -    return _config_get (config, &config->user_primary_email, "user", "primary_email");\r
130 > -}\r
131 > -\r
132 > -void\r
133 > -notmuch_config_set_user_primary_email (notmuch_config_t *config,\r
134 > -                                    const char *primary_email)\r
135 > -{\r
136 > -    _config_set (config, &config->user_primary_email, "user", "primary_email", primary_email);\r
137 > -}\r
138 > -\r
139 > -const char **\r
140 > -notmuch_config_get_user_other_email (notmuch_config_t *config,   size_t *length)\r
141 > -{\r
142 > -    return _config_get_list (config, "user", "other_email",\r
143 > -                          &(config->user_other_email),\r
144 > -                          &(config->user_other_email_length), length);\r
145 > -}\r
146 > -\r
147 > -const char **\r
148 > -notmuch_config_get_new_tags (notmuch_config_t *config,   size_t *length)\r
149 > -{\r
150 > -    return _config_get_list (config, "new", "tags",\r
151 > -                          &(config->new_tags),\r
152 > -                          &(config->new_tags_length), length);\r
153 > -}\r
154 > -\r
155 > -const char **\r
156 > -notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)\r
157 > -{\r
158 > -    return _config_get_list (config, "new", "ignore",\r
159 > -                          &(config->new_ignore),\r
160 > -                          &(config->new_ignore_length), length);\r
161 > -}\r
162 > -\r
163 > -void\r
164 > -notmuch_config_set_user_other_email (notmuch_config_t *config,\r
165 > -                                  const char *list[],\r
166 > -                                  size_t length)\r
167 > -{\r
168 > -    _config_set_list (config, "user", "other_email", list, length,\r
169 > -                  &(config->user_other_email));\r
170 > -}\r
171 > -\r
172 > -void\r
173 > -notmuch_config_set_new_tags (notmuch_config_t *config,\r
174 > -                                  const char *list[],\r
175 > -                                  size_t length)\r
176 > -{\r
177 > -    _config_set_list (config, "new", "tags", list, length,\r
178 > -                  &(config->new_tags));\r
179 > -}\r
180 > -\r
181 > -void\r
182 > -notmuch_config_set_new_ignore (notmuch_config_t *config,\r
183 > -                            const char *list[],\r
184 > -                            size_t length)\r
185 > -{\r
186 > -    _config_set_list (config, "new", "ignore", list, length,\r
187 > -                  &(config->new_ignore));\r
188 > -}\r
189 > +#define DEFINE_CONFIG_GET_LIST(group, key)                           \\r
190 > +    const char **                                                    \\r
191 > +    notmuch_config_get_ ## group ## _ ## key (notmuch_config_t *config, size_t *length) { \\r
192 > +     return _config_get_list (config, #group, #key, &config->group ## _ ## key, &config->group ## _ ## key ## _ ## length, length); \\r
193 > +    }\r
194 >  \r
195 > -const char **\r
196 > -notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length)\r
197 > -{\r
198 > -    return _config_get_list (config, "search", "exclude_tags",\r
199 > -                          &(config->search_exclude_tags),\r
200 > -                          &(config->search_exclude_tags_length), length);\r
201 > -}\r
202 > +#define DEFINE_CONFIG_SET_LIST(group, key)                           \\r
203 > +    void                                                             \\r
204 > +    notmuch_config_set_ ## group ## _ ## key (notmuch_config_t *config, const char *list[], size_t length) { \\r
205 > +     _config_set_list (config, #group, #key, list, length, &config->group ## _ ## key); \\r
206 > +    }\r
207 >  \r
208 > -void\r
209 > -notmuch_config_set_search_exclude_tags (notmuch_config_t *config,\r
210 > -                                   const char *list[],\r
211 > -                                   size_t length)\r
212 > -{\r
213 > -    _config_set_list (config, "search", "exclude_tags", list, length,\r
214 > -                   &(config->search_exclude_tags));\r
215 > -}\r
216 > +DEFINE_CONFIG_GET(database, path);\r
217 > +DEFINE_CONFIG_SET(database, path);\r
218 > +DEFINE_CONFIG_GET(user, name);\r
219 > +DEFINE_CONFIG_SET(user, name);\r
220 > +DEFINE_CONFIG_GET(user, primary_email);\r
221 > +DEFINE_CONFIG_SET(user, primary_email);\r
222 > +\r
223 > +DEFINE_CONFIG_GET_LIST(user, other_email);\r
224 > +DEFINE_CONFIG_SET_LIST(user, other_email);\r
225 > +DEFINE_CONFIG_GET_LIST(new, tags);\r
226 > +DEFINE_CONFIG_SET_LIST(new, tags);\r
227 > +DEFINE_CONFIG_GET_LIST(new, ignore);\r
228 > +DEFINE_CONFIG_SET_LIST(new, ignore);\r
229 > +DEFINE_CONFIG_GET_LIST(search, exclude_tags);\r
230 > +DEFINE_CONFIG_SET_LIST(search, exclude_tags);\r
231 >  \r
232 >  /* Given a configuration item of the form <group>.<key> return the\r
233 >   * component group and key. If any error occurs, print a message on\r
234 > -- \r
235 > 1.7.10.4\r
236 >\r
237 > _______________________________________________\r
238 > notmuch mailing list\r
239 > notmuch@notmuchmail.org\r
240 > http://notmuchmail.org/mailman/listinfo/notmuch\r