From 74d40f4d20a0e9e937a758f3458f6eebe1e21763 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 25 Feb 2020 21:20:51 +0200 Subject: [PATCH] mu4e: make mu4e-maildir-shortcuts a plist Similar to mu4e-bookmarks. --- mu4e/mu4e-utils.el | 39 +++++++++++++------------------------- mu4e/mu4e-vars.el | 47 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 31 deletions(-) diff --git a/mu4e/mu4e-utils.el b/mu4e/mu4e-utils.el index 3c056f6d..1dd38c43 100644 --- a/mu4e/mu4e-utils.el +++ b/mu4e/mu4e-utils.el @@ -357,35 +357,35 @@ the list of maildirs will not change until you restart mu4e." mu4e-maildir-list) (defun mu4e-ask-maildir (prompt) - "Ask the user for a shortcut (using PROMPT) as defined in -`mu4e-maildir-shortcuts', then return the corresponding folder + "Ask the user for a shortcut (using PROMPT) as per +(mu4e-maildir-shortcuts), then return the corresponding folder name. If the special shortcut 'o' (for _o_ther) is used, or if -`mu4e-maildir-shortcuts' is not defined, let user choose from all -maildirs under `mu4e-maildir'." +`(mu4e-maildir-shortcuts)' evaluates to nil, let user choose from +all maildirs under `mu4e-maildir'." (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)) - (let* ((mlist (append mu4e-maildir-shortcuts '(("ther" . ?o)))) + (let* ((mlist (append (mu4e-maildir-shortcuts) + '((:maildir "ther" :key ?o)))) (fnames (mapconcat (lambda (item) (concat "[" - (propertize (make-string 1 (cdr item)) + (propertize (make-string 1 (plist-get item :key)) 'face 'mu4e-highlight-face) "]" - (car item))) + (plist-get item :maildir))) mlist ", ")) (kar (read-char (concat prompt fnames)))) (if (member kar '(?/ ?o)) ;; user chose 'other'? (funcall mu4e-completing-read-function prompt (mu4e-get-maildirs) nil nil "/") - (or (car-safe - (cl-find-if (lambda (item) (= kar (cdr item))) - mu4e-maildir-shortcuts)) + (or (plist-get + (cl-find-if (lambda (item) (= kar (plist-get item :key))) + (mu4e-maildir-shortcuts)) :maildir) (mu4e-warn "Unknown shortcut '%c'" kar))))))) - (defun mu4e-ask-maildir-check-exists (prompt) "Like `mu4e-ask-maildir', but check for existence of the maildir, 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)) ;;; Bookmarks - -(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) + (defun mu4e-ask-bookmark (prompt) "Ask the user for a bookmark (using PROMPT) as defined in `mu4e-bookmarks', then return the corresponding query." (unless (mu4e-bookmarks) (mu4e-error "No bookmarks defined")) diff --git a/mu4e/mu4e-vars.el b/mu4e/mu4e-vars.el index f388e636..cc5252a1 100644 --- a/mu4e/mu4e-vars.el +++ b/mu4e/mu4e-vars.el @@ -233,6 +233,20 @@ bookmarks depend on that, the results may differ." :type '(repeat (plist)) :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 "How to show messages / headers. A symbol which is either: @@ -527,20 +541,43 @@ nil otherwise." "A list of maildir shortcuts. This makes it possible to quickly go to a particular maildir (folder), or quickly moving messages to them (e.g., for -archiving or refiling). The list contains elements of the -form (maildir . shortcut), where MAILDIR is a maildir (such as -\"/archive/\"), and shortcut is a single character. +archiving or refiling). + +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 example with `mu4e-mark-for-move-quick' (or 'm', by default) or `mu4e-jump-to-maildir' (or 'j', by default), followed by the designated shortcut character for the maildir. -Unlike in search queries, folder names with spaces in them must NOT -be quoted, since mu4e does this automatically for you." +Unlike in search queries, folder names with spaces in them must +NOT be quoted, since mu4e does this for you." :type '(repeat (cons (string :tag "Maildir") character)) :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 "Non-nil value will display the update status in the modeline." :group 'mu4e