X-Git-Url: http://rtime.felk.cvut.cz/gitweb/notmuch.git/blobdiff_plain/89f78d38c1f7c9416e5bd9521dd694bb4f90572f..c13ff402c42143941010cd03bd57658d42f0df7d:/emacs/notmuch-address.el diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el index 498ef8ae..8b79d340 100644 --- a/emacs/notmuch-address.el +++ b/emacs/notmuch-address.el @@ -1,4 +1,4 @@ -;; notmuch-address.el --- address completion with notmuch +;;; notmuch-address.el --- address completion with notmuch ;; ;; Copyright © David Edmondson ;; @@ -19,10 +19,14 @@ ;; ;; Authors: David Edmondson +;;; Code: + (require 'message) (require 'notmuch-parser) (require 'notmuch-lib) +(require 'notmuch-company) ;; +(declare-function company-manual-begin "company") (defcustom notmuch-address-command 'internal "The command which generates possible addresses. It must take a @@ -72,9 +76,21 @@ finished") (defun notmuch-address-message-insinuate () (message "calling notmuch-address-message-insinuate is no longer needed")) +(defcustom notmuch-address-use-company t + "If available, use company mode for address completion" + :type 'boolean + :group 'notmuch-send) + (defun notmuch-address-setup () - (let ((pair (cons notmuch-address-completion-headers-regexp - #'notmuch-address-expand-name))) + (let* ((use-company (and notmuch-address-use-company + (eq notmuch-address-command 'internal) + (require 'company nil t))) + (pair (cons notmuch-address-completion-headers-regexp + (if use-company + #'company-manual-begin + #'notmuch-address-expand-name)))) + (when use-company + (notmuch-company-setup)) (unless (memq pair message-completion-alist) (setq message-completion-alist (push pair message-completion-alist))))) @@ -233,4 +249,25 @@ called when harvesting finishes." ;; +(defun notmuch-address-from-minibuffer (prompt) + (if (not notmuch-address-command) + (read-string prompt) + (let ((rmap (copy-keymap minibuffer-local-map)) + (omap minibuffer-local-map)) + ;; Configure TAB to start completion when executing read-string. + ;; "Original" minibuffer keymap is restored just before calling + ;; notmuch-address-expand-name as it may also use minibuffer-local-map + ;; (completing-read probably does not but if something else is used there). + (define-key rmap (kbd "TAB") (lambda () + (interactive) + (let ((enable-recursive-minibuffers t) + (minibuffer-local-map omap)) + (notmuch-address-expand-name)))) + (let ((minibuffer-local-map rmap)) + (read-string prompt))))) + +;; + (provide 'notmuch-address) + +;;; notmuch-address.el ends here