[PATCH 2/2] WIP: treat notmuch tag without operations as query
[notmuch-archives.git] / 67 / cca3d738f86215a33de8e961cad48937dc84df
1 Return-Path: <pieter@praet.org>\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 4738042119F\r
6         for <notmuch@notmuchmail.org>; Sun, 22 Jan 2012 20:24:54 -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 056yZO3t+0XH for <notmuch@notmuchmail.org>;\r
16         Sun, 22 Jan 2012 20:24:53 -0800 (PST)\r
17 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
18  [74.125.82.45])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
19  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
20  8C9D242119C    for <notmuch@notmuchmail.org>; Sun, 22 Jan 2012 20:24:53 -0800\r
21  (PST)\r
22 Received: by mail-ww0-f45.google.com with SMTP id dt12so2215149wgb.2\r
23         for <notmuch@notmuchmail.org>; Sun, 22 Jan 2012 20:24:53 -0800 (PST)\r
24 MIME-Version: 1.0\r
25 Received: by 10.180.94.97 with SMTP id db1mr10668097wib.16.1327292693232;\r
26         Sun, 22 Jan 2012 20:24:53 -0800 (PST)\r
27 Received: from localhost ([109.131.95.182])\r
28         by mx.google.com with ESMTPS id t6sm10821091wid.1.2012.01.22.20.24.52\r
29         (version=TLSv1/SSLv3 cipher=OTHER);\r
30         Sun, 22 Jan 2012 20:24:52 -0800 (PST)\r
31 From: Pieter Praet <pieter@praet.org>\r
32 To: Austin Clements <amdragon@mit.edu>\r
33 Subject: [PATCH v2 4/6] setup: move tag printing and parsing into separate\r
34         functions\r
35 Date: Mon, 23 Jan 2012 05:22:35 +0100\r
36 Message-Id: <1327292557-7701-4-git-send-email-pieter@praet.org>\r
37 X-Mailer: git-send-email 1.7.8.1\r
38 In-Reply-To: <87obtvaw8h.fsf@praet.org>\r
39 References: <87obtvaw8h.fsf@praet.org>\r
40 X-Gm-Message-State:\r
41  ALoCoQmWtSK7smf0hfR/BJXgezHOQnpEgrVUCbWDqiAlDymzQBSzcp+J81rTNyo3c4mZl8s3j1On\r
42 Cc: Notmuch Mail <notmuch@notmuchmail.org>\r
43 X-BeenThere: notmuch@notmuchmail.org\r
44 X-Mailman-Version: 2.1.13\r
45 Precedence: list\r
46 List-Id: "Use and development of the notmuch mail system."\r
47         <notmuch.notmuchmail.org>\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
51 List-Post: <mailto:notmuch@notmuchmail.org>\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
55 X-List-Received-Date: Mon, 23 Jan 2012 04:24:54 -0000\r
56 \r
57 From: Austin Clements <amdragon@MIT.EDU>\r
58 \r
59 * notmuch-setup.c (notmuch_setup_command):\r
60   Break tag printing and response parsing out into separate functions\r
61   called `print_tag_list' respectively `parse_tag_list', for reuse\r
62   with the 'search.exclude_tags' option.\r
63 \r
64 ---\r
65  notmuch-setup.c |   55 ++++++++++++++++++++++++++++++++++---------------------\r
66  1 files changed, 34 insertions(+), 21 deletions(-)\r
67 \r
68 diff --git a/notmuch-setup.c b/notmuch-setup.c\r
69 index c3ea937..dcfa607 100644\r
70 --- a/notmuch-setup.c\r
71 +++ b/notmuch-setup.c\r
72 @@ -87,6 +87,38 @@ welcome_message_post_setup (void)\r
73  "have sufficient storage space available now.\n\n");\r
74  }\r
75  \r
76 +static void\r
77 +print_tag_list (const char **tags, size_t tags_len)\r
78 +{\r
79 +    unsigned int i;\r
80 +    for (i = 0; i < tags_len; i++) {\r
81 +       if (i != 0)\r
82 +           printf (" ");\r
83 +       printf ("%s", tags[i]);\r
84 +    }\r
85 +}\r
86 +\r
87 +static GPtrArray *\r
88 +parse_tag_list (void *ctx, char *response)\r
89 +{\r
90 +    GPtrArray *tags = g_ptr_array_new ();\r
91 +    char *tag = response;\r
92 +    char *space;\r
93 +\r
94 +    while (tag && *tag) {\r
95 +       space = strchr (tag, ' ');\r
96 +       if (space)\r
97 +           g_ptr_array_add (tags, talloc_strndup (ctx, tag, space - tag));\r
98 +       else\r
99 +           g_ptr_array_add (tags, talloc_strdup (ctx, tag));\r
100 +       tag = space;\r
101 +       while (tag && *tag == ' ')\r
102 +           tag++;\r
103 +    }\r
104 +\r
105 +    return tags;\r
106 +}\r
107 +\r
108  int\r
109  notmuch_setup_command (unused (void *ctx),\r
110                        unused (int argc), unused (char *argv[]))\r
111 @@ -164,30 +196,11 @@ notmuch_setup_command (unused (void *ctx),\r
112      new_tags = notmuch_config_get_new_tags (config, &new_tags_len);\r
113  \r
114      printf ("Tags to apply to all new messages (separated by spaces) [");\r
115 -\r
116 -    for (i = 0; i < new_tags_len; i++) {\r
117 -       if (i != 0)\r
118 -           printf (" ");\r
119 -       printf ("%s", new_tags[i]);\r
120 -    }\r
121 -\r
122 +    print_tag_list(new_tags, new_tags_len);\r
123      prompt ("]: ");\r
124  \r
125      if (strlen (response)) {\r
126 -       GPtrArray *tags = g_ptr_array_new ();\r
127 -       char *tag = response;\r
128 -       char *space;\r
129 -\r
130 -       while (tag && *tag) {\r
131 -           space = strchr (tag, ' ');\r
132 -           if (space)\r
133 -               g_ptr_array_add (tags, talloc_strndup (ctx, tag, space - tag));\r
134 -           else\r
135 -               g_ptr_array_add (tags, talloc_strdup (ctx, tag));\r
136 -           tag = space;\r
137 -           while (tag && *tag == ' ')\r
138 -               tag++;\r
139 -       }\r
140 +       GPtrArray *tags = parse_tag_list (ctx, response);\r
141  \r
142         notmuch_config_set_new_tags (config, (const char **) tags->pdata,\r
143                                      tags->len);\r
144 -- \r
145 1.7.8.1\r
146 \r