Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / e9 / 7c609f04d871b8dd8869750dd1b8804fcead61
1 Return-Path: <daniel.schoepe@googlemail.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 870C7429E2C\r
6         for <notmuch@notmuchmail.org>; Sat,  4 Jun 2011 15:54:56 -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.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id BRdK3rxAtbgO for <notmuch@notmuchmail.org>;\r
17         Sat,  4 Jun 2011 15:54:55 -0700 (PDT)\r
18 Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com\r
19         [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 32464431FB6\r
22         for <notmuch@notmuchmail.org>; Sat,  4 Jun 2011 15:54:55 -0700 (PDT)\r
23 Received: by bwg12 with SMTP id 12so2829274bwg.26\r
24         for <notmuch@notmuchmail.org>; Sat, 04 Jun 2011 15:54:53 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=googlemail.com; s=gamma;\r
27         h=domainkey-signature:from:to:cc:subject:in-reply-to:references\r
28         :user-agent:date:message-id:mime-version:content-type;\r
29         bh=PuCohA8+MnhAGfBOATMSRZyH+viURsTXEvfikpEIidM=;\r
30         b=OtdwxqlRVNOYw4d6uGfgsBsDsIt//lDpb7WxRIsc8pwFHOEgrXF2SQjFTtDI9oH267\r
31         VNgmKGx4bsu787fE6Md76km7h6L8joMDNwN3ao2sJr7k3/MMLe21l9UPH99ELhLRJ5Ji\r
32         OT/9xRH1mW56QGWqTsZDag2YRMBYviFwih1xw=\r
33 DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma;\r
34         h=from:to:cc:subject:in-reply-to:references:user-agent:date\r
35         :message-id:mime-version:content-type;\r
36         b=AaZRJxQYyinpO5SHwuqdTcnRoU2qYFKjiL0bwkpgBiFp+JUPrJ7kmy+B8fwcqFZHRc\r
37         iIXcUvjOlrZSsx6MIV/apjqzrKNX3UcFaE1xknYO/N0RkH5uNQhJkv/7HVEbMsZbUngz\r
38         +lBhX4OqDyCdJ0C7oieay5azPDHouHb7Ob024=\r
39 Received: by 10.204.82.224 with SMTP id c32mr3304890bkl.161.1307228093761;\r
40         Sat, 04 Jun 2011 15:54:53 -0700 (PDT)\r
41 Received: from localhost (dslb-088-069-155-133.pools.arcor-ip.net\r
42         [88.69.155.133])\r
43         by mx.google.com with ESMTPS id ek1sm2237091bkb.9.2011.06.04.15.54.51\r
44         (version=TLSv1/SSLv3 cipher=OTHER);\r
45         Sat, 04 Jun 2011 15:54:52 -0700 (PDT)\r
46 From: Daniel Schoepe <daniel.schoepe@googlemail.com>\r
47 To: Austin Clements <amdragon@MIT.EDU>\r
48 Subject: Re: [PATCH] emacs: Tab completion for notmuch-search and\r
49         notmuch-search-filter\r
50 In-Reply-To: <20110604215523.GF29861@mit.edu>\r
51 References: <1307189970-728-1-git-send-email-daniel.schoepe@googlemail.com>\r
52         <BANLkTimudbqYy8JhGHu67WsOS04mCm0hfA@mail.gmail.com>\r
53         <87mxhxjrry.fsf@gilead.invalid> <20110604215523.GF29861@mit.edu>\r
54 User-Agent: Notmuch/0.5-217-gd1f0224 (http://notmuchmail.org) Emacs/23.3.1\r
55         (x86_64-pc-linux-gnu)\r
56 Date: Sun, 05 Jun 2011 00:54:38 +0200\r
57 Message-ID: <87hb85jjgx.fsf@gilead.invalid>\r
58 MIME-Version: 1.0\r
59 Content-Type: multipart/signed; boundary="==-=-=";\r
60         micalg=pgp-sha1; protocol="application/pgp-signature"\r
61 Cc: notmuch@notmuchmail.org\r
62 X-BeenThere: notmuch@notmuchmail.org\r
63 X-Mailman-Version: 2.1.13\r
64 Precedence: list\r
65 List-Id: "Use and development of the notmuch mail system."\r
66         <notmuch.notmuchmail.org>\r
67 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
69 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
70 List-Post: <mailto:notmuch@notmuchmail.org>\r
71 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
72 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
73         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
74 X-List-Received-Date: Sat, 04 Jun 2011 22:54:56 -0000\r
75 \r
76 --==-=-=\r
77 Content-Type: multipart/mixed; boundary="=-=-="\r
78 \r
79 --=-=-=\r
80 Content-Type: text/plain\r
81 Content-Transfer-Encoding: quoted-printable\r
82 \r
83 On Sat, 4 Jun 2011 17:55:24 -0400, Austin Clements <amdragon@MIT.EDU> wrote:\r
84 > Oh, sorry, I wasn't suggesting setq'ing a global.  I agree that that's\r
85 > really ugly.  Rather, something like\r
86 >=20\r
87 > (defun notmuch-query-completions (string)\r
88 >   ... as you have it now ...)\r
89 >=20\r
90 > (defun notmuch-read-query (prompt)\r
91 >   (let ((notmuch-completions (append (list "folder:" ...)))\r
92 >         (keymap ...)\r
93 >         (minibuffer-completion-table ...))\r
94 >     (read-from-minibuffer ...)))\r
95 >=20\r
96 > Unfortunately, you still need the global defvar to avoid compilation\r
97 > warnings, but this at least avoids the side-effects, and is probably\r
98 > how programmed completion was intended to be used.\r
99 \r
100 Both alternatives seem about equally ugly to me, since the one using\r
101 dynamic scoping still uses side-effects, because it still passes the\r
102 completion information around without using it as an argument to\r
103 notmuch-query-completions. At least defvar-ing a global variable and\r
104 then never actually using it, seems somewhat unclean as well.\r
105 \r
106 > Alternatively, here's a completely different way to structure this\r
107 > that avoids globals and dynamic scoping entirely.  This is how some of\r
108 > the standard completing read functions appear to work:\r
109 \r
110 Ah right, I forgot that using macros from cl is fine even in library\r
111 code.\r
112 \r
113 \r
114 --=-=-=\r
115 Content-Type: text/x-diff\r
116 Content-Disposition: inline;\r
117  filename=0001-emacs-Tab-completion-for-notmuch-search-and-notmuch-.patch\r
118 Content-Transfer-Encoding: quoted-printable\r
119 \r
120 From=207768f41ac44213c5e2c1dc3b0f13e3edf1d97a26 Mon Sep 17 00:00:00 2001\r
121 From: Daniel Schoepe <daniel.schoepe@googlemail.com>\r
122 Date: Sat, 4 Jun 2011 14:17:44 +0200\r
123 Subject: [PATCH] emacs: Tab completion for notmuch-search and\r
124  notmuch-search-filter\r
125 \r
126 This patch adds completion with <tab> in the minibuffer for\r
127 notmuch-search and notmuch-search-filter.\r
128 =2D--\r
129  emacs/notmuch.el |   36 ++++++++++++++++++++++++++++++++++--\r
130  1 files changed, 34 insertions(+), 2 deletions(-)\r
131 \r
132 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
133 index 3311fe8..33c34bd 100644\r
134 =2D-- a/emacs/notmuch.el\r
135 +++ b/emacs/notmuch.el\r
136 @@ -72,6 +72,9 @@ For example:\r
137    :type '(alist :key-type (string) :value-type (string))\r
138    :group 'notmuch)\r
139 =20\r
140 +(defvar notmuch-completions nil\r
141 +  "List of completions used in notmuch-query-completions")\r
142 +\r
143  (defun notmuch-select-tag-with-completion (prompt &rest search-terms)\r
144    (let ((tag-list\r
145          (with-output-to-string\r
146 @@ -882,6 +885,35 @@ characters as well as `_.+-'.\r
147            (concat "*notmuch-search-" query "*"))\r
148           )))\r
149 =20\r
150 +(defun notmuch-read-query (prompt)\r
151 +  "Read a notmuch-query from the minibuffer with completion.\r
152 +\r
153 +PROMPT is the string to prompt with."\r
154 +  (lexical-let\r
155 +      ((completions=20\r
156 +       (append (list "folder:" "thread:" "id:" "date:" "from:" "to:"\r
157 +                     "subject:" "attachment:")\r
158 +               (mapcar (lambda (tag)\r
159 +                         (concat "tag:" tag))\r
160 +                       (process-lines "notmuch" "search-tags")))))\r
161 +    (let ((keymap (copy-keymap minibuffer-local-map))\r
162 +         (minibuffer-completion-table\r
163 +          (completion-table-dynamic\r
164 +           (lambda (string)\r
165 +             ;; generate a list of possible completions for the current input\r
166 +             (cond\r
167 +              ;; this ugly regexp is used to get the last word of the input\r
168 +              ;; possibly preceded by a '('\r
169 +              ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)\r
170 +               (mapcar (lambda (compl)\r
171 +                         (concat (match-string-no-properties 1 string) compl))\r
172 +                       (all-completions (match-string-no-properties 2 string)\r
173 +                                        completions)))\r
174 +              (t (list string)))))))\r
175 +      ;; this was simpler than convincing completing-read to accept spaces:\r
176 +      (define-key keymap (kbd "<tab>") 'minibuffer-complete)\r
177 +      (read-from-minibuffer prompt nil keymap nil minibuffer-history nil n=\r
178 il))))\r
179 +\r
180  ;;;###autoload\r
181  (defun notmuch-search (query &optional oldest-first target-thread target-l=\r
182 ine continuation)\r
183    "Run \"notmuch search\" with the given query string and display results.\r
184 @@ -893,7 +925,7 @@ The optional parameters are used as follows:\r
185                   current if it appears in the search results.\r
186    target-line: The line number to move to if the target thread does not\r
187                 appear in the search results."\r
188 =2D  (interactive "sNotmuch search: ")\r
189 +  (interactive (list (notmuch-read-query "Notmuch search: ")))\r
190    (let ((buffer (get-buffer-create (notmuch-search-buffer-title query))))\r
191      (switch-to-buffer buffer)\r
192      (notmuch-search-mode)\r
193 @@ -991,7 +1023,7 @@ search."\r
194 =20\r
195  Runs a new search matching only messages that match both the\r
196  current search results AND the additional query string provided."\r
197 =2D  (interactive "sFilter search: ")\r
198 +  (interactive (list (notmuch-read-query "Filter search: ")))\r
199    (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-rege=\r
200 xp query)\r
201                            (concat "( " query " )")\r
202                          query)))\r
203 =2D-=20\r
204 1.7.5.3\r
205 \r
206 \r
207 --=-=-=--\r
208 \r
209 --==-=-=\r
210 Content-Type: application/pgp-signature\r
211 \r
212 -----BEGIN PGP SIGNATURE-----\r
213 Version: GnuPG v1.4.11 (GNU/Linux)\r
214 \r
215 iQIcBAEBAgAGBQJN6revAAoJEIaTAtce+Z+JOEwP/1sLQk12MjZ2+4TxZIgpQpri\r
216 /2cZr5boUa128WDXFD7adLRQGoIPaYWkp5kNkHYqcc12Vo23fNRIh4dmchb0bdqL\r
217 CVfW8aNID6rMrJ9XLQPuehTPo6IX2ixEpkARPC23XgYDDqEt5OJJzo07DDTOluwG\r
218 LxLQ58vhu4B1yTm8OoD765ohHz89buDNchRblvPrlVVIaZ7nE2Jjd76J62Buayhc\r
219 mv+f53n8sghK/k3m9nT2lOvuEK7ZvWpMPfe+O62HHhoE1bkSgxAV35Mo+eKjSWMT\r
220 JIcdO7Pouflh2vleDhQcSxF7Sp5/3uC4nUnBRUbDUvDZkHPuzSLuG1ml2Z8yRanJ\r
221 beegu6kuAVmrEb2HFDQbYjPOoh1lLYEZLXrWv2CbX5ouwDPa+HBHuc8xgXAmx1oH\r
222 /BtrnW/dTK9COtm2PxwgRXpUqPnLr0iPvMwDP8tIrsHm3pl2+5Um3EhvfZ9bjPft\r
223 qbE04XTm+ZNpOsnDOKOJYoTWYHHuvtoVo8iIrH6rNERVWKcdM5Dg559gDAuLREJd\r
224 usDbjX0CmPhPS050CJWW8/tUbC0GRfEdJUpI10+jzNpS6nA6rr7MCkYHhg51kFID\r
225 IuMXJsQ/y60pBbO3C0sDIJYxYhFWZ6OjiyMbfH/QNWftCSvBW6SQZW/pbdifKJnK\r
226 1i5oO9nE72nR7egz9K41\r
227 =sKyo\r
228 -----END PGP SIGNATURE-----\r
229 --==-=-=--\r