Re: [PATCH 3/5] nmbug-status: Add an nmbug-status(5) man page
[notmuch-archives.git] / 62 / 3b7e266e5ed120f8b52c891970f549cfbdd3ca
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 393086DE1733\r
6  for <notmuch@notmuchmail.org>; Tue, 27 Oct 2015 02:05:37 -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.124\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.124 tagged_above=-999 required=5 tests=[AWL=0.446,\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, RCVD_IN_DNSWL_LOW=-0.7,\r
14  RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001]\r
15  autolearn=disabled\r
16 Received: from arlo.cworth.org ([127.0.0.1])\r
17  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
18  with ESMTP id 53f91SiiWBEI for <notmuch@notmuchmail.org>;\r
19  Tue, 27 Oct 2015 02:05:35 -0700 (PDT)\r
20 Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com\r
21  [209.85.212.173])\r
22  by arlo.cworth.org (Postfix) with ESMTPS id E2FCA6DE13EF\r
23  for <notmuch@notmuchmail.org>; Tue, 27 Oct 2015 02:05:34 -0700 (PDT)\r
24 Received: by wicll6 with SMTP id ll6so149967543wic.1\r
25  for <notmuch@notmuchmail.org>; Tue, 27 Oct 2015 02:05:31 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27  h=from:to:cc:subject:date:message-id;\r
28  bh=6YOP8beHAArwmZTj4i+0EcVohWzQRKcyC01X5S9uqI4=;\r
29  b=W2disYO3WsNJZoB7UPcDZw6uGWbx26LJkky8OJco3Y7irMQJmrzGZhaf1a0+7x1DFI\r
30  uQVRgkZcMCGngQoHJhUJhOIyzoVDL7p532uXeSY4hHVKp7GagPdOYtxoRhl+akB77IEH\r
31  QUr+eaNEz5kbd/5Wgw6kmpE6kIGAgS/WqgvM3JX150c4veu3uDVbbvyMUJj88iSJZAF6\r
32  E0SjUtaNwVIxhfcxidzW50cldr7fTzDANieHvvd+LQfUcP9pOlc6w378KgqXJrozE6P+\r
33  Twl1Ua30QkDIB845BQRzxjKYUOnV0QdxeXU2urNiQXwen5TAoj9zb6Gw9bK0k2HER3wS\r
34  SoDA==\r
35 X-Received: by 10.194.59.137 with SMTP id z9mr25820928wjq.28.1445936731562;\r
36  Tue, 27 Oct 2015 02:05:31 -0700 (PDT)\r
37 Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
38  by smtp.gmail.com with ESMTPSA id q8sm16965563wiz.23.2015.10.27.02.05.30\r
39  (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
40  Tue, 27 Oct 2015 02:05:31 -0700 (PDT)\r
41 From: Mark Walters <markwalters1009@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH (draft)] company model for external programs\r
44 Date: Tue, 27 Oct 2015 09:05:28 +0000\r
45 Message-Id: <1445936728-30840-1-git-send-email-markwalters1009@gmail.com>\r
46 X-Mailer: git-send-email 2.1.4\r
47 X-BeenThere: notmuch@notmuchmail.org\r
48 X-Mailman-Version: 2.1.20\r
49 Precedence: list\r
50 List-Id: "Use and development of the notmuch mail system."\r
51  <notmuch.notmuchmail.org>\r
52 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
53  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
55 List-Post: <mailto:notmuch@notmuchmail.org>\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
57 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
58  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
59 X-List-Received-Date: Tue, 27 Oct 2015 09:05:37 -0000\r
60 \r
61 ---\r
62 \r
63 This is an attempt to make company mode work for external address\r
64 completion programs. We need to be able to run the address completion\r
65 asynchronously.\r
66 \r
67 The changes are three fold: separate out the internal completion code\r
68 into its own function, allow the external program to be called\r
69 asynchronously, and copy the relevant code from the emacs function\r
70 process-lines into our function as it doesn't appear to be available\r
71 as a separate function.\r
72 \r
73 It seems to work in light testing but asynchronous emacs is always a\r
74 little fragile/tricky.\r
75 \r
76 Best wishes\r
77 \r
78 Mark\r
79 \r
80 \r
81 \r
82 emacs/notmuch-address.el |  2 +-\r
83  emacs/notmuch-company.el | 65 +++++++++++++++++++++++++++++++++++++-----------\r
84  2 files changed, 51 insertions(+), 16 deletions(-)\r
85 \r
86 diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el\r
87 index 49e2402..65d04ce 100644\r
88 --- a/emacs/notmuch-address.el\r
89 +++ b/emacs/notmuch-address.el\r
90 @@ -81,7 +81,7 @@ (defcustom notmuch-address-use-company t\r
91  \r
92  (defun notmuch-address-setup ()\r
93    (let* ((use-company (and notmuch-address-use-company\r
94 -                          (eq notmuch-address-command 'internal)\r
95 +               ;;         (eq notmuch-address-command 'internal)\r
96                            (require 'company nil t)))\r
97          (pair (cons notmuch-address-completion-headers-regexp\r
98                      (if use-company\r
99 diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el\r
100 index add3161..dc3d018 100644\r
101 --- a/emacs/notmuch-company.el\r
102 +++ b/emacs/notmuch-company.el\r
103 @@ -42,6 +42,7 @@ (defvar company-backends)\r
104  (declare-function notmuch-address-matching "notmuch-address")\r
105  (defvar notmuch-address-full-harvest-finished)\r
106  (defvar notmuch-address-completion-headers-regexp)\r
107 +(defvar notmuch-address-command)\r
108  \r
109  ;;;###autoload\r
110  (defun notmuch-company-setup ()\r
111 @@ -49,6 +50,54 @@ (defun notmuch-company-setup ()\r
112    (make-local-variable 'company-backends)\r
113    (setq company-backends '(notmuch-company)))\r
114  \r
115 +(defun notmuch-company-address-internal (arg)\r
116 +  (cond\r
117 +   (notmuch-address-full-harvest-finished\r
118 +    ;; Update harvested addressed from time to time\r
119 +    (notmuch-address-harvest-trigger)\r
120 +    (notmuch-address-matching arg))\r
121 +   (t\r
122 +    (cons :async\r
123 +         (lambda (callback)\r
124 +           ;; First run quick asynchronous harvest based on what the user entered so far\r
125 +           (notmuch-address-harvest\r
126 +            (format "to:%s*" arg) nil\r
127 +            (lambda (_proc _event)\r
128 +              (funcall callback (notmuch-address-matching arg))\r
129 +              ;; Then start the (potentially long-running) full asynchronous harvest if necessary\r
130 +              (notmuch-address-harvest-trigger))))))))\r
131 +\r
132 +(defun notmuch-company-external-sentinel (callback proc _event)\r
133 +  (let (lines)\r
134 +    (with-current-buffer (process-buffer proc)\r
135 +      ;; Copied verbatim from the process-lines function in subr.el in\r
136 +      ;; the standard emacs distribution.\r
137 +      (goto-char (point-min))\r
138 +      (while (not (eobp))\r
139 +       (setq lines (cons (buffer-substring-no-properties\r
140 +                          (line-beginning-position)\r
141 +                          (line-end-position))\r
142 +                         lines))\r
143 +       (forward-line 1))\r
144 +      (message "lines %s" lines))\r
145 +    (kill-buffer (process-buffer proc))\r
146 +    (funcall callback (nreverse lines))))\r
147 +\r
148 +(defun notmuch-company-address-external (arg)\r
149 +  (cons :async\r
150 +       (lambda (callback)\r
151 +         (let* ((buf (generate-new-buffer " *notmuch-external-address*"))\r
152 +                (proc (start-process "notmuch-external-address" buf\r
153 +                                     notmuch-address-command arg)))\r
154 +           (set-process-sentinel proc (apply-partially\r
155 +                                       'notmuch-company-external-sentinel\r
156 +                                       callback))))))\r
157 +\r
158 +(defun notmuch-company-address (arg)\r
159 +  (if (eq notmuch-address-command 'internal)\r
160 +      (notmuch-company-address-internal arg)\r
161 +    (notmuch-company-address-external arg)))\r
162 +\r
163  ;;;###autoload\r
164  (defun notmuch-company (command &optional arg &rest _ignore)\r
165    "`company-mode' completion back-end for `notmuch'."\r
166 @@ -62,21 +111,7 @@ (defun notmuch-company (command &optional arg &rest _ignore)\r
167                    (looking-back (concat notmuch-address-completion-headers-regexp ".*")\r
168                                  (line-beginning-position))\r
169                    (setq notmuch-company-last-prefix (company-grab "[:,][ \t]*\\(.*\\)" 1 (point-at-bol)))))\r
170 -      (candidates (cond\r
171 -                  (notmuch-address-full-harvest-finished\r
172 -                   ;; Update harvested addressed from time to time\r
173 -                   (notmuch-address-harvest-trigger)\r
174 -                   (notmuch-address-matching arg))\r
175 -                  (t\r
176 -                   (cons :async\r
177 -                         (lambda (callback)\r
178 -                           ;; First run quick asynchronous harvest based on what the user entered so far\r
179 -                           (notmuch-address-harvest\r
180 -                            (format "to:%s*" arg) nil\r
181 -                            (lambda (_proc _event)\r
182 -                              (funcall callback (notmuch-address-matching arg))\r
183 -                              ;; Then start the (potentially long-running) full asynchronous harvest if necessary\r
184 -                              (notmuch-address-harvest-trigger))))))))\r
185 +      (candidates (notmuch-company-address arg))\r
186        (match (if (string-match notmuch-company-last-prefix arg)\r
187                  (match-end 0)\r
188                0))\r
189 -- \r
190 2.1.4\r
191 \r