Mu4e: Add account stripe, and use it by default

This commit is contained in:
TEC 2020-10-14 17:28:10 +08:00
parent 7cf91ff61d
commit 6490565404
No known key found for this signature in database
GPG key ID: 779591AFDB81F06C
2 changed files with 80 additions and 29 deletions

View file

@ -131,6 +131,48 @@ will also be the width of all other printable characters."
(put-text-property 0 (length str) 'face color str)
str))
;;;###autoload
(defun +mu4e-colorize-str (str &optional unique herring)
"Apply a face from `+mu4e-header-colorized-faces' to STR.
If HERRING is set, it will be used to determine the face instead of STR.
Will try to make unique when non-nil UNIQUE,
a quoted symbol for a alist of current strings and faces provided."
(unless herring
(setq herring str))
(put-text-property
0 (length str)
'face
(if (not unique)
(+mu4e--str-color-face herring str)
(let ((unique-alist (eval unique)))
(unless (assoc herring unique-alist)
(if (> (length unique-alist) (length +mu4e-header-colorized-faces))
(push (cons herring (+mu4e--str-color-face herring)) unique-alist)
(let ((offset 0) color color?)
(while (not color)
(setq color? (+mu4e--str-color-face herring offset))
(if (not (rassoc color? unique-alist))
(setq color color?)
(setq offset (1+ offset))
(when (> offset (length +mu4e-header-colorized-faces))
(message "Warning: +mu4e-colorize-str was called with non-unique-alist UNIQUE-alist alist.")
(setq color (+mu4e--str-color-face herring)))))
(push (cons herring color) unique-alist)))
(set unique unique-alist))
(cdr (assoc herring unique-alist))))
str)
str)
;;;###autoload
(defun +mu4e--str-color-face (str &optional offset)
"Select a face from `+mu4e-header-colorized-faces' based on
STR and any integer OFFSET."
(let* ((str-sum (apply #'+ (mapcar (lambda (c) (% c 3)) str)))
(color (nth (% (+ str-sum (if offset offset 0))
(length +mu4e-header-colorized-faces))
+mu4e-header-colorized-faces)))
color))
;; Adding emails to the agenda
;; Perfect for when you see an email you want to reply to
;; later, but don't want to forget about

View file

@ -61,10 +61,10 @@
mu4e-headers-thread-connection-prefix '("" . "")
;; remove 'lists' column
mu4e-headers-fields
'((:account . 12)
'((:account-stripe . 1)
(:human-date . 8)
(:flags . 6) ; 3 icon flags
(:from . 25)
(:from-or-to . 25)
(:subject)))
;; set mail user agent
@ -94,39 +94,48 @@
(add-to-list 'mu4e-bookmarks
'(:name "Flagged messages" :query "flag:flagged" :key ?f) t)
(defun +mu4e-header-colorize (str)
(let* ((str-sum (apply #'+ (mapcar (lambda (c) (% c 3)) str)))
(colour (nth (% str-sum (length +mu4e-header-colorized-faces))
+mu4e-header-colorized-faces)))
(put-text-property 0 (length str) 'face colour str)
str))
(setq +mu4e-header-colorized-faces
'(all-the-icons-green
all-the-icons-lblue
all-the-icons-purple-alt
all-the-icons-blue-alt
all-the-icons-purple
all-the-icons-yellow))
(defvar +mu4e-header-colorized-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.
;; Add a column to display what email account the email belongs to,
;; and an account color stripe column
(defvar +mu4e-header--maildir-colors nil)
(setq mu4e-header-info-custom
'((:account .
(:name "account"
:shortname "account"
(:name "Account"
:shortname "Account"
:help "which account this email belongs to"
:function
(lambda (msg)
(let ((maildir
(mu4e-message-field msg :maildir)))
(+mu4e-header-colorize
(replace-regexp-in-string
"^gmail"
(propertize "g" 'face 'bold-italic)
(format "%s"
(substring maildir 1
(string-match-p "/" maildir 1)))))))))
(+mu4e-colorize-str
(replace-regexp-in-string
"^gmail"
(propertize "g" 'face 'bold-italic)
(format "%s"
(substring maildir 1
(string-match-p "/" maildir 1))))
'+mu4e-header--maildir-colors
(replace-regexp-in-string
"\\`/\\([^/]+\\)/.*\\'" "\\1"
(mu4e-message-field msg :maildir))))))
(:account-stripe .
(:name "Account"
:shortname ""
:help "Which account this email belongs to"
:function
(lambda (msg)
(let ((account
(replace-regexp-in-string
"\\`/?\\([^/]+\\)/.*\\'" "\\1"
(mu4e-message-field msg :maildir))))
(propertize
(+mu4e-colorize-str "" '+mu4e-header--maildir-colors account)
'help-echo account)))))
(:recipnum .
(:name "Number of recipients"
:shortname ""