11.1 Defining actions

Defining a new custom action comes down to writing an elisp-function to do the work. Functions that operate on messages receive a msg parameter, which corresponds to the message at point. Something like:

(defun my-action-func (msg)
  "Describe my message function."
  ;; do stuff
  )

Functions that operate on attachments receive a msg parameter, which corresponds to the message at point, and an attachment-num, which is the number of the attachment as seen in the message view. An attachment function looks like:

(defun my-attachment-action-func (msg attachment-num)
  "Describe my attachment function."
  ;; do stuff
  )

After you have defined your function, you can add it to the list of actions17, either mu4e-headers-actions, mu4e-view-actions or mu4e-view-mime-part-actions. The format18 of each action is a cons-cell, (DESCRIPTION . VALUE); see below for some examples. If your shortcut is not also the first character of the description, simply prefix the description with that character.

Let’s look at some examples.


Footnotes

(17)

Instead of defining the functions separately, you can obviously also add a lambda-function directly to the list; however, separate functions are easier to change

(18)

Note, the format of the actions has changed since version 0.9.8.4, and you must change your configuration to use the new format; mu4e warns you when you are using the old format.