mu4e-folders: rework the mu4e-ask-maildir

Attempt to restore the old behaviour of _other_ when there are no maildir
shortcuts defined.

Should help for #2843.
This commit is contained in:
Dirk-Jan C. Binnema
2025-04-23 07:42:45 +03:00
parent 371216a9fe
commit 9cd4d73212

View File

@ -248,37 +248,36 @@ to create it; otherwise return nil."
"Get maildirs under `mu4e-maildir'." "Get maildirs under `mu4e-maildir'."
mu4e-maildir-list) mu4e-maildir-list)
(defun mu4e-ask-maildir (prompt &optional query-item) (defun mu4e-ask-maildir (prompt &optional query-item)
"Ask the user for a maildir (using PROMPT). "Ask the user for a maildir (using PROMPT).
If QUERY-ITEM is non-nil, return the full query-item rather than If QUERY-ITEM is non-nil, return the full query-item rather than
just the query-string. just the query-string.
If the special shortcut \"o\" (for _o_ther) is used, or If the special shortcut \"o\" (for _o_ther) is used, or if there
if (mu4e-maildir-shortcuts) evaluates to nil, let user choose a no single-key elements in (mu4e-maildir-shortcuts), let user
from all maildirs under `mu4e-maildir'. choose from all maildirs under `mu4e-maildir'.
The names of the maildirs are displayed in the minibuffer, The names of the maildirs are displayed in the minibuffer,
suffixed with the short version of the unread counts, as per suffixed with the short version of the unread counts, as per
`mu4e--query-item-display-short-counts'." `mu4e--query-item-display-short-counts'."
(let* ((mdirs (let* ((mdirs
(append (seq-map
(seq-map (lambda (md)
(lambda (md) (let* ((qitem (mu4e--query-item-for-maildir-shortcut md))
(let* ((qitem (mu4e--query-item-for-maildir-shortcut md)) (unreads (mu4e--query-item-display-short-counts qitem)))
(unreads (mu4e--query-item-display-short-counts qitem))) (cons
(cons (format "%c%s%s"
(format "%c%s%s" (plist-get md :key)
(plist-get md :key) (or (plist-get md :name)
(or (plist-get md :name) (plist-get md :maildir))
(plist-get md :maildir)) unreads) md)))
unreads) md))) (mu4e-filter-single-key (mu4e-maildir-shortcuts))))
(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 ;; special case: handle pseudo-maildir 'other
(chosen (if (eq chosen 'other) (mdirs (and mdirs (append mdirs '(("oOther..." . other)))))
(chosen (and mdirs (mu4e-read-option prompt mdirs)))
;; if chosen nothing or other, ask for more.
(chosen (if (or (not chosen) (eq chosen 'other))
(list :maildir (list :maildir
(substring-no-properties (substring-no-properties
(funcall mu4e-completing-read-function prompt (funcall mu4e-completing-read-function prompt
@ -287,9 +286,7 @@ suffixed with the short version of the unread counts, as per
chosen))) chosen)))
;; return either the maildir (as a string), or the corresponding ;; return either the maildir (as a string), or the corresponding
;; query-item. ;; query-item.
(if query-item (if query-item chosen (plist-get chosen :maildir))))
chosen
(plist-get chosen :maildir))))
(defun mu4e-ask-maildir-check-exists (prompt) (defun mu4e-ask-maildir-check-exists (prompt)
"Like `mu4e-ask-maildir', PROMPT for existence of the maildir. "Like `mu4e-ask-maildir', PROMPT for existence of the maildir.