7

I'd like to color the messages in my *mu4e-headers* view, depending on which mailing list they come from. I'm rather new to emacs face alterations, and I didn't see anything that looked relevant for this. Are there programmatic hooks for defining a per-line face?

Example: If an email is in my INBOX/ML folder, I'd like it green. If it's just in my INBOX, I'd like it blue.

0

Line faces are defined in mu4e~headers-line-handler-functions. To change the face conditionally you can set your preferences in mu4e-mailing-list-colors and try the following code (based on the mu4e~headers-line-apply-flag-face function):

(defvar mu4e-mailing-list-colors
  '(("emacs-devel.gnu.org" . "green")
    ("emacs-orgmode.gnu.org" . "blue")))

(defun mu4e~headers-line-apply-mailing-list-face (msg line)
  "Adjust LINE's face property based on the MSG's mailing-list value."
  (let* ((ml (mu4e-message-field msg :mailing-list))
         (face (if (assoc ml mu4e-mailing-list-colors)
                   `(:foreground ,(assoc-default ml mu4e-mailing-list-colors))
                 'mu4e-header-face)))
    (when (fboundp 'add-face-text-property)
      (add-face-text-property 0 (length line) face t line))
    line))

(add-to-list 'mu4e~headers-line-handler-functions
             'mu4e~headers-line-apply-mailing-list-face)

enter image description here

For a more suddle effect you can add a new header field and add fontification only on that portion of the line. You will also have to add (:colorize . 1) to mu4e-headers-fields and tweak the numbers in add-face-text-property. Here's an example:

(add-to-list 'mu4e-header-info-custom
             '(:colorize . (:name "Mailing list"
                            :shortname ""
                            :function (lambda (_msg)
                                        (make-string 1 ?\s)))))

(defun mu4e~headers-line-apply-mailing-list-face (msg line)
  "Adjust LINE's face property based on the mailing list."
  (let* ((ml (mu4e-message-field msg :mailing-list))
         (face (if (assoc ml mu4e-mailing-list-colors)
                   `(:background ,(assoc-default ml mu4e-mailing-list-colors))
                 'mu4e-header-face)))
    (when (fboundp 'add-face-text-property)
      (add-face-text-property 53 54 face t line))
    line))

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.