X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=emacs%2Fnotmuch-address.el;h=2eaca7958bb2736de3e21abe0e04a5946f95ab96;hp=c6f5f11136093c8d857e236da4525d414cdf8225;hb=df9736f20be0aa4db96e3ceaccb4f614ecbd4a9b;hpb=2cf0ef3998a75a8e5bcd83f0a286d9660f1bdb0e diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el index c6f5f111..2eaca795 100644 --- a/emacs/notmuch-address.el +++ b/emacs/notmuch-address.el @@ -37,7 +37,11 @@ (defvar notmuch-address-full-harvest-finished nil "t indicates that full completion address harvesting has been -finished") +finished. Use notmuch-address--harvest-ready to access.") + +(defun notmuch-address--harvest-ready () + "Return t if there is a full address hash available." + notmuch-address-full-harvest-finished) (defcustom notmuch-address-command 'internal "Determines how address completion candidates are generated. @@ -98,6 +102,17 @@ to know how address selection is made by default." :group 'notmuch-send :group 'notmuch-external) +(defcustom notmuch-address-post-completion-functions nil + "Functions called after completing address. + +The completed address is passed as an argument to each function. +Note that this hook will be invoked for completion in headers +matching `notmuch-address-completion-headers-regexp'. +" + :type 'hook + :group 'notmuch-address + :group 'notmuch-hooks) + (defun notmuch-address-selection-function (prompt collection initial-input) "Call (`completing-read' PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)" @@ -118,17 +133,30 @@ to know how address selection is made by default." :group 'notmuch-send) (defun notmuch-address-setup () - (let* ((use-company (and notmuch-address-use-company - (eq notmuch-address-command 'internal) + (let* ((setup-company (and notmuch-address-use-company (require 'company nil t))) (pair (cons notmuch-address-completion-headers-regexp #'notmuch-address-expand-name))) - (when use-company + (when setup-company (notmuch-company-setup)) (unless (memq pair message-completion-alist) (setq message-completion-alist (push pair message-completion-alist))))) +(defun notmuch-address-toggle-internal-completion () + "Toggle use of internal completion for current buffer. + +This overrides the global setting for address completion and +toggles the setting in this buffer." + (interactive) + (if (local-variable-p 'notmuch-address-command) + (kill-local-variable 'notmuch-address-command) + (notmuch-setq-local notmuch-address-command 'internal)) + (if (boundp 'company-idle-delay) + (if (local-variable-p 'company-idle-delay) + (kill-local-variable 'company-idle-delay) + (notmuch-setq-local company-idle-delay nil)))) + (defun notmuch-address-matching (substring) "Returns a list of completion candidates matching SUBSTRING. The candidates are taken from `notmuch-address-completions'." @@ -146,7 +174,7 @@ elisp-based implementation or older implementation requiring external commands." (cond ((eq notmuch-address-command 'internal) - (when (not notmuch-address-full-harvest-finished) + (unless (notmuch-address--harvest-ready) ;; First, run quick synchronous harvest based on what the user ;; entered so far (notmuch-address-harvest original t)) @@ -181,12 +209,20 @@ external commands." (t (funcall notmuch-address-selection-function (format "Address (%s matches): " num-options) - (cdr options) (car options)))))) + ;; We put the first match as the initial + ;; input; we put all the matches as + ;; possible completions, moving the + ;; first match to the end of the list + ;; makes cursor up/down in the list work + ;; better. + (append (cdr options) (list (car options))) + (car options)))))) (if chosen (progn (push chosen notmuch-address-history) (delete-region beg end) - (insert chosen)) + (insert chosen) + (run-hook-with-args 'notmuch-address-post-completion-functions chosen)) (message "No matches.") (ding)))) (t nil)))