--- /dev/null
+Return-Path: <sojkam1@fel.cvut.cz>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 05E28431FBC\r
+ for <notmuch@notmuchmail.org>; Fri, 19 Sep 2014 11:17:13 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 32pbe+8VFH7Y for <notmuch@notmuchmail.org>;\r
+ Fri, 19 Sep 2014 11:17:07 -0700 (PDT)\r
+Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
+ by olra.theworths.org (Postfix) with ESMTP id 6F377431FBD\r
+ for <notmuch@notmuchmail.org>; Fri, 19 Sep 2014 11:17:06 -0700 (PDT)\r
+Received: from localhost (unknown [192.168.200.7])\r
+ by max.feld.cvut.cz (Postfix) with ESMTP id 117CA19F33E7;\r
+ Fri, 19 Sep 2014 20:17:01 +0200 (CEST)\r
+X-Virus-Scanned: IMAP STYX AMAVIS\r
+Received: from max.feld.cvut.cz ([192.168.200.1])\r
+ by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,\r
+ port 10044)\r
+ with ESMTP id xD7QTUEXTrY2; Fri, 19 Sep 2014 20:16:57 +0200 (CEST)\r
+Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
+ by max.feld.cvut.cz (Postfix) with ESMTP id C68B819F33B8;\r
+ Fri, 19 Sep 2014 20:16:56 +0200 (CEST)\r
+Received: from wsh by steelpick.2x.cz with local (Exim 4.84)\r
+ (envelope-from <sojkam1@fel.cvut.cz>)\r
+ id 1XV2jo-0005iD-0U; Fri, 19 Sep 2014 20:16:56 +0200\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 3/3] Emacs: Add address completion based on company-mode\r
+Date: Fri, 19 Sep 2014 20:16:42 +0200\r
+Message-Id: <1411150602-21892-4-git-send-email-sojkam1@fel.cvut.cz>\r
+X-Mailer: git-send-email 2.1.0\r
+In-Reply-To: <1411150602-21892-1-git-send-email-sojkam1@fel.cvut.cz>\r
+References: <1411150602-21892-1-git-send-email-sojkam1@fel.cvut.cz>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 19 Sep 2014 18:17:13 -0000\r
+\r
+With this patch, address completion candidates are shown automatically\r
+after short typing delay in a nice popup box. This requires company-mode\r
+to be installed and it works only on Emacs >= 24. The completion is\r
+based entirely on the asynchronous address harvesting from\r
+notmuch-address.el so the GUI is theoretically not blocked for long\r
+time.\r
+\r
+The completion works similarly as the TAB-initiated completion from\r
+notmuch-address.el, i.e. quick harvest based on user input is executed\r
+first and only after full harvesting is finished, in-memory cached data\r
+is used.\r
+\r
+The notmuch-company.el is excluded from byte-compilation, because it\r
+would require every person who want to compile notmuch to have\r
+company-mode installed.\r
+---\r
+ emacs/Makefile.local | 6 +++-\r
+ emacs/notmuch-company.el | 81 ++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 2 files changed, 86 insertions(+), 1 deletion(-)\r
+ create mode 100644 emacs/notmuch-company.el\r
+\r
+diff --git a/emacs/Makefile.local b/emacs/Makefile.local\r
+index 1109cfa..6c93e73 100644\r
+--- a/emacs/Makefile.local\r
++++ b/emacs/Makefile.local\r
+@@ -20,6 +20,7 @@ emacs_sources := \\r
+ $(dir)/notmuch-print.el \\r
+ $(dir)/notmuch-version.el \\r
+ $(dir)/notmuch-jump.el \\r
++ $(dir)/notmuch-company.el\r
+ \r
+ $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp\r
+ $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl\r
+@@ -30,7 +31,10 @@ $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl\r
+ emacs_images := \\r
+ $(srcdir)/$(dir)/notmuch-logo.png\r
+ \r
+-emacs_bytecode = $(emacs_sources:.el=.elc)\r
++# Do not try to install files that are not byte-compiled.\r
++emacs_no_byte_compile := $(dir)/notmuch-company.el\r
++\r
++emacs_bytecode = $(patsubst %.el,%.elc,$(filter-out $(emacs_no_byte_compile),$(emacs_sources)))\r
+ \r
+ # Because of defmacro's and defsubst's, we have to account for load\r
+ # dependencies between Elisp files when byte compiling. Otherwise,\r
+diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el\r
+new file mode 100644\r
+index 0000000..0d4fe49\r
+--- /dev/null\r
++++ b/emacs/notmuch-company.el\r
+@@ -0,0 +1,81 @@\r
++;; notmuch-company.el --- Mail address completion for notmuch via company-mode -*- no-byte-compile: t; lexical-binding: t -*-\r
++\r
++\r
++;; Authors: Trevor Jim <tjim@mac.com>\r
++;; Michal Sojka <sojkam1@fel.cvut.cz>\r
++;;\r
++;; Keywords: mail, completion\r
++\r
++;; This program is free software; you can redistribute it and/or modify\r
++;; it under the terms of the GNU General Public License as published by\r
++;; the Free Software Foundation, either version 3 of the License, or\r
++;; (at your option) any later version.\r
++\r
++;; This program is distributed in the hope that it will be useful,\r
++;; but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
++;; GNU General Public License for more details.\r
++\r
++;; You should have received a copy of the GNU General Public License\r
++;; along with this program. If not, see <http://www.gnu.org/licenses/>.\r
++\r
++;;; Commentary:\r
++\r
++;; To enable this, install company mode (https://company-mode.github.io/)\r
++;; and add\r
++;;\r
++;; (require 'notmuch-company)\r
++;;\r
++;; to your .emacs.\r
++;;\r
++;; NB company-minimum-prefix-length defaults to 3 so you don't get\r
++;; completion unless you type 3 characters\r
++\r
++;;; Code:\r
++\r
++(require 'company)\r
++(require 'message)\r
++(require 'notmuch-address)\r
++(require 'cl-lib)\r
++\r
++(defvar-local notmuch-company-last-prefix nil)\r
++\r
++;;;###autoload\r
++(defun notmuch-company (command &optional arg &rest ignore)\r
++ "`company-mode' completion back-end for `notmuch'."\r
++ (interactive (list 'interactive))\r
++ (let ((case-fold-search t)\r
++ (completion-ignore-case t))\r
++ (cl-case command\r
++ (interactive (company-begin-backend 'notmuch-company))\r
++ (prefix (and (eq major-mode 'message-mode)\r
++ (looking-back "^\\(To\\|Cc\\|Bcc\\):.*"\r
++ (line-beginning-position))\r
++ (setq notmuch-company-last-prefix (company-grab "[:,][ \t]*\\(.*\\)" 1 (point-at-bol)))))\r
++ (candidates (cond\r
++ (notmuch-address-full-harvest-finished\r
++ ;; Update harvested addressed from time to time\r
++ (notmuch-address-harvest-trigger)\r
++ (notmuch-address-matching arg))\r
++ (t\r
++ (cons :async\r
++ (lambda (callback)\r
++ ;; First run quick asynchronous harvest based on what the user entered so far\r
++ (notmuch-address-harvest\r
++ (format "to:%s*" arg) nil\r
++ (lambda (proc event)\r
++ (funcall callback (notmuch-address-matching arg))\r
++ ;; Then (re)start potentially long-running full asynchronous harvesting\r
++ (notmuch-address-harvest-trigger))))))))\r
++ (match (if (string-match notmuch-company-last-prefix arg)\r
++ (match-end 0)\r
++ 0))\r
++ (no-cache t))))\r
++\r
++;;;###autoload\r
++(add-hook 'message-mode-hook '(lambda ()\r
++ (company-mode)\r
++ (make-local-variable 'company-backends)\r
++ (setq company-backends '(notmuch-company))))\r
++\r
++(provide 'notmuch-company)\r
+-- \r
+2.1.0\r
+\r