Is there a way to auto-complete email addresses in the mu4e compose window using Ido or Helm rather than the standard *Completions* buffer?


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 ()
  (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)
  (let ((mail-abbrev-mode-regexp mu4e~compose-address-fields-regexp)
        (eoh ;; end-of-headers
           (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))
              (or start
                    (re-search-backward "\\(\\`\\|[\n:,]\\)[ \t]*")
                    (goto-char (match-end 0))
              (ido-completing-read "Contact: "
                                   (buffer-substring-no-properties start end))))
        (unless (equal contact "")
          (kill-region start end)
          (insert contact))))))

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)))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.