X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=emacs%2Fnotmuch-company.el;h=ac998f9b4496d39f157923846329e9f301e32848;hp=0619c7ef739951c6618b67c47c565bc457b754dd;hb=11ac932a4503872c19987b843d58513c4b9ef76f;hpb=92d8eae8f182e4eebc87d76f8d4f37e6c018883a diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el index 0619c7ef..ac998f9b 100644 --- a/emacs/notmuch-company.el +++ b/emacs/notmuch-company.el @@ -27,7 +27,9 @@ ;;; Code: -(eval-when-compile (require 'cl)) +(eval-when-compile (require 'cl-lib)) + +(require 'notmuch-lib) (defvar notmuch-company-last-prefix nil) (make-variable-buffer-local 'notmuch-company-last-prefix) @@ -36,18 +38,26 @@ (declare-function company-mode "company") (declare-function company-manual-begin "company") (defvar company-backends) +(defvar company-idle-delay) (declare-function notmuch-address-harvest "notmuch-address") (declare-function notmuch-address-harvest-trigger "notmuch-address") (declare-function notmuch-address-matching "notmuch-address") -(defvar notmuch-address-full-harvest-finished) +(declare-function notmuch-address--harvest-ready "notmuch-address") (defvar notmuch-address-completion-headers-regexp) +(defvar notmuch-address-command) ;;;###autoload (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) @@ -56,14 +66,14 @@ (require 'company) (let ((case-fold-search t) (completion-ignore-case t)) - (case command + (cl-case command (interactive (company-begin-backend 'notmuch-company)) (prefix (and (derived-mode-p 'message-mode) (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 - (notmuch-address-full-harvest-finished + ((notmuch-address--harvest-ready) ;; Update harvested addressed from time to time (notmuch-address-harvest-trigger) (notmuch-address-matching arg)) @@ -72,7 +82,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 @@ -80,6 +90,7 @@ (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))))