]> git.notmuchmail.org Git - notmuch/blobdiff - emacs/notmuch-company.el
Merge branch 'release'
[notmuch] / emacs / notmuch-company.el
index add3161b790d6a490c7994ad0c1aad2632d803e8..ebe2c0846e1b2108f520023e3198970d7e43410e 100644 (file)
@@ -1,4 +1,4 @@
-;; notmuch-company.el --- Mail address completion for notmuch via company-mode  -*- lexical-binding: t -*-
+;;; notmuch-company.el --- Mail address completion for notmuch via company-mode  -*- lexical-binding: t -*-
 
 ;; Authors: Trevor Jim <tjim@mac.com>
 ;;         Michal Sojka <sojkam1@fel.cvut.cz>
@@ -16,7 +16,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -28,6 +28,7 @@
 ;;; Code:
 
 (eval-when-compile (require 'cl))
+(require 'notmuch-lib)
 
 (defvar notmuch-company-last-prefix nil)
 (make-variable-buffer-local 'notmuch-company-last-prefix)
 (defun notmuch-company-setup ()
   (company-mode)
   (make-local-variable 'company-backends)
-  (setq company-backends '(notmuch-company)))
+  (setq company-backends '(notmuch-company))
+  ;; Disable automatic company completion unless an internal
+  ;; completion method is configured. Company completion (using
+  ;; internal completion) can still be accessed via standard company
+  ;; functions, e.g., company-complete.
+  (unless (eq notmuch-address-command 'internal)
+    (notmuch-setq-local company-idle-delay nil)))
 
 ;;;###autoload
 (defun notmuch-company (command &optional arg &rest _ignore)
@@ -72,7 +79,7 @@
                          (lambda (callback)
                            ;; First run quick asynchronous harvest based on what the user entered so far
                            (notmuch-address-harvest
-                            (format "to:%s*" arg) nil
+                            arg nil
                             (lambda (_proc _event)
                               (funcall callback (notmuch-address-matching arg))
                               ;; Then start the (potentially long-running) full asynchronous harvest if necessary
       (match (if (string-match notmuch-company-last-prefix arg)
                 (match-end 0)
               0))
+      (post-completion (run-hook-with-args 'notmuch-address-post-completion-functions arg))
       (no-cache t))))
 
 
 (provide 'notmuch-company)
+
+;;; notmuch-company.el ends here