Mu4e: Fancify headers

Add accounts name colourisation (with a colourisation function + var of
colours) and change the :recipnum header display while I'm at it. It
doesn't deserve the default amount of space/attention.
This commit is contained in:
TEC 2020-09-23 01:22:29 +08:00
parent 65d743926b
commit 9b9f64d912
No known key found for this signature in database
GPG key ID: 779591AFDB81F06C

View file

@ -120,6 +120,10 @@ will also be the width of all other printable characters."
(mu4e~initialise-icons) (mu4e~initialise-icons)
(remove-hook #'mu4e~initialise-icons-hook))))) (remove-hook #'mu4e~initialise-icons-hook)))))
;;----------------
;; Header view
;;----------------
(setq mu4e-headers-fields (setq mu4e-headers-fields
'((:account . 12) '((:account . 12)
(:human-date . 8) (:human-date . 8)
@ -129,17 +133,50 @@ will also be the width of all other printable characters."
(plist-put (cdr (assoc :flags mu4e-header-info)) :shortname " Flags") ; default=Flgs (plist-put (cdr (assoc :flags mu4e-header-info)) :shortname " Flags") ; default=Flgs
;; Add a column to display what email account the email belongs to. ;; A header colourisation function/variable could be handy
(add-to-list 'mu4e-header-info-custom (defun mu4e~header-colourise (str)
'(:account (let* ((str-sum (apply #'+ (mapcar (lambda (c) (% c 3)) str)))
:name "Account" (colour (nth (% str-sum (length mu4e-header-colourised-faces))
:shortname "Account" mu4e-header-colourised-faces)))
:help "Which account this email belongs to" (put-text-property 0 (length str) 'face colour str)
:function str))
(lambda (msg)
(let ((maildir (mu4e-message-field msg :maildir)))
(format "%s" (substring maildir 1 (string-match-p "/" maildir 1)))))))
(defvar mu4e~header-colourised-faces
'(all-the-icons-lblue
all-the-icons-purple
all-the-icons-blue-alt
all-the-icons-green
all-the-icons-maroon
all-the-icons-yellow
all-the-icons-orange))
;; Add a column to display what email account the email belongs to.
(setq mu4e-header-info-custom
'((:account .
(:name "account"
:shortname "account"
:help "which account this email belongs to"
:function
(lambda (msg)
(let ((maildir
(mu4e-message-field msg :maildir)))
(mu4e-header-colourise
(replace-regexp-in-string
"^gmail"
(propertize "g" 'face 'bold-italic)
(format "%s"
(substring maildir 1
(string-match-p "/" maildir 1)))))))))
(:recipnum .
(:name "Number of recipients"
:shortname ""
:help "Number of recipients for this message"
:function
(lambda (msg)
(propertize (format "%2d"
(+ (length (mu4e-message-field msg :to))
(length (mu4e-message-field msg :cc))))
'face 'mu4e-footer-face)))))))
(defadvice! +mu4e--refresh-current-view-a (&rest _) (defadvice! +mu4e--refresh-current-view-a (&rest _)
:after #'mu4e-mark-execute-all (mu4e-headers-rerun-search)) :after #'mu4e-mark-execute-all (mu4e-headers-rerun-search))