Color filters

21 views
Skip to first unread message

Myravian

unread,
Aug 8, 2021, 2:27:55 PM8/8/21
to mu-discuss
Hi there, 

There was this trick I was using to get different colors depending on the from address:

;;colors
  (defvar mu4e-list-colors
    '(
      ;;work
      ("xxx" . "#AFA")
      ))
  (setq list (alist-keys mu4e-list-colors))
  (defun mu4e~headers-line-apply-list-face (msg line)
    "Adjust LINE's face property based on the color list."
    (let* ((ml (downcase (cdar (mu4e-message-field msg :from))))
           ;;(face (if (assoc ml mu4e-list-colors)
           ;;          (let ((color (assoc-default ml mu4e-list-colors)))
           (res (xah-string-match-in-list-p ml list "no" 1))
           (face (if res
                     (let ((color (assoc-default res mu4e-list-colors)))
                       ;;`(:foreground ,color :background ,color))
                       `(:foreground ,color))
                   ;;`(:foreground ,(face-attribute 'highlight :background))
                   `(:foreground ,(face-attribute 'mu4e-flagged-face :background))
                   ;;`(:foreground "black" :background "black")
                   )))
      (when (fboundp 'add-face-text-property)
        (add-face-text-property 0 (length line) face t line))
      ;;(add-face-text-property 28 29 face t line))
      line))
  (add-to-list 'mu4e~headers-line-handler-functions
               'mu4e~headers-line-apply-list-face)

But this doesn't work anymore with 1.6. 

There's also this method with the font-lock:

(setq header-highlights
  '(
    (".*\\(mrX\\|mrsY\\).*" . email-dir-face)
    ))

(add-hook 'mu4e-headers-mode-hook
      (lambda ()
        (setq font-lock-defaults '(header-highlights))))
 
  (defface email-dir
  '((t :foreground "#FAA"))
  "Face for mail headers"
  :group 'basic-faces)

(setq email-dir-face 'email-dir)

Which is ok except this considers all the header row, and I'd like to use the from address. 

So I have some questions!
- Do you have a working color filter for the header view working with 1.6?
- Is it possible to add the actual email addresses in the headers view? (in which case the font-lock method would still work ok)

Cheers!

Myravian

unread,
Aug 9, 2021, 5:57:49 AM8/9/21
to mu-discuss
Sorry for the double post but I figured out I could just modify the mu4e-column-faces program as such:

;;define specific faces
(defface mu4e-column-faces-list
  '((t :foreground "#AAA" :inherit mu4e-header-face))
  "Face for `:flags' columns.")

;;define list of matches
(defvar mu4e-list-faces
  '(
    ;;group
    ("mrX" . 'mu4e-column-faces-list)
;;...
))
(setq listmatches (alist-keys
                   mu4e-list-faces))

And in (define-inline mu4e-column-faces--determine-face...:

((:to :from :cc :bcc)  (let* ((ml (downcase (cdar (mu4e-message-field ,msg :from))))
                                     (res (xah-string-match-in-list-p ml listmatches "no" 1))
                                     )
                                (if res
                                    (assoc-default res mu4e-list-faces)
                                  'mu4e-header-face)
                                ))

That does the job for me, but if you have other suggestions, I'm always interested!
Reply all
Reply to author
Forward
0 new messages