Next: , Previous: , Up: Editor view   [Contents]

6.4 Compose hooks

If you want to change some setting, or execute some custom action before message composition starts, you can define a hook function. mu4e offers two hooks:

Let’s look at some examples. First, suppose we want to set the From:-address for a reply message based on the receiver of the original:

;; 1) messages to should be replied with
;; 2) messages to should be replied with
;; 3) all other mail should use
(add-hook 'mu4e-compose-pre-hook
  (defun my-set-from-address ()
    "Set the From address based on the To address of the original."
    (let ((msg mu4e-compose-parent-message)) ;; msg is shorter...
      (when msg
        (setq user-mail-address
            ((mu4e-message-contact-field-matches msg :to "")
            ((mu4e-message-contact-field-matches msg :to "")
            (t "")))))))

Second, as mentioned, mu4e-compose-mode-hook is especially useful for editing-related settings. For example:

(add-hook 'mu4e-compose-mode-hook
  (defun my-do-compose-stuff ()
    "My settings for message composition."
    (set-fill-column 72)

This hook is also useful for adding headers or changing headers, since the message is fully formed when this hook runs. For example, to add a Bcc:-header, you could add something like the following, using message-add-header from message-mode.

(add-hook 'mu4e-compose-mode-hook
  (defun my-add-bcc ()
    "Add a Bcc: header."
    (save-excursion (message-add-header "Bcc:\n"))))

For a more general discussion about extending mu4e, see Extending mu4e.

Next: , Previous: , Up: Editor view   [Contents]