8.8 Adding a new kind of mark

It is possible to configure new marks, by adding elements to 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 the symbols 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). We can use 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 elements to mu4e-marks (as in the example) allows you to use the mark in bulk operations (for example when tagging a whole thread); if you also want to add a key-binding for the headers view, you can use something like:

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

(define-key mu4e-headers-mode-map (kbd "g") #'my-mu4e-mark-add-tag)