diff options
author | Vincent Ambo <tazjin@gmail.com> | 2018-06-14T23·12+0200 |
---|---|---|
committer | Vincent Ambo <tazjin@gmail.com> | 2018-06-14T23·15+0200 |
commit | 59aa3389325fd1ddad56f98aec917ab6583f52ea (patch) | |
tree | 4aaa173e5806fc25245be8c5437e895cb6cc0e30 /init/mail-setup.el | |
parent | 96653181158a799ba091e76fe66784826da71f9f (diff) |
feat(mail): Implement unread count telephone-line segment
Implements a periodically updated telephone-line segment that displays the current unread count for the two most important inboxes in the mode-line, if there are unread mails.
Diffstat (limited to 'init/mail-setup.el')
-rw-r--r-- | init/mail-setup.el | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/init/mail-setup.el b/init/mail-setup.el index b7fffa360856..8db2662d17b3 100644 --- a/init/mail-setup.el +++ b/init/mail-setup.el @@ -58,4 +58,36 @@ ;; for this seems to run at the wrong time. (advice-add 'notmuch-mua-send-common :before 'warmup-gpg-agent) +;; Define a telephone-line segment for displaying the count of unread, +;; important mails in the last window's mode-line: +(defvar *last-notmuch-count-redraw* 0) +(defvar *current-notmuch-count* nil) + +(defun update-display-notmuch-counts () + "Update and render the current state of the notmuch unread + count for display in the mode-line. + + The offlineimap-timer runs every 2 minutes, so it does not make + sense to refresh this much more often than that." + + (when (> (- (float-time) *last-notmuch-count-redraw*) 90) + (setq *last-notmuch-count-redraw* (float-time)) + (let* ((inbox-unread (notmuch-saved-search-count "tag:inbox and tag:unread")) + (devel-unread (notmuch-saved-search-count "tag:aprila-dev and tag:unread")) + (notmuch-count (format "I: %s; D: %s" inbox-unread devel-unread))) + (setq *current-notmuch-count* notmuch-count))) + + (when (and (bottom-right-window-p) + ;; Only render if the initial update is done and there + ;; are unread mails: + *current-notmuch-count* + (not (equal *current-notmuch-count* "I: 0; D: 0"))) + *current-notmuch-count*)) + +(telephone-line-defsegment telephone-line-notmuch-counts () + "This segment displays the count of unread notmuch messages in + the last window's mode-line (if unread messages are present)." + + (update-display-notmuch-counts)) + (provide 'mail-setup) |