[PATCH] address completion tweaks
Mark Walters
markwalters1009 at gmail.com
Sun Oct 25 06:02:11 PDT 2015
If the user has company installed and notmuch is configured to use it,
then use it for all the completions. In particular, pressing tab now
forces company to run immediately.
In addition this patch fixes a semi-bug where address completion was
used for more headers than company mode was. With the change above
this became important. Thus make company mode work for all headers
that address completion does.
---
I think this is an improvement: without pressing tab quickly brings up
the normal mini-buffer completion mode, but waiting a second means
company has started and then tab doesn't bring up the mini-buffer.
The change in notmuch-mua is just so that company-setup runs before we
setup the message-completion-alist.
Best wishes
Mark
emacs/notmuch-address.el | 7 ++++---
emacs/notmuch-company.el | 5 +++--
emacs/notmuch-mua.el | 10 +++++-----
3 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 228135e..0a73ddf 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -64,9 +64,11 @@ (defun notmuch-address-selection-function (prompt collection initial-input)
(completing-read
prompt collection nil nil initial-input 'notmuch-address-history))
+(defvar notmuch-address-completion-headers-regexp
+ "^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):")
+
(defvar notmuch-address-message-alist-member
- '("^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
- . notmuch-address-expand-name))
+ (cons notmuch-address-completion-headers-regexp 'notmuch-address-expand-name))
(defvar notmuch-address-history nil)
@@ -221,7 +223,6 @@ (defun notmuch-address-harvest-trigger ()
(if (string= event "finished\n")
(setq notmuch-address-full-harvest-finished t)
(setq notmuch-address-last-harvest 0)))))))
-
;;
(provide 'notmuch-address)
diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
index 9e57914..3157ed7 100644
--- a/emacs/notmuch-company.el
+++ b/emacs/notmuch-company.el
@@ -41,6 +41,8 @@ (defvar company-backends)
;;;###autoload
(defun notmuch-company-setup ()
(company-mode)
+ (setq notmuch-address-message-alist-member
+ (cons notmuch-address-completion-headers-regexp 'company-manual-begin))
(make-local-variable 'company-backends)
(setq company-backends '(notmuch-company)))
@@ -54,7 +56,7 @@ (defun notmuch-company (command &optional arg &rest _ignore)
(case command
(interactive (company-begin-backend 'notmuch-company))
(prefix (and (derived-mode-p 'message-mode)
- (looking-back "^\\(To\\|Cc\\|Bcc\\):.*"
+ (looking-back (concat notmuch-address-completion-headers-regexp ".*")
(line-beginning-position))
(setq notmuch-company-last-prefix (company-grab "[:,][ \t]*\\(.*\\)" 1 (point-at-bol)))))
(candidates (cond
@@ -77,5 +79,4 @@ (defun notmuch-company (command &optional arg &rest _ignore)
0))
(no-cache t))))
-
(provide 'notmuch-company)
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 63fc8db..8cbf38c 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -276,13 +276,13 @@ (defcustom notmuch-message-use-company t
(define-derived-mode notmuch-message-mode message-mode "Message[Notmuch]"
"Notmuch message composition mode. Mostly like `message-mode'"
(when notmuch-address-command
+ (when (and notmuch-message-use-company
+ (eq notmuch-address-command 'internal)
+ (require 'company nil t))
+ (notmuch-company-setup))
(unless (memq notmuch-address-message-alist-member message-completion-alist)
(setq message-completion-alist
- (push notmuch-address-message-alist-member message-completion-alist))))
- (when (and notmuch-message-use-company
- (eq notmuch-address-command 'internal)
- (require 'company nil t))
- (notmuch-company-setup)))
+ (push notmuch-address-message-alist-member message-completion-alist)))))
(define-key notmuch-message-mode-map (kbd "C-c C-c") #'notmuch-mua-send-and-exit)
(define-key notmuch-message-mode-map (kbd "C-c C-s") #'notmuch-mua-send)
--
2.1.4
More information about the notmuch
mailing list