Mu4e: Improve alert style

This commit is contained in:
TEC 2020-05-26 01:16:23 +08:00
parent 7dbab92acd
commit fde8a3e8c5

View file

@ -1765,10 +1765,11 @@ bit more visually appealing.
:after mu4e :after mu4e
:config :config
(mu4e-alert-enable-mode-line-display) (mu4e-alert-enable-mode-line-display)
(mu4e-alert-enable-notifications) (mu4e-alert-enable-notifications)
(setq mu4e-alert-email-notification-types '(subject count))
(mu4e-alert-set-default-style 'libnotify) (mu4e-alert-set-default-style 'libnotify)
(setq mu4e-alert-icon "/usr/share/icons/Papirus/64x64/apps/evolution.svg") (setq mu4e-alert-icon "/usr/share/icons/Papirus/64x64/apps/evolution.svg")
(defun mu4e-alert-iconised-modeline-formatter (mail-count) (defun mu4e-alert-iconised-modeline-formatter (mail-count)
"Formatter used to get the string to be displayed in the mode-line, using all-the-icons. "Formatter used to get the string to be displayed in the mode-line, using all-the-icons.
MAIL-COUNT is the count of mails for which the string is to displayed" MAIL-COUNT is the count of mails for which the string is to displayed"
@ -1790,7 +1791,49 @@ MAIL-COUNT is the count of mails for which the string is to displayed"
(mouse-1 . mu4e-alert-view-unread-mails) (mouse-1 . mu4e-alert-view-unread-mails)
(mouse-2 . mu4e-alert-view-unread-mails) (mouse-2 . mu4e-alert-view-unread-mails)
(mouse-3 . mu4e-alert-view-unread-mails)))))) (mouse-3 . mu4e-alert-view-unread-mails))))))
(setq mu4e-alert-modeline-formatter #'mu4e-alert-iconised-modeline-formatter)) (setq mu4e-alert-modeline-formatter #'mu4e-alert-iconised-modeline-formatter)
(setq mu4e-alert-email-notification-types '(subjects))
(defun mu4e-alert-grouped-mail-notification-formatter-with-bell (mail-group all-mails)
"Default function to format MAIL-GROUP for notification.
ALL-MAILS are the all the unread emails"
(shell-command "paplay /usr/share/sounds/freedesktop/stereo/message.oga")
(if (> (length mail-group) 1)
(let* ((mail-count (length mail-group))
(total-mails (length all-mails))
(first-mail (car mail-group))
(title-prefix (format "You have %d unread emails"
mail-count))
(field-value (mu4e-alert--get-group first-mail))
(title-suffix (format (pcase mu4e-alert-group-by
(`:from "from %s:")
(`:to "to %s:")
(`:maildir "in %s:")
(`:priority "with %s priority:")
(`:flags "with %s flags:"))
field-value))
(title (format "%s %s" title-prefix title-suffix)))
(list :title title
:body (s-join "\n"
(mapcar (lambda (mail)
(format "%s<b>%s</b> • %s"
(cond
((plist-get mail :in-reply-to) "⮩ ")
((string-match-p "\\`Fwd:"
(plist-get mail :subject)) " ⮯ ")
(t "  "))
(truncate-string-to-width (caar (plist-get mail :from))
20 nil nil t)
(truncate-string-to-width
(replace-regexp-in-string "\\`Re: \\|\\`Fwd: " ""
(plist-get mail :subject))
40 nil nil t)))
mail-group))))
(let* ((new-mail (car mail-group))
(subject (plist-get new-mail :subject))
(sender (caar (plist-get new-mail :from))))
(list :title sender :body subject))))
(setq mu4e-alert-grouped-mail-notification-formatter #'mu4e-alert-grouped-mail-notification-formatter-with-bell))
#+END_SRC #+END_SRC
**** Process control **** Process control
Here's what I want Here's what I want