diff --git a/mu4e/mu4e-main.el b/mu4e/mu4e-main.el index ad6dd280..6ea6657d 100644 --- a/mu4e/mu4e-main.el +++ b/mu4e/mu4e-main.el @@ -143,9 +143,9 @@ clicked." (mapconcat (lambda (bm) (mu4e~main-action-str - (concat "\t* [b" (make-string 1 (mu4e-bookmark-key bm)) "] " - (mu4e-bookmark-name bm)) - (concat "b" (make-string 1 (mu4e-bookmark-key bm))))) + (concat "\t* [b" (make-string 1 (plist-get bm :key)) "] " + (plist-get bm :name)) + (concat "b" (make-string 1 (plist-get bm :key))))) (mu4e-bookmarks) "\n") "\n\n" (propertize " Misc\n\n" 'face 'mu4e-title-face) diff --git a/mu4e/mu4e-speedbar.el b/mu4e/mu4e-speedbar.el index 4849373d..1aa65d7f 100644 --- a/mu4e/mu4e-speedbar.el +++ b/mu4e/mu4e-speedbar.el @@ -99,11 +99,11 @@ (interactive) (mapcar (lambda (bookmark) (speedbar-insert-button - (concat " " (mu4e-bookmark-name bookmark)) + (concat " " (plist-get bookmark :name)) 'mu4e-highlight-face 'highlight 'mu4e~speedbar-bookmark - (mu4e-bookmark-query bookmark))) + (plist-get bookmark :query))) (mu4e-bookmarks))) (defun mu4e~speedbar-bookmark (&optional _text token _ident) diff --git a/mu4e/mu4e-utils.el b/mu4e/mu4e-utils.el index 1dbfe0f9..d9136a8d 100644 --- a/mu4e/mu4e-utils.el +++ b/mu4e/mu4e-utils.el @@ -397,20 +397,16 @@ and offer to create it if it does not exist yet." mdir)) (defun mu4e-bookmarks () - "Get `mu4e-bookmarks' in the (new) format, converting from the old -format if needed." + "Get `mu4e-bookmarks' in the (new) format, converting from the +old format if needed." (cl-map 'list (lambda (item) - (if (mu4e-bookmark-p item) - item ;; already in the right format - (if (and (listp item) (= (length item) 3)) - (make-mu4e-bookmark - :name (nth 1 item) - :query (nth 0 item) - :key (nth 2 item)) - (mu4e-error "Invalid bookmark in mu4e-bookmarks")))) - mu4e-bookmarks)) - + (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 &optional kar) "Ask the user for a bookmark (using PROMPT) as defined in @@ -421,10 +417,10 @@ format if needed." (mapconcat (lambda (bm) (concat - "[" (propertize (make-string 1 (mu4e-bookmark-key bm)) + "[" (propertize (make-string 1 (plist-get bm :key)) 'face 'mu4e-highlight-face) "]" - (mu4e-bookmark-name bm))) (mu4e-bookmarks) ", ")) + (plist-get bm :name))) (mu4e-bookmarks) ", ")) (kar (read-char (concat prompt bmarks)))) (mu4e-get-bookmark-query kar))) @@ -434,10 +430,10 @@ KAR, or raise an error if none is found." (let* ((chosen-bm (or (cl-find-if (lambda (bm) - (= kar (mu4e-bookmark-key bm))) + (= kar (plist-get bm :key))) (mu4e-bookmarks)) (mu4e-warn "Unknown shortcut '%c'" kar))) - (expr (mu4e-bookmark-query chosen-bm)) + (expr (plist-get chosen-bm :query)) (expr (if (not (functionp expr)) expr (funcall expr))) (query (eval expr))) @@ -453,14 +449,12 @@ replaces any existing bookmark with KEY." (setq mu4e-bookmarks (cl-remove-if (lambda (bm) - (= (mu4e-bookmark-key bm) key)) - (mu4e-bookmarks))) - (cl-pushnew (make-mu4e-bookmark - :name name - :query query - :key key) - mu4e-bookmarks - :test 'equal)) + (= (plist-get bm :key) key)) + (mu4e-bookmarks))) + (cl-pushnew `(:name ,name + :query ,query + :key ,key) + mu4e-bookmarks :test 'equal)) ;;; converting flags->string and vice-versa ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/mu4e/mu4e-vars.el b/mu4e/mu4e-vars.el index 179d587b..ce414a6f 100644 --- a/mu4e/mu4e-vars.el +++ b/mu4e/mu4e-vars.el @@ -201,41 +201,36 @@ If the string exceeds this limit, it will be truncated to fit." (defvar mu4e-debug nil "When set to non-nil, log debug information to the *mu4e-log* buffer.") -(cl-defstruct mu4e-bookmark - "A mu4e bookmarl object with the following members: +;; for backward compatibility, when a bookmark was defined with defstruct. +(cl-defun make-mu4e-bookmark (&key name query key) + "Create a mu4e proplist with the following elements: - `name': the user-visible name of the bookmark - `key': a single key to search for this bookmark - `query': the query for this bookmark. Either a literal string or a function that evaluates to a string." - name ;; name/description of the bookmark - query ;; a query (a string or a function evaluation to string) - key ;; key to activate the bookmark - ) + `(:name ,name :query ,query :key ,key)) (defcustom mu4e-bookmarks - `( ,(make-mu4e-bookmark - :name "Unread messages" - :query "flag:unread AND NOT flag:trashed" - :key ?u) - ,(make-mu4e-bookmark - :name "Today's messages" - :query "date:today..now" - :key ?t) - ,(make-mu4e-bookmark - :name "Last 7 days" - :query "date:7d..now" - :key ?w) - ,(make-mu4e-bookmark - :name "Messages with images" - :query "mime:image/*" - :key ?p)) - "A list of pre-defined queries. -These will show up in the main screen. Each of the list elements -is a three-element list of the form (QUERY DESCRIPTION KEY), -where QUERY is a string with a mu query, DESCRIPTION is a short -description of the query (this will show up in the UI), and KEY -is a shortcut key for the query." - :type '(repeat (list (string :tag "Query") + '(( :name "Unread messages" + :query "flag:unread AND NOT flag:trashed" + :key ?u) + ( :name "Today's messages" + :query "date:today..now" + :key ?t) + ( :name "Last 7 days" + :query "date:7d..now" + :key ?w) + ( :name "Messages with images" + :query "mime:image/*" + :key ?p)) + "List of pre-defined queries that are shown on the main screen. + +Each of the list elements is a plist with +three-element list of the +form (QUERY DESCRIPTION KEY), where QUERY is a string with a mu +query, DESCRIPTION is a short description of the query (this will +show up in the UI), and KEY is a shortcut key for the query." + :type '(repeat (plist (string :tag "Query") (string :tag "Description") character)) :group 'mu4e) diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index f16451f4..da3c304c 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -1962,25 +1962,21 @@ mu4e-search-bookmark-edit}) which lets you edit the bookmark first. @subsection Setting up bookmarks -@t{mu4e} provides a number of default bookmarks. Their definition is -instructive: +@t{mu4e} provides a number of default bookmarks. Their definition may +be instructive: @lisp (defvar mu4e-bookmarks - `( ,(make-mu4e-bookmark - :name "Unread messages" + '( ( :name "Unread messages" :query "flag:unread AND NOT flag:trashed" :key ?u) - ,(make-mu4e-bookmark - :name "Today's messages" + ( :name "Today's messages" :query "date:today..now" :key ?t) - ,(make-mu4e-bookmark - :name "Last 7 days" + ( :name "Last 7 days" :query "date:7d..now" :key ?w) - ,(make-mu4e-bookmark - :name "Messages with images" + ( :name "Messages with images" :query "mime:image/*" :key ?p)) "A list of pre-defined queries. Each query is represented by a @@ -1997,10 +1993,9 @@ You can replace these or add your own items, by putting in your configuration (@file{~/.emacs}) something like: @lisp (add-to-list 'mu4e-bookmarks - (make-mu4e-bookmark - :name "Big messages" - :query "size:5M..500M" - :key ?b)) + '( :name "Big messages" + :query "size:5M..500M" + :key ?b)) @end lisp This prepends your bookmark to the list, and assigns the key @key{b} to it. If @@ -2023,12 +2018,11 @@ inbox: @lisp (add-to-list 'mu4e-bookmarks - (make-mu4e-bookmark - :name "Inbox messages in the last 7 days" - :query (lambda () (concat "maildir:/inbox AND date:" - (format-time-string "%Y%m%d" + '( :name "Inbox messages in the last 7 days" + :query (lambda () (concat "maildir:/inbox AND date:" + (format-time-string "%Y%m%d" (subtract-time (current-time) (days-to-time 7))))) - :key ?w) t) + :key ?w) t) @end lisp Another example where the user is prompted how many days old messages should be @@ -2042,10 +2036,9 @@ shown: (format-time-string "%Y%m%d" start-date)))) (add-to-list 'mu4e-bookmarks - (make-mu4e-bookmark - :name "Inbox messages in the last 7 days" - :query (lambda () (call-interactively 'my/mu4e-bookmark-num-days-old-query)) - :key ?o) t) + `(:name "Inbox messages in the last 7 days" + :query ,(lambda () (call-interactively 'my/mu4e-bookmark-num-days-old-query)) + :key ?o) t) @end lisp It is defining a function to make the code more readable.