Dear All,
When writing an email, and selecting the addresses, I like the automatic completion popup that company can provide. When writing the text of the email, I don't want the automatic completion popup (but I want to be able to trigger company manually).
I think the simplest way to achieve this would be to set "company-idle-delay" to nil when writing the email itself, but keep it to, say, 0.2, when adding recipients in the To/CC/BCC fields. I do not know how to do this properly, and my googling around has found nothing that would work.
Option 1: This (ugly kludge?) kind of works:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'mu4e-compose-mode-hook
(lambda() (setq-local company-idle-delay 0.2)))
(defun rdu-goto-message ()
"Goto message body, but first set company-idle-delay to 0"
(interactive)
(setq-local company-idle-delay nil)
(call-interactively 'message-goto-body)
)
(define-key mu4e-compose-mode-map (kbd "C-c C-b") 'rdu-goto-message)
(defun rdu/on-reply-set-company-idle-nil (&optional WIDE)
(setq-local company-idle-delay nil)
)
(advice-add 'mu4e-compose-wide-reply :before
#'rdu/on-reply-set-company-idle-nil)
(advice-add 'mu4e-compose-reply :before
#'rdu/on-reply-set-company-idle-nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
But there are several things I dislike:
1. company-idle-delay is still 0.2 when I reply and wide-reply. For reasons I do not understand, the advice I've tried adding does not seem to do anything.
2. Remapping C-c C-b to my function seems like an inelegant brute force approach to me (though I am an elisp newby, so elegance might not be something I can yet assess :) ).
3. If, after C-c C-b, I want to add a recipient, company automatic completion is now disabled (though this is not a big deal).
Option 2: hooks. I don't know how to make it work
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'message-header-hook
(lambda() (setq-local company-idle-delay 0.2)))
(add-hook 'mu4e-compose-mode-hook
(lambda() (setq-local company-idle-delay nil)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
But this does not work, because I think the mu4e-compose-mode-hook is run last on all of the buffer.
Option 3: advice message-goto-body:
I've tried adding advice to message-goto-body to set company-idle-delay to nil, as follows:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Default, so it is 0.2 in To/Cc/BCC
(add-hook 'mu4e-compose-mode-hook
(lambda() (setq-local company-idle-delay 0.2)))
;; When we move to the body, set company-idle-delay to nil
(defun rdu/after-message-goto-body (&optional interactive)
(setq-local company-idle-delay nil)
)
(advice-add 'message-goto-body :after #'rdu/after-message-goto-body)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
But that does not work. First, it just doesn't work: for reasons I do not understand, even before I move to the message body, adding the advice to message-goto-body sets the variable to nil in To/CC/BCC. And even if this worked, this would disable automatic completion when doing reply and moving back to the To/CC/BCC (though this is not such a big deal).
What is the proper way to do this?
Thanks,
R.
--
Ramon Diaz-Uriarte
Department of Biochemistry, Lab B-31
Facultad de Medicina
Universidad Autónoma de Madrid
Arzobispo Morcillo, 4
28029 Madrid
Spain
Phone:
+34-91-497-2412
Email:
rdi...@gmail.com
r.d...@uam.es
ramon...@iib.uam.es
https://ligarto.org/rdiaz