1 Return-Path: <sojkam1@fel.cvut.cz>
\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 05E28431FBC
\r
6 for <notmuch@notmuchmail.org>; Fri, 19 Sep 2014 11:17:13 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3] 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 32pbe+8VFH7Y for <notmuch@notmuchmail.org>;
\r
16 Fri, 19 Sep 2014 11:17:07 -0700 (PDT)
\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 6F377431FBD
\r
19 for <notmuch@notmuchmail.org>; Fri, 19 Sep 2014 11:17:06 -0700 (PDT)
\r
20 Received: from localhost (unknown [192.168.200.7])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id 117CA19F33E7;
\r
22 Fri, 19 Sep 2014 20:17:01 +0200 (CEST)
\r
23 X-Virus-Scanned: IMAP STYX AMAVIS
\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])
\r
25 by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,
\r
27 with ESMTP id xD7QTUEXTrY2; Fri, 19 Sep 2014 20:16:57 +0200 (CEST)
\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])
\r
29 by max.feld.cvut.cz (Postfix) with ESMTP id C68B819F33B8;
\r
30 Fri, 19 Sep 2014 20:16:56 +0200 (CEST)
\r
31 Received: from wsh by steelpick.2x.cz with local (Exim 4.84)
\r
32 (envelope-from <sojkam1@fel.cvut.cz>)
\r
33 id 1XV2jo-0005iD-0U; Fri, 19 Sep 2014 20:16:56 +0200
\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
35 To: notmuch@notmuchmail.org
\r
36 Subject: [PATCH v4 3/3] Emacs: Add address completion based on company-mode
\r
37 Date: Fri, 19 Sep 2014 20:16:42 +0200
\r
38 Message-Id: <1411150602-21892-4-git-send-email-sojkam1@fel.cvut.cz>
\r
39 X-Mailer: git-send-email 2.1.0
\r
40 In-Reply-To: <1411150602-21892-1-git-send-email-sojkam1@fel.cvut.cz>
\r
41 References: <1411150602-21892-1-git-send-email-sojkam1@fel.cvut.cz>
\r
42 X-BeenThere: notmuch@notmuchmail.org
\r
43 X-Mailman-Version: 2.1.13
\r
45 List-Id: "Use and development of the notmuch mail system."
\r
46 <notmuch.notmuchmail.org>
\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
50 List-Post: <mailto:notmuch@notmuchmail.org>
\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
53 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
54 X-List-Received-Date: Fri, 19 Sep 2014 18:17:13 -0000
\r
56 With this patch, address completion candidates are shown automatically
\r
57 after short typing delay in a nice popup box. This requires company-mode
\r
58 to be installed and it works only on Emacs >= 24. The completion is
\r
59 based entirely on the asynchronous address harvesting from
\r
60 notmuch-address.el so the GUI is theoretically not blocked for long
\r
63 The completion works similarly as the TAB-initiated completion from
\r
64 notmuch-address.el, i.e. quick harvest based on user input is executed
\r
65 first and only after full harvesting is finished, in-memory cached data
\r
68 The notmuch-company.el is excluded from byte-compilation, because it
\r
69 would require every person who want to compile notmuch to have
\r
70 company-mode installed.
\r
72 emacs/Makefile.local | 6 +++-
\r
73 emacs/notmuch-company.el | 81 ++++++++++++++++++++++++++++++++++++++++++++++++
\r
74 2 files changed, 86 insertions(+), 1 deletion(-)
\r
75 create mode 100644 emacs/notmuch-company.el
\r
77 diff --git a/emacs/Makefile.local b/emacs/Makefile.local
\r
78 index 1109cfa..6c93e73 100644
\r
79 --- a/emacs/Makefile.local
\r
80 +++ b/emacs/Makefile.local
\r
81 @@ -20,6 +20,7 @@ emacs_sources := \
\r
82 $(dir)/notmuch-print.el \
\r
83 $(dir)/notmuch-version.el \
\r
84 $(dir)/notmuch-jump.el \
\r
85 + $(dir)/notmuch-company.el
\r
87 $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp
\r
88 $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl
\r
89 @@ -30,7 +31,10 @@ $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl
\r
91 $(srcdir)/$(dir)/notmuch-logo.png
\r
93 -emacs_bytecode = $(emacs_sources:.el=.elc)
\r
94 +# Do not try to install files that are not byte-compiled.
\r
95 +emacs_no_byte_compile := $(dir)/notmuch-company.el
\r
97 +emacs_bytecode = $(patsubst %.el,%.elc,$(filter-out $(emacs_no_byte_compile),$(emacs_sources)))
\r
99 # Because of defmacro's and defsubst's, we have to account for load
\r
100 # dependencies between Elisp files when byte compiling. Otherwise,
\r
101 diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
\r
102 new file mode 100644
\r
103 index 0000000..0d4fe49
\r
105 +++ b/emacs/notmuch-company.el
\r
107 +;; notmuch-company.el --- Mail address completion for notmuch via company-mode -*- no-byte-compile: t; lexical-binding: t -*-
\r
110 +;; Authors: Trevor Jim <tjim@mac.com>
\r
111 +;; Michal Sojka <sojkam1@fel.cvut.cz>
\r
113 +;; Keywords: mail, completion
\r
115 +;; This program is free software; you can redistribute it and/or modify
\r
116 +;; it under the terms of the GNU General Public License as published by
\r
117 +;; the Free Software Foundation, either version 3 of the License, or
\r
118 +;; (at your option) any later version.
\r
120 +;; This program is distributed in the hope that it will be useful,
\r
121 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
122 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
123 +;; GNU General Public License for more details.
\r
125 +;; You should have received a copy of the GNU General Public License
\r
126 +;; along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
130 +;; To enable this, install company mode (https://company-mode.github.io/)
\r
133 +;; (require 'notmuch-company)
\r
135 +;; to your .emacs.
\r
137 +;; NB company-minimum-prefix-length defaults to 3 so you don't get
\r
138 +;; completion unless you type 3 characters
\r
142 +(require 'company)
\r
143 +(require 'message)
\r
144 +(require 'notmuch-address)
\r
147 +(defvar-local notmuch-company-last-prefix nil)
\r
150 +(defun notmuch-company (command &optional arg &rest ignore)
\r
151 + "`company-mode' completion back-end for `notmuch'."
\r
152 + (interactive (list 'interactive))
\r
153 + (let ((case-fold-search t)
\r
154 + (completion-ignore-case t))
\r
156 + (interactive (company-begin-backend 'notmuch-company))
\r
157 + (prefix (and (eq major-mode 'message-mode)
\r
158 + (looking-back "^\\(To\\|Cc\\|Bcc\\):.*"
\r
159 + (line-beginning-position))
\r
160 + (setq notmuch-company-last-prefix (company-grab "[:,][ \t]*\\(.*\\)" 1 (point-at-bol)))))
\r
161 + (candidates (cond
\r
162 + (notmuch-address-full-harvest-finished
\r
163 + ;; Update harvested addressed from time to time
\r
164 + (notmuch-address-harvest-trigger)
\r
165 + (notmuch-address-matching arg))
\r
168 + (lambda (callback)
\r
169 + ;; First run quick asynchronous harvest based on what the user entered so far
\r
170 + (notmuch-address-harvest
\r
171 + (format "to:%s*" arg) nil
\r
172 + (lambda (proc event)
\r
173 + (funcall callback (notmuch-address-matching arg))
\r
174 + ;; Then (re)start potentially long-running full asynchronous harvesting
\r
175 + (notmuch-address-harvest-trigger))))))))
\r
176 + (match (if (string-match notmuch-company-last-prefix arg)
\r
182 +(add-hook 'message-mode-hook '(lambda ()
\r
184 + (make-local-variable 'company-backends)
\r
185 + (setq company-backends '(notmuch-company))))
\r
187 +(provide 'notmuch-company)
\r