Is there a way to auto-complete email addresses in the mu4e compose window using Ido or Helm rather than the standard *Completions* buffer?
2 Answers
The variable mu4e~contacts-for-completion
stores a list of contacts that mu4e
knows about. The contacts are conveniently stored as "name <email>"
strings, which is the same thing you want to insert.
Here's an example function that uses the variable together with ido
to select and insert a contact:
(defun select-and-insert-contact ()
(interactive)
(insert (ido-completing-read "Contact: " mu4e~contacts-for-completion)))
Here's a more elaborate version which will use the partial contact before point (if any) as the initial input when completing. (Most of the code is directly from mu4e~compose-complete-contact
).
(defun select-and-insert-contact (&optional start)
(interactive)
(let ((mail-abbrev-mode-regexp mu4e~compose-address-fields-regexp)
(eoh ;; end-of-headers
(save-excursion
(goto-char (point-min))
(search-forward-regexp mail-header-separator nil t))))
(when (and eoh (> eoh (point)) (mail-abbrev-in-expansion-header-p))
(let* ((end (point))
(start
(or start
(save-excursion
(re-search-backward "\\(\\`\\|[\n:,]\\)[ \t]*")
(goto-char (match-end 0))
(point))))
(contact
(ido-completing-read "Contact: "
mu4e~contacts-for-completion
nil
nil
(buffer-substring-no-properties start end))))
(unless (equal contact "")
(kill-region start end)
(insert contact))))))

- 382
- 1
- 5
Disclaimer: I don't use mu4e anymore, so this is not a copy/paste or tested answer.
The function mu4e~compose-complete-contact
seems to provide a list of contacts available for completion :
https://github.com/djcb/mu/blob/master/mu4e/mu4e-compose.el#L236
You could just feed the list to ido-completing-read
.
(ido-completing-read "Complete contact: " (mu4e~compose-complete-contact)))))

- 634
- 5
- 6