Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / e6 / d0e25ab40ade55f62b3733927e66e7c3ec19fb
1 Return-Path: <markwalters1009@gmail.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 arlo.cworth.org (Postfix) with ESMTP id 9FCD76DE1413\r
6  for <notmuch@notmuchmail.org>; Sun, 25 Oct 2015 10:26:34 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.252\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.252 tagged_above=-999 required=5 tests=[AWL=0.078, \r
12  DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13  FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001,\r
14  RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01,\r
15  RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001, URIBL_SBL=0.644,\r
16  URIBL_SBL_A=0.1] autolearn=disabled\r
17 Received: from arlo.cworth.org ([127.0.0.1])\r
18  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
19  with ESMTP id Y4h1L34iVhTl for <notmuch@notmuchmail.org>;\r
20  Sun, 25 Oct 2015 10:26:30 -0700 (PDT)\r
21 Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com\r
22  [209.85.212.173])\r
23  by arlo.cworth.org (Postfix) with ESMTPS id 52CC96DE1405\r
24  for <notmuch@notmuchmail.org>; Sun, 25 Oct 2015 10:26:30 -0700 (PDT)\r
25 Received: by wicfv8 with SMTP id fv8so87429730wic.0\r
26  for <notmuch@notmuchmail.org>; Sun, 25 Oct 2015 10:26:28 -0700 (PDT)\r
27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
28  h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
29  :mime-version:content-type;\r
30  bh=AkzkUxHyVkx5AjXNSoeCEuIqxGb5E3sQNGVlei9ZISg=;\r
31  b=JOmp2LNx4r9+22TVgSvE6x4LK1cnVfvaD0X29UgrgUHArmkCEqxRNLlEKZCYNiqAYZ\r
32  nUUMwcGtmmhUmQdxTFdFccTcOmxcCJ+Y7MyEzBa/Z+DWnOigOsAIcdNpRYQDvYJRYYhu\r
33  fiQ/66kYv/t1SeB8b133tbsJSMAzqETU2Xw/yDIAU+gEuoNW48Rz4jVvL2oy1m/Xqaga\r
34  KoTZr9Td1UbxiRdo0o8bx0LjGtPUC+Wi7kOrUyCN6PyH/hSoiSB/zWhSvdDLRk/QUkmb\r
35  09moY1FH9kCdXb//Qj87krTZFvokqttF5AQnMfuqHtgQvHIoq/Ekfhz8gCwzOovu5Jf6\r
36  y4IQ==\r
37 X-Received: by 10.180.74.80 with SMTP id r16mr16783084wiv.88.1445793988344;\r
38  Sun, 25 Oct 2015 10:26:28 -0700 (PDT)\r
39 Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
40  by smtp.gmail.com with ESMTPSA id w9sm12984313wjf.20.2015.10.25.10.26.26\r
41  (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
42  Sun, 25 Oct 2015 10:26:27 -0700 (PDT)\r
43 From: Mark Walters <markwalters1009@gmail.com>\r
44 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
45 Subject: Re: [Patch v7 3/3] Emacs: Add address completion based on\r
46  company-mode\r
47 In-Reply-To: <1445786638-13763-4-git-send-email-david@tethera.net>\r
48 References: <1445786638-13763-1-git-send-email-david@tethera.net>\r
49  <1445786638-13763-4-git-send-email-david@tethera.net>\r
50 User-Agent: Notmuch/0.21~rc1+29~g057f24d (http://notmuchmail.org) Emacs/23.4.1\r
51  (x86_64-pc-linux-gnu)\r
52 Date: Sun, 25 Oct 2015 17:26:25 +0000\r
53 Message-ID: <87bnbmdflq.fsf@qmul.ac.uk>\r
54 MIME-Version: 1.0\r
55 Content-Type: text/plain; charset=us-ascii\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.20\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60  <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
62  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
67  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Sun, 25 Oct 2015 17:26:34 -0000\r
69 \r
70 \r
71 On Sun, 25 Oct 2015, David Bremner <david@tethera.net> wrote:\r
72 > From: Michal Sojka <sojkam1@fel.cvut.cz>\r
73 >\r
74 > With this patch, address completion candidates are shown automatically\r
75 > after short typing delay in a nice popup box. This requires company-mode\r
76 > to be installed and it works only on Emacs >= 24. The completion is\r
77 > based entirely on the asynchronous address harvesting from\r
78 > notmuch-address.el so the GUI is theoretically not blocked for long\r
79 > time.\r
80 >\r
81 > The completion works similarly as the TAB-initiated completion from\r
82 > notmuch-address.el, i.e. quick harvest based on user input is executed\r
83 > first and only after full harvesting is finished, in-memory cached data\r
84 > is used.\r
85 > ---\r
86 \r
87 This series looks good to me. There are a couple of very small nits that\r
88 might be worth fixing (on the level of typos/whitespace see below and a\r
89 reply to patch 2). But +1 from me for this version.\r
90 \r
91 \r
92 Best wishes\r
93 \r
94 Mark\r
95 \r
96 >  emacs/Makefile.local     |  1 +\r
97 >  emacs/notmuch-address.el | 18 ++++++++--\r
98 >  emacs/notmuch-company.el | 86 ++++++++++++++++++++++++++++++++++++++++++++++++\r
99 >  emacs/notmuch-mua.el     |  2 +-\r
100 >  4 files changed, 104 insertions(+), 3 deletions(-)\r
101 >  create mode 100644 emacs/notmuch-company.el\r
102 >\r
103 > diff --git a/emacs/Makefile.local b/emacs/Makefile.local\r
104 > index 1109cfa..4c06c52 100644\r
105 > --- a/emacs/Makefile.local\r
106 > +++ b/emacs/Makefile.local\r
107 > @@ -20,6 +20,7 @@ emacs_sources := \\r
108 >       $(dir)/notmuch-print.el \\r
109 >       $(dir)/notmuch-version.el \\r
110 >       $(dir)/notmuch-jump.el \\r
111 > +     $(dir)/notmuch-company.el\r
112 >  \r
113 >  $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp\r
114 >  $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl\r
115 > diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el\r
116 > index aa6228d..5456d5c 100644\r
117 > --- a/emacs/notmuch-address.el\r
118 > +++ b/emacs/notmuch-address.el\r
119 > @@ -22,7 +22,9 @@\r
120 >  (require 'message)\r
121 >  (require 'notmuch-parser)\r
122 >  (require 'notmuch-lib)\r
123 > +(require 'notmuch-company)\r
124 >  ;;\r
125 > +(declare-function company-manual-begin "company")\r
126 >  \r
127 >  (defcustom notmuch-address-command 'internal\r
128 >    "The command which generates possible addresses. It must take a\r
129 > @@ -72,9 +74,21 @@ finished")\r
130 >  (defun notmuch-address-message-insinuate ()\r
131 >    (message "calling notmuch-address-message-insinuate is no longer needed"))\r
132 >  \r
133 > +(defcustom notmuch-address-use-company t\r
134 > +  "If available, use company mode for address completion"\r
135 > +  :type 'boolean\r
136 > +  :group 'notmuch-send)\r
137 > +\r
138 >  (defun notmuch-address-setup ()\r
139 > -  (let ((pair (cons notmuch-address-completion-headers-regexp\r
140 > -                 #'notmuch-address-expand-name)))\r
141 > +  (let* ((use-company (and notmuch-address-use-company\r
142 > +                        (eq notmuch-address-command 'internal)\r
143 > +                        (require 'company nil t)))\r
144 > +      (pair (cons notmuch-address-completion-headers-regexp\r
145 > +                  (if use-company\r
146 > +                      #'company-manual-begin\r
147 > +                    #'notmuch-address-expand-name))))\r
148 > +      (when use-company\r
149 > +     (notmuch-company-setup))\r
150 >        (unless (memq pair message-completion-alist)\r
151 >       (setq message-completion-alist\r
152 >             (push pair message-completion-alist)))))\r
153 > diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el\r
154 > new file mode 100644\r
155 > index 0000000..49d1d81\r
156 > --- /dev/null\r
157 > +++ b/emacs/notmuch-company.el\r
158 > @@ -0,0 +1,86 @@\r
159 > +;; notmuch-company.el --- Mail address completion for notmuch via company-mode  -*- lexical-binding: t -*-\r
160 > +\r
161 > +;; Authors: Trevor Jim <tjim@mac.com>\r
162 > +;;       Michal Sojka <sojkam1@fel.cvut.cz>\r
163 > +;;\r
164 > +;; Keywords: mail, completion\r
165 > +\r
166 > +;; This program is free software; you can redistribute it and/or modify\r
167 > +;; it under the terms of the GNU General Public License as published by\r
168 > +;; the Free Software Foundation, either version 3 of the License, or\r
169 > +;; (at your option) any later version.\r
170 > +\r
171 > +;; This program is distributed in the hope that it will be useful,\r
172 > +;; but WITHOUT ANY WARRANTY; without even the implied warranty of\r
173 > +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
174 > +;; GNU General Public License for more details.\r
175 > +\r
176 > +;; You should have received a copy of the GNU General Public License\r
177 > +;; along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
178 > +\r
179 > +;;; Commentary:\r
180 > +\r
181 > +;; To enable this, install company mode (https://company-mode.github.io/)\r
182 > +;;\r
183 > +;; NB company-minimum-prefix-length defaults to 3 so you don't get\r
184 > +;; completion unless you type 3 characters\r
185 > +\r
186 > +;;; Code:\r
187 > +\r
188 > +(eval-when-compile (require 'cl))\r
189 > +\r
190 > +(defvar notmuch-company-last-prefix nil)\r
191 > +(make-variable-buffer-local 'notmuch-company-last-prefix)\r
192 > +(declare-function company-begin-backend "company")\r
193 > +(declare-function company-grab "company")\r
194 > +(declare-function company-mode "company")\r
195 > +(declare-function company-manual-begin "company")\r
196 > +(defvar company-backends)\r
197 > +\r
198 > +(declare-function notmuch-address-harvest "notmuch-address")\r
199 > +(declare-function notmuch-address-harvest-trigger "notmuch-address")\r
200 > +(declare-function notmuch-address-matching "notmuch-address")\r
201 > +(defvar notmuch-address-full-harvest-finished)\r
202 > +(defvar notmuch-address-completion-headers-regexp)\r
203 > +\r
204 > +;;;###autoload\r
205 > +(defun notmuch-company-setup ()\r
206 > +  (company-mode)\r
207 > +  (make-local-variable 'company-backends)\r
208 > +  (setq company-backends '(notmuch-company)))\r
209 > +\r
210 > +;;;###autoload\r
211 > +(defun notmuch-company (command &optional arg &rest _ignore)\r
212 > +  "`company-mode' completion back-end for `notmuch'."\r
213 > +  (interactive (list 'interactive))\r
214 > +  (require 'company)\r
215 > +  (let ((case-fold-search t)\r
216 > +     (completion-ignore-case t))\r
217 > +    (case command\r
218 > +      (interactive (company-begin-backend 'notmuch-company))\r
219 > +      (prefix (and (derived-mode-p 'message-mode)\r
220 > +                (looking-back (concat notmuch-address-completion-headers-regexp ".*")\r
221 > +                              (line-beginning-position))\r
222 > +                (setq notmuch-company-last-prefix (company-grab "[:,][ \t]*\\(.*\\)" 1 (point-at-bol)))))\r
223 > +      (candidates (cond\r
224 > +                (notmuch-address-full-harvest-finished\r
225 > +                 ;; Update harvested addressed from time to time\r
226 > +                 (notmuch-address-harvest-trigger)\r
227 > +                 (notmuch-address-matching arg))\r
228 > +                (t\r
229 > +                 (cons :async\r
230 > +                       (lambda (callback)\r
231 > +                         ;; First run quick asynchronous harvest based on what the user entered so far\r
232 > +                         (notmuch-address-harvest\r
233 > +                          (format "to:%s*" arg) nil\r
234 > +                          (lambda (_proc _event)\r
235 > +                            (funcall callback (notmuch-address-matching arg))\r
236 > +                            ;; Then (re)start potentially long-running full asynchronous harvesting\r
237 > +                            (notmuch-address-harvest-trigger))))))))\r
238 \r
239 Could we reword this comment? restart definitely suggests to me starting\r
240 a stopped/paused thing not starting it for a second run. Perhaps "Start\r
241 the (potentially long-running) full asynchronous harvest if necessary"?\r
242 (The same comment occurs in Patch 2)\r
243 \r
244  \r
245 > +      (match (if (string-match notmuch-company-last-prefix arg)\r
246 > +              (match-end 0)\r
247 > +            0))\r
248 > +      (no-cache t))))\r
249 > +\r
250 > +\r
251 > +(provide 'notmuch-company)\r
252 > diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
253 > index fd98ea4..c12054c 100644\r
254 > --- a/emacs/notmuch-mua.el\r
255 > +++ b/emacs/notmuch-mua.el\r
256 > @@ -271,7 +271,7 @@ Note that these functions use `mail-citation-hook' if that is non-nil."\r
257 >  (define-derived-mode notmuch-message-mode message-mode "Message[Notmuch]"\r
258 >    "Notmuch message composition mode. Mostly like `message-mode'"\r
259 >    (when notmuch-address-command\r
260 > -    (notmuch-address-setup)))\r
261 > +      (notmuch-address-setup)))\r
262 \r
263 An accidental whitespace change? There were also a couple on\r
264 added/deleted lines in the earlier patches.\r
265 \r
266 >  \r
267 >  (define-key notmuch-message-mode-map (kbd "C-c C-c") #'notmuch-mua-send-and-exit)\r
268 >  (define-key notmuch-message-mode-map (kbd "C-c C-s") #'notmuch-mua-send)\r
269 > -- \r
270 > 2.6.1\r
271 >\r
272 > _______________________________________________\r
273 > notmuch mailing list\r
274 > notmuch@notmuchmail.org\r
275 > https://notmuchmail.org/mailman/listinfo/notmuch\r