Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 5d / 0d1e218c18c919f9ae0186c97ae0bcbb5c8061
1 Return-Path: <amthrax@drake.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 F125341ED73\r
6         for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 16:17:39 -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 dvBJNufrmKC8 for <notmuch@notmuchmail.org>;\r
16         Sat, 14 Jan 2012 16:17:38 -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 7E6D441ED6C\r
20         for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 16:17:38 -0800 (PST)\r
21 X-AuditID: 12074424-b7fae6d000000906-cb-4f121b219632\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id A0.27.02310.12B121F4; Sat, 14 Jan 2012 19:17:38 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0F0Hbu8032304; \r
27         Sat, 14 Jan 2012 19:17:37 -0500\r
28 Received: from drake.mit.edu (26-4-180.dynamic.csail.mit.edu [18.26.4.180])\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 q0F0HZv7027543\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Sat, 14 Jan 2012 19:17:36 -0500 (EST)\r
34 Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
35         (envelope-from <amthrax@drake.mit.edu>)\r
36         id 1RmDmx-0004Rx-O7; Sat, 14 Jan 2012 19:17:35 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH v3 1/2] lib: Add support for automatically excluding tags from\r
40         queries\r
41 Date: Sat, 14 Jan 2012 19:17:33 -0500\r
42 Message-Id: <1326586654-16840-2-git-send-email-amdragon@mit.edu>\r
43 X-Mailer: git-send-email 1.7.7.3\r
44 In-Reply-To: <1326586654-16840-1-git-send-email-amdragon@mit.edu>\r
45 References: <1326496024-14403-1-git-send-email-amdragon@mit.edu>\r
46         <1326586654-16840-1-git-send-email-amdragon@mit.edu>\r
47 X-Brightmail-Tracker:\r
48  H4sIAAAAAAAAA+NgFjrIIsWRmVeSWpSXmKPExsUixG6nrqskLeRvsH4eq0XTdGeLPfu8LK7f\r
49         nMnswOxx9zSXx637r9k9nq26xRzAHMVlk5Kak1mWWqRvl8CVsaC7l63gm0LFlY7LLA2MV6W6\r
50         GDk5JARMJC5dOMcIYYtJXLi3ng3EFhLYxyjx6rJaFyMXkL2BUaKndTlU4jiTxOY3cRCJ+YwS\r
51         h18+BetmE9CQ2LZ/OZgtIiAtsfPubFYQm1nAUeLnvYdgtrBAmMSVCY/BalgEVCW275rD0sXI\r
52         wcEr4CBxd4MyxBEKEudWn2MHsTmBWucc6GIEKRESKJe4di9sAiP/AkaGVYyyKblVurmJmTnF\r
53         qcm6xcmJeXmpRbrmermZJXqpKaWbGMEh5aKyg7H5kNIhRgEORiUeXsksAX8h1sSy4srcQ4yS\r
54         HExKorz2UkL+QnxJ+SmVGYnFGfFFpTmpxYcYJTiYlUR4F7AC5XhTEiurUovyYVLSHCxK4rwa\r
55         Wu/8hATSE0tSs1NTC1KLYLIyHBxKEry+IEMFi1LTUyvSMnNKENJMHJwgw3mAhtuC1PAWFyTm\r
56         FmemQ+RPMSpKifMGgSQEQBIZpXlwvbCYf8UoDvSKMK8jSBUPMF3Adb8CGswENLgshQ9kcEki\r
57         QkqqgXHPe5HEl0GZmxyC3O32xm/tTLc2ajnVPcvgB8eLJ9tbuwu/n0xYdGTdggKvW0sZvl7s\r
58         ehzyT3AOv9qRk4wtcW6vTrR3XD4rcEYhzWJu0p/3Oj946wx+/1qv+4CzrJOPXzWK9x8X6+7/\r
59         s/30Nu3yXq58bUGuRUyY8OrVu76WZ7+b8UGKPfH49atKLMUZiYZazEXFiQDUwZCU1AIAAA==\r
60 X-BeenThere: notmuch@notmuchmail.org\r
61 X-Mailman-Version: 2.1.13\r
62 Precedence: list\r
63 List-Id: "Use and development of the notmuch mail system."\r
64         <notmuch.notmuchmail.org>\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
68 List-Post: <mailto:notmuch@notmuchmail.org>\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
72 X-List-Received-Date: Sun, 15 Jan 2012 00:17:40 -0000\r
73 \r
74 This is useful for tags like "deleted" and "spam" that people\r
75 generally want to exclude from query results.  These exclusions will\r
76 be overridden if a tag is explicitly mentioned in a query.\r
77 ---\r
78  lib/notmuch-private.h |    2 +-\r
79  lib/notmuch.h         |    6 ++++++\r
80  lib/query.cc          |   35 +++++++++++++++++++++++++++++++++++\r
81  3 files changed, 42 insertions(+), 1 deletions(-)\r
82 \r
83 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
84 index 60a932f..7bf153e 100644\r
85 --- a/lib/notmuch-private.h\r
86 +++ b/lib/notmuch-private.h\r
87 @@ -458,7 +458,7 @@ typedef struct _notmuch_string_node {\r
88      struct _notmuch_string_node *next;\r
89  } notmuch_string_node_t;\r
90  \r
91 -typedef struct _notmuch_string_list {\r
92 +typedef struct visible _notmuch_string_list {\r
93      int length;\r
94      notmuch_string_node_t *head;\r
95      notmuch_string_node_t **tail;\r
96 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
97 index 9f23a10..7929fe7 100644\r
98 --- a/lib/notmuch.h\r
99 +++ b/lib/notmuch.h\r
100 @@ -457,6 +457,12 @@ notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);\r
101  notmuch_sort_t\r
102  notmuch_query_get_sort (notmuch_query_t *query);\r
103  \r
104 +/* Add a tag that will be excluded from the query results by default.\r
105 + * This exclusion will be overridden if this tag appears explicitly in\r
106 + * the query. */\r
107 +void\r
108 +notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag);\r
109 +\r
110  /* Execute a query for threads, returning a notmuch_threads_t object\r
111   * which can be used to iterate over the results. The returned threads\r
112   * object is owned by the query and as such, will only be valid until\r
113 diff --git a/lib/query.cc b/lib/query.cc\r
114 index b6c0f12..0b36602 100644\r
115 --- a/lib/query.cc\r
116 +++ b/lib/query.cc\r
117 @@ -27,6 +27,7 @@ struct _notmuch_query {\r
118      notmuch_database_t *notmuch;\r
119      const char *query_string;\r
120      notmuch_sort_t sort;\r
121 +    notmuch_string_list_t *exclude_terms;\r
122  };\r
123  \r
124  typedef struct _notmuch_mset_messages {\r
125 @@ -76,6 +77,8 @@ notmuch_query_create (notmuch_database_t *notmuch,\r
126  \r
127      query->sort = NOTMUCH_SORT_NEWEST_FIRST;\r
128  \r
129 +    query->exclude_terms = _notmuch_string_list_create (query);\r
130 +\r
131      return query;\r
132  }\r
133  \r
134 @@ -97,6 +100,13 @@ notmuch_query_get_sort (notmuch_query_t *query)\r
135      return query->sort;\r
136  }\r
137  \r
138 +void\r
139 +notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag)\r
140 +{\r
141 +    char *term = talloc_asprintf (query, "%s%s", _find_prefix ("tag"), tag);\r
142 +    _notmuch_string_list_append (query->exclude_terms, term);\r
143 +}\r
144 +\r
145  /* We end up having to call the destructors explicitly because we had\r
146   * to use "placement new" in order to initialize C++ objects within a\r
147   * block that we allocated with talloc. So C++ is making talloc\r
148 @@ -112,6 +122,27 @@ _notmuch_messages_destructor (notmuch_mset_messages_t *messages)\r
149      return 0;\r
150  }\r
151  \r
152 +/* Return a query that does not match messages with the excluded tags\r
153 + * registered with the query.  Any tags that explicitly appear in\r
154 + * xquery will not be excluded. */\r
155 +static Xapian::Query\r
156 +_notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)\r
157 +{\r
158 +    for (notmuch_string_node_t *term = query->exclude_terms->head; term;\r
159 +        term = term->next) {\r
160 +       Xapian::TermIterator it = xquery.get_terms_begin ();\r
161 +       Xapian::TermIterator end = xquery.get_terms_end ();\r
162 +       for (; it != end; it++) {\r
163 +           if ((*it).compare (term->string) == 0)\r
164 +               break;\r
165 +       }\r
166 +       if (it == end)\r
167 +           xquery = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
168 +                                   xquery, Xapian::Query (term->string));\r
169 +    }\r
170 +    return xquery;\r
171 +}\r
172 +\r
173  notmuch_messages_t *\r
174  notmuch_query_search_messages (notmuch_query_t *query)\r
175  {\r
176 @@ -157,6 +188,8 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
177                                          mail_query, string_query);\r
178         }\r
179  \r
180 +       final_query = _notmuch_exclude_tags (query, final_query);\r
181 +\r
182         enquire.set_weighting_scheme (Xapian::BoolWeight());\r
183  \r
184         switch (query->sort) {\r
185 @@ -436,6 +469,8 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
186                                          mail_query, string_query);\r
187         }\r
188  \r
189 +       final_query = _notmuch_exclude_tags (query, final_query);\r
190 +\r
191         enquire.set_weighting_scheme(Xapian::BoolWeight());\r
192         enquire.set_docid_order(Xapian::Enquire::ASCENDING);\r
193  \r
194 -- \r
195 1.7.7.3\r
196 \r