Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / 27 / f47d40bc1b3281b24db13908ff5faeebac3b6b
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 75251429E29\r
6         for <notmuch@notmuchmail.org>; Sat,  4 Jun 2011 12:55:30 -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 OWp0STL1zwxw for <notmuch@notmuchmail.org>;\r
17         Sat,  4 Jun 2011 12:55:29 -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 25F86431FB6\r
22         for <notmuch@notmuchmail.org>; Sat,  4 Jun 2011 12:55:29 -0700 (PDT)\r
23 Received: by bwg12 with SMTP id 12so2773598bwg.26\r
24         for <notmuch@notmuchmail.org>; Sat, 04 Jun 2011 12:55:27 -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=BTlj07blQ/QXJfujq6KIr7J5aT0V/qbVb+pZjdb/svU=;\r
30         b=SFBlq4Z9QDurh54XNNOQWphbgtwwAHyZfJZLszZjxxjQNHmD12uEYMrhw+OW+vF+gB\r
31         g31pSCaQAj9b2AnDZm5Lcd+HttXKF76Mcw2N88BUmxjtveoG+xdhYvMMq0C/bhIIYAsV\r
32         9VBYpN/c0jdw7fdBkWtKpABjP8GDM6PpI7NTc=\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=G6UDTYqi4MEAToOtSXEaE6yKNQA3KQgV05lZZmOKvbWTxk0+iIso7dLZTkLsFKompd\r
37         S1Mn+AtIhU0owcEqU2N869ZevrWGVarx5PiCW/rtL2Eq53ykRWqYPjOCvdJj+14VFh+Y\r
38         4ojiXDhO+mBqdIM8eK2UfvZvEpJDvdRrE6Tvg=\r
39 Received: by 10.204.7.88 with SMTP id c24mr1250533bkc.61.1307217327448;\r
40         Sat, 04 Jun 2011 12:55:27 -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 k16sm2158983bks.1.2011.06.04.12.55.25\r
44         (version=TLSv1/SSLv3 cipher=OTHER);\r
45         Sat, 04 Jun 2011 12:55:26 -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: <BANLkTimudbqYy8JhGHu67WsOS04mCm0hfA@mail.gmail.com>\r
51 References: <1307189970-728-1-git-send-email-daniel.schoepe@googlemail.com>\r
52         <BANLkTimudbqYy8JhGHu67WsOS04mCm0hfA@mail.gmail.com>\r
53 User-Agent: Notmuch/0.5-217-gd1f0224 (http://notmuchmail.org) Emacs/23.3.1\r
54         (x86_64-pc-linux-gnu)\r
55 Date: Sat, 04 Jun 2011 21:55:13 +0200\r
56 Message-ID: <87mxhxjrry.fsf@gilead.invalid>\r
57 MIME-Version: 1.0\r
58 Content-Type: multipart/signed; boundary="==-=-=";\r
59         micalg=pgp-sha1; protocol="application/pgp-signature"\r
60 Cc: notmuch@notmuchmail.org\r
61 X-BeenThere: notmuch@notmuchmail.org\r
62 X-Mailman-Version: 2.1.13\r
63 Precedence: list\r
64 List-Id: "Use and development of the notmuch mail system."\r
65         <notmuch.notmuchmail.org>\r
66 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
68 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
69 List-Post: <mailto:notmuch@notmuchmail.org>\r
70 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
71 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
73 X-List-Received-Date: Sat, 04 Jun 2011 19:55:30 -0000\r
74 \r
75 --==-=-=\r
76 Content-Type: multipart/mixed; boundary="=-=-="\r
77 \r
78 --=-=-=\r
79 Content-Type: text/plain\r
80 Content-Transfer-Encoding: quoted-printable\r
81 \r
82 On Sat, 4 Jun 2011 11:32:15 -0400, Austin Clements <amdragon@mit.edu> wrote:\r
83 > Dynamic scoping is obnoxious, but I think programmed completion is\r
84 > steeped in the assumption that you'll use it.  This code would be much\r
85 > simpler if notmuch-query-completions took only `string' and used the\r
86 > dynamically-bound all-compls (which should probably be renamed\r
87 > notmuch-completions or something if you do this).  Then this could be\r
88 > just\r
89 >   (minibuffer-completion-table (completion-table-dynamic\r
90 > #'notmuch-query-completions)))\r
91 > and there'd be no need for quasiquoting, comments, and fake lexical scopi=\r
92 ng.\r
93 \r
94 Sounds reasonable, I guess I really should stop fighting all those ugly\r
95 parts of elisp with unreadable constructs like that. I made it a global\r
96 variable though to avoid compilation warnings about notmuch-completion\r
97 being a free variable. Since it's contents are not dependent on\r
98 how/where notmuch-read-query is called, this shouldn't cause any\r
99 problems, except my personal discomfort arising from the use of side\r
100 effects for something as simple as this. :)\r
101 \r
102 > > +    (define-key keymap (kbd "<tab>") 'minibuffer-complete)\r
103 >=20\r
104 > This probably deserves a comment about why you're doing so much work\r
105 > to avoid completing-read (which I assume is because it also binds SPC,\r
106 > even if require-match is nil, which is unfortunate).\r
107 \r
108 Yes, that was the reason.\r
109 \r
110 Another thing that bugs me, is that I did not find a better way of doing\r
111 the completion: Ideally I'd like to just specify a list of completions\r
112 for individual words and have emacs handle separating the input string\r
113 into individual words, but I couldn't find any options to accomplish\r
114 that.\r
115 \r
116 An updated patch is attached.\r
117 \r
118 --=-=-=\r
119 Content-Type: text/x-diff\r
120 Content-Disposition: inline;\r
121  filename=0001-emacs-Tab-completion-for-notmuch-search-and-notmuch-.patch\r
122 Content-Transfer-Encoding: quoted-printable\r
123 \r
124 From=2070642aecbf63428d9bcedc108c55f65574a792e7 Mon Sep 17 00:00:00 2001\r
125 From: Daniel Schoepe <daniel.schoepe@googlemail.com>\r
126 Date: Sat, 4 Jun 2011 14:17:44 +0200\r
127 Subject: [PATCH] emacs: Tab completion for notmuch-search and\r
128  notmuch-search-filter\r
129 \r
130 This patch adds completion with <tab> in the minibuffer for\r
131 notmuch-search and notmuch-search-filter.\r
132 =2D--\r
133  emacs/notmuch.el |   35 +++++++++++++++++++++++++++++++++--\r
134  1 files changed, 33 insertions(+), 2 deletions(-)\r
135 \r
136 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
137 index 3311fe8..17c214c 100644\r
138 =2D-- a/emacs/notmuch.el\r
139 +++ b/emacs/notmuch.el\r
140 @@ -72,6 +72,9 @@ For example:\r
141    :type '(alist :key-type (string) :value-type (string))\r
142    :group 'notmuch)\r
143 =20\r
144 +(defvar notmuch-completions nil\r
145 +  "List of completions used in notmuch-query-completions")\r
146 +\r
147  (defun notmuch-select-tag-with-completion (prompt &rest search-terms)\r
148    (let ((tag-list\r
149          (with-output-to-string\r
150 @@ -882,6 +885,34 @@ characters as well as `_.+-'.\r
151            (concat "*notmuch-search-" query "*"))\r
152           )))\r
153 =20\r
154 +(defun notmuch-query-completions (string)\r
155 +  "Return possible completions for STRING."\r
156 +  (cond\r
157 +   ;; this ugly regexp is used to get the last word of the input\r
158 +   ;; possibly preceded by a '('\r
159 +   ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)\r
160 +    (mapcar (lambda (compl)\r
161 +             (concat (match-string-no-properties 1 string) compl))\r
162 +           (all-completions (match-string-no-properties 2 string)\r
163 +                            notmuch-completions)))\r
164 +   (t (list string))))\r
165 +\r
166 +(defun notmuch-read-query (prompt)\r
167 +  "Read a notmuch-query from the minibuffer with completion.\r
168 +\r
169 +PROMPT is the string to prompt with."\r
170 +  (let ((keymap (copy-keymap minibuffer-local-map))\r
171 +       (minibuffer-completion-table (completion-table-dynamic #'notmuch-query-co=\r
172 mpletions)))\r
173 +    ;; this was simpler than convincing completing-read to accept spaces:\r
174 +    (define-key keymap (kbd "<tab>") 'minibuffer-complete)\r
175 +    (setq notmuch-completions\r
176 +         (append (list "folder:" "thread:" "id:" "date:" "from:" "to:"\r
177 +                       "subject:" "attachment:")\r
178 +                 (mapcar (lambda (tag)\r
179 +                           (concat "tag:" tag))\r
180 +                         (process-lines "notmuch" "search-tags"))))\r
181 +    (read-from-minibuffer prompt nil keymap nil minibuffer-history nil nil=\r
182 )))\r
183 +\r
184  ;;;###autoload\r
185  (defun notmuch-search (query &optional oldest-first target-thread target-l=\r
186 ine continuation)\r
187    "Run \"notmuch search\" with the given query string and display results.\r
188 @@ -893,7 +924,7 @@ The optional parameters are used as follows:\r
189                   current if it appears in the search results.\r
190    target-line: The line number to move to if the target thread does not\r
191                 appear in the search results."\r
192 =2D  (interactive "sNotmuch search: ")\r
193 +  (interactive (notmuch-read-query "Notmuch search: "))\r
194    (let ((buffer (get-buffer-create (notmuch-search-buffer-title query))))\r
195      (switch-to-buffer buffer)\r
196      (notmuch-search-mode)\r
197 @@ -991,7 +1022,7 @@ search."\r
198 =20\r
199  Runs a new search matching only messages that match both the\r
200  current search results AND the additional query string provided."\r
201 =2D  (interactive "sFilter search: ")\r
202 +  (interactive (notmuch-read-query "Filter search: "))\r
203    (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-rege=\r
204 xp query)\r
205                            (concat "( " query " )")\r
206                          query)))\r
207 =2D-=20\r
208 1.7.5.3\r
209 \r
210 \r
211 --=-=-=--\r
212 \r
213 --==-=-=\r
214 Content-Type: application/pgp-signature\r
215 \r
216 -----BEGIN PGP SIGNATURE-----\r
217 Version: GnuPG v1.4.11 (GNU/Linux)\r
218 \r
219 iQIcBAEBAgAGBQJN6o2iAAoJEIaTAtce+Z+JJBkP/jJtzFb/DDMBD1loU9a/vdUg\r
220 X7GJRZwIijPoT59bsjlwwI+ArsPzAWcRK2fulyEiEjXcK+SQqThoUNR+9PuW8s8/\r
221 ym5e/+lDiGFxk7txUUfNzUpY9/I3tc773C6f2xkRHPN2fPdAi9wOPMJNYm1ckp3F\r
222 XpMAX0xYb/ebXNFulbpEnyVB9hsXlQXOyQVhomWdIdf+LULlyLkD9nVWx+sXNiQS\r
223 ksB9GdwfuWdQY8A5Wf18Y/7RBYdkrZTB36nG3ZTDe+ARBLyvwLFQNwr2io6wF7IS\r
224 dd+GciK2EnpvX8hB1B83g+1Nc/nsuT5fvn7YDIGGnnE4ILOm5hPvTpZqcEE2jbXN\r
225 X7ST0NRQiDhmsEqIHx01hbzWl1+FXG0vDECTfZyq8dF5nKR8ea+Ry36q8JQa4/Xc\r
226 Lth8PDQTehkrLleTtUtjtiO/AbH165frPA+UlZkltSEFiApWeTUJU+BKOT78BV+U\r
227 oJgwLrdHMKdgjjHhiZyViJwXV2WSj4wvN2u+Pa5UrYtxq6gtQ6cG81S9pQENXf0g\r
228 ZtQfbGPjvYdBEwCpDAxBe4oXM+K4x2zGe4v58A+p7NmPTQBr741yHz9CqoY7ASDl\r
229 55LZ8H1pw7gzIATLXwrpcL0OqghJas1Mp3UXNzQ6gn5/5I2X6NS0d4ThSXTg9Eif\r
230 k1FdFpHwlAvRqqae781K\r
231 =FOTO\r
232 -----END PGP SIGNATURE-----\r
233 --==-=-=--\r