8.8 Adding a new kind of mark

It is possible to configure new marks. To do so, one can add entries in the list mu4e-marks. Such an element must have the following form:

  :char STRING
  :prompt STRING
  :ask-target (lambda () TARGET)
  :dyn-target (lambda (TARGET MSG) DYN-TARGET)
  :show-target (lambda (DYN-TARGET) STRING)
  :action (lambda (DOCID MSG DYN-TARGET) nil))

The symbol can be any symbol, except for 'unmark and 'something, which are reserved. The rest is a plist with the following elements:

As an example, suppose we would like to add a mark for tagging messages (GMail-style), then we can run the following code (after loading mu4e):

(add-to-list 'mu4e-marks
     :char       "g"
     :prompt     "gtag"
     :ask-target (lambda () (read-string "What tag do you want to add?"))
     :action      (lambda (docid msg target)
                    (mu4e-action-retag-message msg (concat "+" target)))))

Adding to mu4e-marks list allows to use the mark in bulk operations (for example when tagging a whole thread), but does not bind the mark to a key to use at the top-level. This must be done separately. In our example:

(defun my-mu4e-mark-add-tag()
  "Add a tag to the message."
  (mu4e-headers-mark-and-next 'tag))

(define-key mu4e-headers-mode-map (kbd "g") 'mu4e-headers-mark-for-tag)