mu4e-bookmarks/folders: allow -ask to return query-item
Instead of just the query-string or maildir name, allow mu4e-ask-bookmark / mu4e-ask-folder to return the query-item, when a new optional parameter QUERY-ITEM is non-nil.
This commit is contained in:
@ -87,11 +87,14 @@ query."
|
||||
(declare-function mu4e-query-items "mu4e-query-items")
|
||||
(declare-function mu4e--query-item-display-short-counts "mu4e-query-items")
|
||||
|
||||
(defun mu4e-ask-bookmark (prompt)
|
||||
(defun mu4e-ask-bookmark (prompt &optional query-item)
|
||||
"Ask user for bookmark using PROMPT.
|
||||
Return the corresponding query. The bookmark are as defined in
|
||||
`mu4e-bookmarks'.
|
||||
|
||||
If QUERY-ITEM is non-nil, return the full query-item rather than
|
||||
just the query-string.
|
||||
|
||||
The names of the bookmarks are displayed in the minibuffer,
|
||||
suffixed with the short version of the unread counts, as per
|
||||
`mu4e--query-item-display-short-counts'."
|
||||
@ -107,10 +110,13 @@ suffixed with the short version of the unread counts, as per
|
||||
(cons (format "%c%s%s"
|
||||
(plist-get bm :key)
|
||||
(plist-get bm :name)
|
||||
unreads)
|
||||
(plist-get bm :query))))
|
||||
(mu4e-filter-single-key (mu4e-bookmarks)))))
|
||||
(mu4e-read-option prompt bmarks)))
|
||||
unreads) bm)))
|
||||
(mu4e-filter-single-key (mu4e-bookmarks))))
|
||||
(chosen (mu4e-read-option prompt bmarks)))
|
||||
;; return either the query string, or the corresponding query-item.
|
||||
(if query-item
|
||||
chosen
|
||||
(plist-get chosen :query))))
|
||||
|
||||
(defun mu4e-get-bookmark-query (kar)
|
||||
"Get the corresponding bookmarked query for shortcut KAR.
|
||||
|
||||
@ -247,9 +247,13 @@ to create it; otherwise return nil."
|
||||
"Get maildirs under `mu4e-maildir'."
|
||||
mu4e-maildir-list)
|
||||
|
||||
(defun mu4e-ask-maildir (prompt)
|
||||
|
||||
(defun mu4e-ask-maildir (prompt &optional query-item)
|
||||
"Ask the user for a maildir (using PROMPT).
|
||||
|
||||
If QUERY-ITEM is non-nil, return the full query-item rather than
|
||||
just the query-string.
|
||||
|
||||
If the special shortcut \"o\" (for _o_ther) is used, or
|
||||
if (mu4e-maildir-shortcuts) evaluates to nil, let user choose
|
||||
from all maildirs under `mu4e-maildir'.
|
||||
@ -257,7 +261,8 @@ from all maildirs under `mu4e-maildir'.
|
||||
The names of the maildirs are displayed in the minibuffer,
|
||||
suffixed with the short version of the unread counts, as per
|
||||
`mu4e--query-item-display-short-counts'."
|
||||
(let* ((options
|
||||
(let* ((mdirs
|
||||
(append
|
||||
(seq-map
|
||||
(lambda (md)
|
||||
(let* ((qitem (mu4e--query-item-for-maildir-shortcut md))
|
||||
@ -267,22 +272,23 @@ suffixed with the short version of the unread counts, as per
|
||||
(plist-get md :key)
|
||||
(or (plist-get md :name)
|
||||
(plist-get md :maildir))
|
||||
unreads)
|
||||
(plist-get md :maildir))))
|
||||
(mu4e-filter-single-key (mu4e-maildir-shortcuts))))
|
||||
(response
|
||||
(if (not options)
|
||||
'other
|
||||
(mu4e-read-option prompt
|
||||
(append options
|
||||
'(("oOther..." . other)))))))
|
||||
unreads) md)))
|
||||
(mu4e-filter-single-key (mu4e-maildir-shortcuts)))
|
||||
'(("oOther..." . other)))) ;; append "Other" pseudo-maildir
|
||||
(chosen (mu4e-read-option prompt mdirs))
|
||||
;; special case: handle pseudo-maildir 'other
|
||||
(chosen (if (eq chosen 'other)
|
||||
(list :maildir
|
||||
(substring-no-properties
|
||||
(if (eq response 'other)
|
||||
(progn
|
||||
(funcall mu4e-completing-read-function prompt
|
||||
(mu4e-get-maildirs) nil nil
|
||||
mu4e-maildir-initial-input))
|
||||
response))))
|
||||
mu4e-maildir-initial-input)))
|
||||
chosen)))
|
||||
;; return either the maildir (as a string), or the corresponding
|
||||
;; query-item.
|
||||
(if query-item
|
||||
chosen
|
||||
(plist-get chosen :maildir))))
|
||||
|
||||
(defun mu4e-ask-maildir-check-exists (prompt)
|
||||
"Like `mu4e-ask-maildir', PROMPT for existence of the maildir.
|
||||
|
||||
Reference in New Issue
Block a user