mu4e: add mu4e-last-query-result[s]

This makes the most recent results from the queries (i.e. the numbers)
available using the supported 'mu4e-' API.

Fixes: #1845.
This commit is contained in:
Dirk-Jan C. Binnema
2020-12-06 13:03:18 +02:00
parent aba0ab3629
commit 273eb822d5
2 changed files with 24 additions and 3 deletions

View File

@ -117,12 +117,11 @@ clicked."
'mouse-face 'highlight newstr)
newstr))
(defun mu4e~main-bookmarks ()
;; TODO: it's a bit uncool to hard-code the "b" shortcut...
(cl-loop with bmks = (mu4e-bookmarks)
with longest = (mu4e~longest-of-maildirs-and-bookmarks)
with queries = (plist-get mu4e~server-props :queries)
with queries = (mu4e-last-query-results)
for bm in bmks
for key = (string (plist-get bm :key))
for name = (plist-get bm :name)

View File

@ -792,6 +792,28 @@ nothing."
(lambda () (mu4e-update-mail-and-index
mu4e-index-update-in-background)))))))
(defun mu4e-last-query-results ()
"Get the results (counts) of the last cached queries.
The cached queries are the bookmark / maildir queries that are
used to populated the read/unread counts in the main view. They
are refreshed when calling `(mu4e)', i.e., when going to the main
view.
The results are a list of elements of the form
(:query \"query string\"
:count <total number matching count>
:unread <number of unread messages in count>)"
(plist-get mu4e~server-props :queries))
(defun mu4e-last-query-result (query)
"Get the last result for some cached query, as per
`mu4e-bookmark-query-results' or nil if not found."
(cl-find-if
(lambda (elm) (string= (plist-get elm :query) query))
(mu4e-last-query-results)))
(defun mu4e~start (&optional func)
"If `mu4e-contexts' have been defined, but we don't have a