From: Mark Walters Date: Fri, 20 May 2016 20:13:03 +0000 (+0100) Subject: emacs: address: allow internal completion on an individual basis X-Git-Tag: 0.23_rc0~54 X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=commitdiff_plain;h=827c28a04effc58f29e751788690d2f4b434902d;hp=2cf0ef3998a75a8e5bcd83f0a286d9660f1bdb0e emacs: address: allow internal completion on an individual basis This commit makes two changes. The first allows the user to override an external completion method with the internal notmuch address based completion for an individual buffer. Secondly, if the user has company-mode enabled then it sets up company mode (based on internal completion) but disables the automatic timeout completion -- the user can still activate it in when desired with standard company commands such as company-complete. --- diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el index c6f5f111..10eaab19 100644 --- a/emacs/notmuch-address.el +++ b/emacs/notmuch-address.el @@ -118,17 +118,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) + (setq-local notmuch-address-command 'internal)) + (if (boundp 'company-idle-delay) + (if (local-variable-p 'company-idle-delay) + (kill-local-variable 'company-idle-delay) + (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'." diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el index 610e223d..168315ff 100644 --- a/emacs/notmuch-company.el +++ b/emacs/notmuch-company.el @@ -47,7 +47,13 @@ (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) + (setq-local company-idle-delay nil))) ;;;###autoload (defun notmuch-company (command &optional arg &rest _ignore)