mu4e: make mu4e-maildir-shortcuts a plist

Similar to mu4e-bookmarks.
This commit is contained in:
Dirk-Jan C. Binnema 2020-02-25 21:20:51 +02:00
parent 865f0ab9db
commit 74d40f4d20
2 changed files with 55 additions and 31 deletions

View File

@ -357,35 +357,35 @@ the list of maildirs will not change until you restart mu4e."
mu4e-maildir-list) mu4e-maildir-list)
(defun mu4e-ask-maildir (prompt) (defun mu4e-ask-maildir (prompt)
"Ask the user for a shortcut (using PROMPT) as defined in "Ask the user for a shortcut (using PROMPT) as per
`mu4e-maildir-shortcuts', then return the corresponding folder (mu4e-maildir-shortcuts), then return the corresponding folder
name. If the special shortcut 'o' (for _o_ther) is used, or if name. If the special shortcut 'o' (for _o_ther) is used, or if
`mu4e-maildir-shortcuts' is not defined, let user choose from all `(mu4e-maildir-shortcuts)' evaluates to nil, let user choose from
maildirs under `mu4e-maildir'." all maildirs under `mu4e-maildir'."
(let ((prompt (mu4e-format "%s" prompt))) (let ((prompt (mu4e-format "%s" prompt)))
(if (not mu4e-maildir-shortcuts) (if (not (mu4e-maildir-shortcuts))
(funcall mu4e-completing-read-function prompt (mu4e-get-maildirs)) (funcall mu4e-completing-read-function prompt (mu4e-get-maildirs))
(let* ((mlist (append mu4e-maildir-shortcuts '(("ther" . ?o)))) (let* ((mlist (append (mu4e-maildir-shortcuts)
'((:maildir "ther" :key ?o))))
(fnames (fnames
(mapconcat (mapconcat
(lambda (item) (lambda (item)
(concat (concat
"[" "["
(propertize (make-string 1 (cdr item)) (propertize (make-string 1 (plist-get item :key))
'face 'mu4e-highlight-face) 'face 'mu4e-highlight-face)
"]" "]"
(car item))) (plist-get item :maildir)))
mlist ", ")) mlist ", "))
(kar (read-char (concat prompt fnames)))) (kar (read-char (concat prompt fnames))))
(if (member kar '(?/ ?o)) ;; user chose 'other'? (if (member kar '(?/ ?o)) ;; user chose 'other'?
(funcall mu4e-completing-read-function prompt (funcall mu4e-completing-read-function prompt
(mu4e-get-maildirs) nil nil "/") (mu4e-get-maildirs) nil nil "/")
(or (car-safe (or (plist-get
(cl-find-if (lambda (item) (= kar (cdr item))) (cl-find-if (lambda (item) (= kar (plist-get item :key)))
mu4e-maildir-shortcuts)) (mu4e-maildir-shortcuts)) :maildir)
(mu4e-warn "Unknown shortcut '%c'" kar))))))) (mu4e-warn "Unknown shortcut '%c'" kar)))))))
(defun mu4e-ask-maildir-check-exists (prompt) (defun mu4e-ask-maildir-check-exists (prompt)
"Like `mu4e-ask-maildir', but check for existence of the maildir, "Like `mu4e-ask-maildir', but check for existence of the maildir,
and offer to create it if it does not exist yet." and offer to create it if it does not exist yet."
@ -398,20 +398,7 @@ and offer to create it if it does not exist yet."
mdir)) mdir))
;;; Bookmarks ;;; Bookmarks
(defun mu4e-ask-bookmark (prompt)
(defun mu4e-bookmarks ()
"Get `mu4e-bookmarks' in the (new) format, converting from the
old format if needed."
(cl-map 'list
(lambda (item)
(if (and (listp item) (= (length item) 3))
`(:name ,(nth 1 item)
:query ,(nth 0 item)
:key ,(nth 2 item))
item))
mu4e-bookmarks))
(defun mu4e-ask-bookmark (prompt)
"Ask the user for a bookmark (using PROMPT) as defined in "Ask the user for a bookmark (using PROMPT) as defined in
`mu4e-bookmarks', then return the corresponding query." `mu4e-bookmarks', then return the corresponding query."
(unless (mu4e-bookmarks) (mu4e-error "No bookmarks defined")) (unless (mu4e-bookmarks) (mu4e-error "No bookmarks defined"))

View File

@ -233,6 +233,20 @@ bookmarks depend on that, the results may differ."
:type '(repeat (plist)) :type '(repeat (plist))
:group 'mu4e) :group 'mu4e)
(defun mu4e-bookmarks ()
"Get `mu4e-bookmarks' in the (new) format, converting from the
old format if needed."
(cl-map 'list
(lambda (item)
(if (and (listp item) (= (length item) 3))
`(:name ,(nth 1 item)
:query ,(nth 0 item)
:key ,(nth 2 item))
item))
mu4e-bookmarks))
(defcustom mu4e-split-view 'horizontal (defcustom mu4e-split-view 'horizontal
"How to show messages / headers. "How to show messages / headers.
A symbol which is either: A symbol which is either:
@ -527,20 +541,43 @@ nil otherwise."
"A list of maildir shortcuts. "A list of maildir shortcuts.
This makes it possible to quickly go to a particular This makes it possible to quickly go to a particular
maildir (folder), or quickly moving messages to them (e.g., for maildir (folder), or quickly moving messages to them (e.g., for
archiving or refiling). The list contains elements of the archiving or refiling).
form (maildir . shortcut), where MAILDIR is a maildir (such as
\"/archive/\"), and shortcut is a single character. Each of the list elements is a plist with at least:
`:maildir' - the maildir for the shortcut (e.g. \"/archive\")
`:key' - the shortcut key.
Optionally, you can add the following:
`:hide' - if t, maildir is hdden from the main-view and speedbar.
`:hide-unread' - do not show the counts of unread/total number
of messages for the maildir in the main-view.
For backward compatibility, an older form is recognized as well:
(maildir . key), where MAILDIR is a maildir (such as
\"/archive/\"), and key is a single character.
You can use these shortcuts in the headers and view buffers, for You can use these shortcuts in the headers and view buffers, for
example with `mu4e-mark-for-move-quick' (or 'm', by default) or example with `mu4e-mark-for-move-quick' (or 'm', by default) or
`mu4e-jump-to-maildir' (or 'j', by default), followed by the `mu4e-jump-to-maildir' (or 'j', by default), followed by the
designated shortcut character for the maildir. designated shortcut character for the maildir.
Unlike in search queries, folder names with spaces in them must NOT Unlike in search queries, folder names with spaces in them must
be quoted, since mu4e does this automatically for you." NOT be quoted, since mu4e does this for you."
:type '(repeat (cons (string :tag "Maildir") character)) :type '(repeat (cons (string :tag "Maildir") character))
:group 'mu4e-folders) :group 'mu4e-folders)
(defun mu4e-maildir-shortcuts ()
"Get `mu4e-maildir-shortcuts' in the (new) format, converting
from the old format if needed."
(cl-map 'list
(lambda (item) ;; convert from old format?
(if (and (consp item) (not (consp (cdr item))))
`(:maildir ,(car item) :key ,(cdr item))
item))
mu4e-maildir-shortcuts))
(defcustom mu4e-display-update-status-in-modeline nil (defcustom mu4e-display-update-status-in-modeline nil
"Non-nil value will display the update status in the modeline." "Non-nil value will display the update status in the modeline."
:group 'mu4e :group 'mu4e