Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 9a / fb650eda17af84d985cce3c2ecbb3f5968202e
1 Return-Path: <bremner@tethera.net>\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 C69766DE140C\r
6  for <notmuch@notmuchmail.org>; Fri, 23 Oct 2015 17:21:56 -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.099\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.099 tagged_above=-999 required=5 tests=[AWL=0.099]\r
12  autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id 6q_gOwBL0SSy for <notmuch@notmuchmail.org>;\r
16  Fri, 23 Oct 2015 17:21:53 -0700 (PDT)\r
17 Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224])\r
18  by arlo.cworth.org (Postfix) with ESMTPS id A8DDE6DE13A6\r
19  for <notmuch@notmuchmail.org>; Fri, 23 Oct 2015 17:21:53 -0700 (PDT)\r
20 Received: from remotemail by gitolite.debian.net with local (Exim 4.80)\r
21  (envelope-from <bremner@tethera.net>)\r
22  id 1ZpmaH-0006n3-OQ; Sat, 24 Oct 2015 00:21:21 +0000\r
23 Received: (nullmailer pid 26055 invoked by uid 1000); Sat, 24 Oct 2015\r
24  00:20:41 -0000\r
25 From: David Bremner <david@tethera.net>\r
26 To: notmuch@notmuchmail.org\r
27 Subject: [Patch v5 3/3] Emacs: Add address completion based on company-mode\r
28 Date: Fri, 23 Oct 2015 21:20:37 -0300\r
29 Message-Id: <1445646037-25994-4-git-send-email-david@tethera.net>\r
30 X-Mailer: git-send-email 2.6.1\r
31 In-Reply-To: <1445646037-25994-1-git-send-email-david@tethera.net>\r
32 References: <1445646037-25994-1-git-send-email-david@tethera.net>\r
33 X-BeenThere: notmuch@notmuchmail.org\r
34 X-Mailman-Version: 2.1.20\r
35 Precedence: list\r
36 List-Id: "Use and development of the notmuch mail system."\r
37  <notmuch.notmuchmail.org>\r
38 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
39  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
41 List-Post: <mailto:notmuch@notmuchmail.org>\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
43 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
44  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
45 X-List-Received-Date: Sat, 24 Oct 2015 00:21:56 -0000\r
46 \r
47 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
48 \r
49 With this patch, address completion candidates are shown automatically\r
50 after short typing delay in a nice popup box. This requires company-mode\r
51 to be installed and it works only on Emacs >= 24. The completion is\r
52 based entirely on the asynchronous address harvesting from\r
53 notmuch-address.el so the GUI is theoretically not blocked for long\r
54 time.\r
55 \r
56 The completion works similarly as the TAB-initiated completion from\r
57 notmuch-address.el, i.e. quick harvest based on user input is executed\r
58 first and only after full harvesting is finished, in-memory cached data\r
59 is used.\r
60 \r
61 The notmuch-company.el is excluded from byte-compilation, because it\r
62 would require every person who want to compile notmuch to have\r
63 company-mode installed.\r
64 ---\r
65  emacs/Makefile.local     |  6 +++-\r
66  emacs/notmuch-company.el | 81 ++++++++++++++++++++++++++++++++++++++++++++++++\r
67  2 files changed, 86 insertions(+), 1 deletion(-)\r
68  create mode 100644 emacs/notmuch-company.el\r
69 \r
70 diff --git a/emacs/Makefile.local b/emacs/Makefile.local\r
71 index 1109cfa..6c93e73 100644\r
72 --- a/emacs/Makefile.local\r
73 +++ b/emacs/Makefile.local\r
74 @@ -20,6 +20,7 @@ emacs_sources := \\r
75         $(dir)/notmuch-print.el \\r
76         $(dir)/notmuch-version.el \\r
77         $(dir)/notmuch-jump.el \\r
78 +       $(dir)/notmuch-company.el\r
79  \r
80  $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp\r
81  $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl\r
82 @@ -30,7 +31,10 @@ $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl\r
83  emacs_images := \\r
84         $(srcdir)/$(dir)/notmuch-logo.png\r
85  \r
86 -emacs_bytecode = $(emacs_sources:.el=.elc)\r
87 +# Do not try to install files that are not byte-compiled.\r
88 +emacs_no_byte_compile := $(dir)/notmuch-company.el\r
89 +\r
90 +emacs_bytecode = $(patsubst %.el,%.elc,$(filter-out $(emacs_no_byte_compile),$(emacs_sources)))\r
91  \r
92  # Because of defmacro's and defsubst's, we have to account for load\r
93  # dependencies between Elisp files when byte compiling.  Otherwise,\r
94 diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el\r
95 new file mode 100644\r
96 index 0000000..f34aec4\r
97 --- /dev/null\r
98 +++ b/emacs/notmuch-company.el\r
99 @@ -0,0 +1,81 @@\r
100 +;; notmuch-company.el --- Mail address completion for notmuch via company-mode  -*- no-byte-compile: t; lexical-binding: t -*-\r
101 +\r
102 +\r
103 +;; Authors: Trevor Jim <tjim@mac.com>\r
104 +;;         Michal Sojka <sojkam1@fel.cvut.cz>\r
105 +;;\r
106 +;; Keywords: mail, completion\r
107 +\r
108 +;; This program is free software; you can redistribute it and/or modify\r
109 +;; it under the terms of the GNU General Public License as published by\r
110 +;; the Free Software Foundation, either version 3 of the License, or\r
111 +;; (at your option) any later version.\r
112 +\r
113 +;; This program is distributed in the hope that it will be useful,\r
114 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of\r
115 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
116 +;; GNU General Public License for more details.\r
117 +\r
118 +;; You should have received a copy of the GNU General Public License\r
119 +;; along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
120 +\r
121 +;;; Commentary:\r
122 +\r
123 +;; To enable this, install company mode (https://company-mode.github.io/)\r
124 +;; and add\r
125 +;;\r
126 +;;     (require 'notmuch-company)\r
127 +;;\r
128 +;; to your .emacs.\r
129 +;;\r
130 +;; NB company-minimum-prefix-length defaults to 3 so you don't get\r
131 +;; completion unless you type 3 characters\r
132 +\r
133 +;;; Code:\r
134 +\r
135 +(require 'company)\r
136 +(require 'message)\r
137 +(require 'notmuch-address)\r
138 +(require 'cl-lib)\r
139 +\r
140 +(defvar-local notmuch-company-last-prefix nil)\r
141 +\r
142 +;;;###autoload\r
143 +(defun notmuch-company (command &optional arg &rest ignore)\r
144 +  "`company-mode' completion back-end for `notmuch'."\r
145 +  (interactive (list 'interactive))\r
146 +  (let ((case-fold-search t)\r
147 +       (completion-ignore-case t))\r
148 +    (cl-case command\r
149 +      (interactive (company-begin-backend 'notmuch-company))\r
150 +      (prefix (and (derived-mode-p 'message-mode)\r
151 +                  (looking-back "^\\(To\\|Cc\\|Bcc\\):.*"\r
152 +                                (line-beginning-position))\r
153 +                  (setq notmuch-company-last-prefix (company-grab "[:,][ \t]*\\(.*\\)" 1 (point-at-bol)))))\r
154 +      (candidates (cond\r
155 +                  (notmuch-address-full-harvest-finished\r
156 +                   ;; Update harvested addressed from time to time\r
157 +                   (notmuch-address-harvest-trigger)\r
158 +                   (notmuch-address-matching arg))\r
159 +                  (t\r
160 +                   (cons :async\r
161 +                         (lambda (callback)\r
162 +                           ;; First run quick asynchronous harvest based on what the user entered so far\r
163 +                           (notmuch-address-harvest\r
164 +                            (format "to:%s*" arg) nil\r
165 +                            (lambda (proc event)\r
166 +                              (funcall callback (notmuch-address-matching arg))\r
167 +                              ;; Then (re)start potentially long-running full asynchronous harvesting\r
168 +                              (notmuch-address-harvest-trigger))))))))\r
169 +      (match (if (string-match notmuch-company-last-prefix arg)\r
170 +                (match-end 0)\r
171 +              0))\r
172 +      (no-cache t))))\r
173 +\r
174 +;;;###autoload\r
175 +(add-hook 'notmuch-message-mode-hook '(lambda ()\r
176 +                                       (company-mode)\r
177 +                                       (make-local-variable 'company-backends)\r
178 +                                       (setq company-backends '(notmuch-company))))\r
179 +\r
180 +(provide 'notmuch-company)\r
181 -- \r
182 2.6.1\r
183 \r