[PATCH 4/8] lib: extend private string map API with iterators
[notmuch-archives.git] / 36 / 6c6159ad7db68062f1586ade5cd56b7d7b4174
1 Return-Path: <keithp@keithp.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 7E447431FC0\r
6         for <notmuch@notmuchmail.org>; Sat, 26 Dec 2009 16:34:40 -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 3WLuDcsdpD5V for <notmuch@notmuchmail.org>;\r
11         Sat, 26 Dec 2009 16:34:39 -0800 (PST)\r
12 Received: from keithp.com (home.keithp.com [63.227.221.253])\r
13         by olra.theworths.org (Postfix) with ESMTP id 3584F431FC3\r
14         for <notmuch@notmuchmail.org>; Sat, 26 Dec 2009 16:34:37 -0800 (PST)\r
15 Received: from localhost (localhost [127.0.0.1])\r
16         by keithp.com (Postfix) with ESMTP id BE03E760142\r
17         for <notmuch@notmuchmail.org>; Sat, 26 Dec 2009 16:34:36 -0800 (PST)\r
18 X-Virus-Scanned: Debian amavisd-new at keithp.com\r
19 Received: from keithp.com ([127.0.0.1])\r
20         by localhost (keithp.com [127.0.0.1]) (amavisd-new, port 10024)\r
21         with LMTP id du1rtUreSsds; Sat, 26 Dec 2009 16:34:33 -0800 (PST)\r
22 Received: by keithp.com (Postfix, from userid 1033)\r
23         id A2192B7C03A; Sat, 26 Dec 2009 16:34:32 -0800 (PST)\r
24 Received: from koto.keithp.com (localhost [127.0.0.1])\r
25         by keithp.com (Postfix) with ESMTP id C8E58760142;\r
26         Sat, 26 Dec 2009 16:34:30 -0800 (PST)\r
27 Received: by koto.keithp.com (Postfix, from userid 1488)\r
28         id F0DCE1381DF; Sat, 26 Dec 2009 16:34:20 -0800 (PST)\r
29 From: Keith Packard <keithp@keithp.com>\r
30 To: notmuch@notmuchmail.org\r
31 Date: Sat, 26 Dec 2009 16:34:18 -0800\r
32 Message-Id: <1261874058-13820-3-git-send-email-keithp@keithp.com>\r
33 X-Mailer: git-send-email 1.6.5.4\r
34 In-Reply-To: <1261874058-13820-2-git-send-email-keithp@keithp.com>\r
35 References: <1261874058-13820-1-git-send-email-keithp@keithp.com>\r
36         <1261874058-13820-2-git-send-email-keithp@keithp.com>\r
37 Subject: [notmuch] [PATCH 3/3] Allow folders with no messages to be elided\r
38         from list.\r
39 X-BeenThere: notmuch@notmuchmail.org\r
40 X-Mailman-Version: 2.1.12\r
41 Precedence: list\r
42 List-Id: "Use and development of the notmuch mail system."\r
43         <notmuch.notmuchmail.org>\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
47 List-Post: <mailto:notmuch@notmuchmail.org>\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
51 X-List-Received-Date: Sun, 27 Dec 2009 00:34:40 -0000\r
52 \r
53 This makes it easier to see folders with messages.\r
54 Eliding empty folders is togged with the 'e' binding.\r
55 \r
56 Signed-off-by: Keith Packard <keithp@keithp.com>\r
57 ---\r
58  lib/Makefile.local |    1 +\r
59  lib/notmuch.h      |   11 +++++++++++\r
60  lib/query.cc       |   41 +++++++++++++++++++++++++++++++++++++++++\r
61  notmuch-new.c      |    1 +\r
62  notmuch.el         |   29 ++++++++++++++++++++++++-----\r
63  5 files changed, 78 insertions(+), 5 deletions(-)\r
64 \r
65 diff --git a/lib/Makefile.local b/lib/Makefile.local\r
66 index a7562c9..e42f533 100644\r
67 --- a/lib/Makefile.local\r
68 +++ b/lib/Makefile.local\r
69 @@ -2,6 +2,7 @@ dir=lib\r
70  extra_cflags += -I$(dir)\r
71  \r
72  libnotmuch_c_srcs =            \\r
73 +       $(dir)/date.c           \\r
74         $(dir)/libsha1.c        \\r
75         $(dir)/message-file.c   \\r
76         $(dir)/messages.c       \\r
77 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
78 index 60834fb..f24da18 100644\r
79 --- a/lib/notmuch.h\r
80 +++ b/lib/notmuch.h\r
81 @@ -94,6 +94,7 @@ typedef enum _notmuch_status {\r
82      NOTMUCH_STATUS_NULL_POINTER,\r
83      NOTMUCH_STATUS_TAG_TOO_LONG,\r
84      NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW,\r
85 +    NOTMUCH_STATUS_INVALID_DATE,\r
86  \r
87      NOTMUCH_STATUS_LAST_STATUS\r
88  } notmuch_status_t;\r
89 @@ -929,6 +930,16 @@ notmuch_tags_advance (notmuch_tags_t *tags);\r
90  void\r
91  notmuch_tags_destroy (notmuch_tags_t *tags);\r
92  \r
93 +/* Convert a string into a time range\r
94 + *\r
95 + * This parses the provided string, providing two time values\r
96 + * representing the begining and end of the period. It\r
97 + * returns NOTMUCH_STATUS_INVALID_DATE if the string could not be\r
98 + * parsed, otherwise it return NOTMUCH_STATUS_SUCCESS\r
99 + */\r
100 +notmuch_status_t\r
101 +notmuch_date(const char *text, time_t *first, time_t *last);\r
102 +\r
103  NOTMUCH_END_DECLS\r
104  \r
105  #endif\r
106 diff --git a/lib/query.cc b/lib/query.cc\r
107 index 9106b92..f511146 100644\r
108 --- a/lib/query.cc\r
109 +++ b/lib/query.cc\r
110 @@ -47,6 +47,47 @@ struct _notmuch_threads {\r
111      const char *thread_id;\r
112  };\r
113  \r
114 +static char *\r
115 +notmuch_query_extract_word(notmuch_query_t *query, char *leader)\r
116 +{\r
117 +       char    *token = strstr(query->query_string, leader);\r
118 +       int     len = strlen(leader);\r
119 +       char    *space;\r
120 +       char    *word;\r
121 +       char    *query_string;\r
122 +\r
123 +       if (!token)\r
124 +           return NULL;\r
125 +       space = strchr(token, ' ');\r
126 +       if (!space)\r
127 +           space = token + strlen(token);\r
128 +       word = talloc_strndup(query, token + len, space - token - len);\r
129 +       query_string = talloc(query, strlen(query->query_string) - (space - token));\r
130 +       strncpy(query_string, query->query_string, token - query->query_string);\r
131 +       strcat(query_string, space);\r
132 +       query->query_string = query_string;\r
133 +       return word;\r
134 +}\r
135 +\r
136 +static notmuch_status_t\r
137 +notmuch_query_edit(notmuch_query_t *query)\r
138 +{\r
139 +       char    *before, *after;\r
140 +       time_t  before_first, before_last, after_first, after_last;\r
141 +       \r
142 +       /* edit date range */\r
143 +       before = notmuch_query_extract_word(query, "before:");\r
144 +       if (notmuch_date(before, &before_first, &before_last) != NOTMUCH_STATUS_SUCCESS)\r
145 +           before = NULL;\r
146 +       after = notmuch_query_extract_word(query, "after:");\r
147 +       if (notmuch_date(after, &after_first, &after_last) != NOTMUCH_STATUS_SUCCESS)\r
148 +           after = NULL;\r
149 +\r
150 +       if (before && after) {\r
151 +           \r
152 +       }\r
153 +}\r
154 +\r
155  notmuch_query_t *\r
156  notmuch_query_create (notmuch_database_t *notmuch,\r
157                       const char *query_string)\r
158 diff --git a/notmuch-new.c b/notmuch-new.c\r
159 index 9d20616..3974b28 100644\r
160 --- a/notmuch-new.c\r
161 +++ b/notmuch-new.c\r
162 @@ -264,6 +264,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
163                     case NOTMUCH_STATUS_TAG_TOO_LONG:\r
164                     case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:\r
165                     case NOTMUCH_STATUS_LAST_STATUS:\r
166 +                   case NOTMUCH_STATUS_INVALID_DATE:\r
167                         INTERNAL_ERROR ("add_message returned unexpected value: %d",  status);\r
168                         goto DONE;\r
169                 }\r
170 diff --git a/notmuch.el b/notmuch.el\r
171 index c02adc6..73917e7 100644\r
172 --- a/notmuch.el\r
173 +++ b/notmuch.el\r
174 @@ -1379,6 +1379,7 @@ current search results AND that are tagged with the given tag."\r
175      (define-key map "x" 'kill-this-buffer)\r
176      (define-key map "q" 'kill-this-buffer)\r
177      (define-key map "m" 'message-mail)\r
178 +    (define-key map "e" 'notmuch-folder-show-empty-toggle)\r
179      (define-key map ">" 'notmuch-folder-last)\r
180      (define-key map "<" 'notmuch-folder-first)\r
181      (define-key map "=" 'notmuch-folder)\r
182 @@ -1455,14 +1456,32 @@ Currently available key bindings:\r
183    (goto-char (point-max))\r
184    (forward-line -1))\r
185  \r
186 +(defun notmuch-folder-count (search)\r
187 +  (car (process-lines notmuch-command "count" search)))\r
188 +\r
189 +(setq notmuch-folder-show-empty t)\r
190 +\r
191 +(defun notmuch-folder-show-empty-toggle ()\r
192 +  "Toggle the listing of empty folders"\r
193 +  (interactive)\r
194 +  (setq notmuch-folder-show-empty (not notmuch-folder-show-empty))\r
195 +  (notmuch-folder))\r
196 +\r
197  (defun notmuch-folder-add (folders)\r
198    (if folders\r
199 -      (let ((name (car (car folders)))\r
200 +      (let* ((name (car (car folders)))\r
201             (inhibit-read-only t)\r
202 -           (search (cdr (car folders))))\r
203 -       (insert name)\r
204 -       (indent-to 16 1)\r
205 -       (call-process notmuch-command nil t nil "count" search)\r
206 +           (search (cdr (car folders)))\r
207 +           (count (notmuch-folder-count search)))\r
208 +       (if (or notmuch-folder-show-empty\r
209 +               (not (equal count "0")))\r
210 +           (progn\r
211 +             (insert name)\r
212 +             (indent-to 16 1)\r
213 +             (insert count)\r
214 +             (insert "\n")\r
215 +             )\r
216 +         )\r
217         (notmuch-folder-add (cdr folders)))))\r
218  \r
219  (defun notmuch-folder-find-name ()\r
220 -- \r
221 1.6.5.4\r
222 \r