Next: , Previous: , Up: Marking   [Contents]

8.6 Custom mark functions

Sometimes, the built-in functions to mark messages may not be sufficient for your needs. For this, mu4e offers an easy way to define your own custom mark functions. You can choose one of the custom marker functions by pressing & in the Headers view and Message view.

Custom mark functions are to be appended to the list mu4e-headers-custom-markers. Each of the elements of this list (’markers’) is a list with two or three elements:

  1. The name of the marker - a short string describing this marker. The first character of this string determines its shortcut, so these should be unique. If necessary, simply prefix the name with a unique character.
  2. a predicate function, taking two arguments msg and param. msg is the message plist (see Message functions) and param is a parameter provided by the third of the marker elements (see the next item). The predicate function should return non-nil if the message matches.
  3. (optionally) a function that is evaluated once, and the result is passed as a parameter to the predicate function. This is useful when user-input is needed.

Let’s look at an example: suppose we want to match all messages that have more than n recipients – we could do this with the following recipe:

(add-to-list 'mu4e-headers-custom-markers
  '("More than n recipients"
     (lambda (msg n)
       (> (+ (length (mu4e-message-field msg :to))
            (length (mu4e-message-field msg :cc))) n))
     (lambda ()
       (read-number "Match messages with more recipients than: "))) t)

After evaluating this expression, you can use it by pressing & in the headers buffer to select a custom marker function, and then M to choose this particular one (M because it is the first character of the description).

As you can see, it’s not very hard to define simple functions to match messages. There are more examples in the defaults for mu4e-headers-custom-markers; see mu4e-headers.el and see Extending mu4e for general information about writing your own functions.

Next: , Previous: , Up: Marking   [Contents]