notmuch-search-toggle-order and notmuch-tree
[notmuch-archives.git] / 3e / 41c5b504fcf0f3322f26e67ecea0837838987f
1 Return-Path: <jan@ryngle.com>\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 97134431FAE\r
6         for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 16:11:23 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id HKOQsob7QVtx for <notmuch@notmuchmail.org>;\r
11         Sun, 22 Nov 2009 16:11:23 -0800 (PST)\r
12 Received: from mail-fx0-f214.google.com (mail-fx0-f214.google.com\r
13         [209.85.220.214])\r
14         by olra.theworths.org (Postfix) with ESMTP id C5ED7431FC0\r
15         for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 16:11:22 -0800 (PST)\r
16 Received: by fxm6 with SMTP id 6so5354636fxm.0\r
17         for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 16:11:21 -0800 (PST)\r
18 Received: by 10.103.84.30 with SMTP id m30mr1873923mul.23.1258935081351;\r
19         Sun, 22 Nov 2009 16:11:21 -0800 (PST)\r
20 Received: from x61s.janakj (r2c34.net.upc.cz [62.245.66.34])\r
21         by mx.google.com with ESMTPS id 14sm14332748muo.34.2009.11.22.16.11.20\r
22         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
23         Sun, 22 Nov 2009 16:11:20 -0800 (PST)\r
24 Received: by x61s.janakj (Postfix, from userid 1000)\r
25         id 0EFC4440656; Mon, 23 Nov 2009 01:10:57 +0100 (CET)\r
26 From: Jan Janak <jan@ryngle.com>\r
27 To: notmuch@notmuchmail.org\r
28 Date: Mon, 23 Nov 2009 01:10:55 +0100\r
29 Message-Id: <1258935056-9746-2-git-send-email-jan@ryngle.com>\r
30 X-Mailer: git-send-email 1.6.3.3\r
31 In-Reply-To: <1258935056-9746-1-git-send-email-jan@ryngle.com>\r
32 References: <1258935056-9746-1-git-send-email-jan@ryngle.com>\r
33 Subject: [notmuch] [PATCH 2/3] notmuch: New command 'search-tags'.\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.12\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38         <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
40         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Mon, 23 Nov 2009 00:11:23 -0000\r
47 \r
48 This is a new notmuch command that can be used to search for all tags\r
49 found in the database. The resulting list is alphabetically sorted.\r
50 \r
51 The primary use-case for this new command is to provide the tag\r
52 completion feature in Emacs (and other interfaces).\r
53 \r
54 Signed-off-by: Jan Janak <jan@ryngle.com>\r
55 ---\r
56  Makefile.local        |    1 +\r
57  notmuch-client.h      |    3 ++\r
58  notmuch-search-tags.c |   71 +++++++++++++++++++++++++++++++++++++++++++++++++\r
59  notmuch.c             |    6 ++++\r
60  4 files changed, 81 insertions(+), 0 deletions(-)\r
61  create mode 100644 notmuch-search-tags.c\r
62 \r
63 diff --git a/Makefile.local b/Makefile.local\r
64 index 2828659..d8f7906 100644\r
65 --- a/Makefile.local\r
66 +++ b/Makefile.local\r
67 @@ -12,6 +12,7 @@ notmuch_client_srcs =         \\r
68         notmuch-reply.c         \\r
69         notmuch-restore.c       \\r
70         notmuch-search.c        \\r
71 +       notmuch-search-tags.c   \\r
72         notmuch-setup.c         \\r
73         notmuch-show.c          \\r
74         notmuch-tag.c           \\r
75 diff --git a/notmuch-client.h b/notmuch-client.h\r
76 index ea77686..c6142b5 100644\r
77 --- a/notmuch-client.h\r
78 +++ b/notmuch-client.h\r
79 @@ -114,6 +114,9 @@ notmuch_show_command (void *ctx, int argc, char *argv[]);\r
80  int\r
81  notmuch_tag_command (void *ctx, int argc, char *argv[]);\r
82  \r
83 +int\r
84 +notmuch_search_tags_command (void *ctx, int argc, char *argv[]);\r
85 +\r
86  const char *\r
87  notmuch_time_relative_date (const void *ctx, time_t then);\r
88  \r
89 diff --git a/notmuch-search-tags.c b/notmuch-search-tags.c\r
90 new file mode 100644\r
91 index 0000000..1201165\r
92 --- /dev/null\r
93 +++ b/notmuch-search-tags.c\r
94 @@ -0,0 +1,71 @@\r
95 +/* notmuch - Not much of an email program, (just index and search)\r
96 + *\r
97 + * Copyright © 2009 Carl Worth\r
98 + * Copyright © 2009 Jan Janak\r
99 + *\r
100 + * This program is free software: you can redistribute it and/or modify\r
101 + * it under the terms of the GNU General Public License as published by\r
102 + * the Free Software Foundation, either version 3 of the License, or\r
103 + * (at your option) any later version.\r
104 + *\r
105 + * This program is distributed in the hope that it will be useful,\r
106 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
107 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
108 + * GNU General Public License for more details.\r
109 + *\r
110 + * You should have received a copy of the GNU General Public License\r
111 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
112 + *\r
113 + * Author: Jan Janak <jan@ryngle.com>\r
114 + */\r
115 +\r
116 +#include "notmuch-client.h"\r
117 +\r
118 +static int\r
119 +list_all_tags (notmuch_database_t* db)\r
120 +{\r
121 +    notmuch_tags_t* tags;\r
122 +    const char* t;\r
123 +\r
124 +    if ((tags = notmuch_database_get_all_tags (db)) == NULL) {\r
125 +       fprintf (stderr, "Error while obtaining tags from the database.\n");\r
126 +       return 1;\r
127 +    }\r
128 +\r
129 +    while((t = notmuch_tags_get (tags))) {\r
130 +       printf ("%s\n", t);\r
131 +       notmuch_tags_advance (tags);\r
132 +    }\r
133 +\r
134 +    notmuch_tags_destroy (tags);\r
135 +    return 0;\r
136 +}\r
137 +\r
138 +int\r
139 +notmuch_search_tags_command (void *ctx, int argc, char *argv[])\r
140 +{\r
141 +    notmuch_config_t *config;\r
142 +    notmuch_database_t *db;\r
143 +\r
144 +    config = NULL;\r
145 +    db = NULL;\r
146 +\r
147 +    if ((config = notmuch_config_open (ctx, NULL, NULL)) == NULL) {\r
148 +       goto error;\r
149 +    }\r
150 +\r
151 +    db = notmuch_database_open (notmuch_config_get_database_path (config),\r
152 +                               NOTMUCH_DATABASE_MODE_READ_ONLY);\r
153 +    if (db == NULL) {\r
154 +       goto error;\r
155 +    }\r
156 +\r
157 +    if (list_all_tags (db) != 0) goto error;\r
158 +\r
159 +    notmuch_database_close (db);\r
160 +    return 0;\r
161 +\r
162 +error:\r
163 +    if (db) notmuch_database_close (db);\r
164 +    return 1;\r
165 +}\r
166 diff --git a/notmuch.c b/notmuch.c\r
167 index 5cc8e4c..b1d7cf9 100644\r
168 --- a/notmuch.c\r
169 +++ b/notmuch.c\r
170 @@ -230,6 +230,12 @@ command_t commands[] = {\r
171        "\t\tSo if you've previously been using sup for mail, then the\n"\r
172        "\t\t\"notmuch restore\" command provides you a way to import\n"\r
173        "\t\tall of your tags (or labels as sup calls them)." },\r
174 +    { "search-tags", notmuch_search_tags_command,\r
175 +      NULL,\r
176 +      "List all tags found in the database.",\r
177 +      "\t\tThis command returns an alphabetically sorted list of all tags\n"\r
178 +      "\t\tthat are present in the database. In other words, the resulting\n"\r
179 +      "\t\tlist is a collection of all tags from all messages." },\r
180      { "help", notmuch_help_command,\r
181        "[<command>]",\r
182        "\t\tThis message, or more detailed help for the named command.",\r
183 -- \r
184 1.6.3.3\r
185 \r