9

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.

1 Answer 1

3

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 ?█)))))

(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)
                   (let ((color (assoc-default ml mu4e-mailing-list-colors)))
                     `(:foreground ,color :background ,color))
                 `(:foreground ,(face-attribute 'highlight :background)))))
    (when (fboundp 'add-face-text-property)
      (add-face-text-property 53 54 face t line))
    line))

enter image description here

4
  • Thanks for the answer @jagrg! Unfortunately the color bar in the second solution disappears when your point is on a particular message. I think the highlighting is overriding it somehow. Any idea how to fix that? Jul 6, 2019 at 22:08
  • @MatthewPiziak can you try now.
    – jagrg
    Jul 7, 2019 at 20:48
  • Interestingly, it still doesn't show the full bar for me, but I can see the color in the underline: imgur.com/XX7lAnvl.png. Jul 8, 2019 at 1:17
  • I stopped mu4e-header-highlight-face from inheriting from region and now it appears. Not sure why, but my region has DistantForeground: gtk_selection_fg_color and Background: #11472b. Anyway, I find that removing the region inheritance looks cleaner with my configuration anyway, so I'm keeping that. Jul 8, 2019 at 1:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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