From 823d80f0754a2599af8f546ecb6b1a39ab44875d Mon Sep 17 00:00:00 2001 From: djcb Date: Mon, 1 Dec 2014 23:29:40 +0200 Subject: [PATCH] mu4e: allow lisp expressions for bookmarks based on an idea by davidcsterratt --- mu4e/mu4e-utils.el | 21 +++++++++++++-------- mu4e/mu4e.texi | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/mu4e/mu4e-utils.el b/mu4e/mu4e-utils.el index 4b11399b..93437880 100644 --- a/mu4e/mu4e-utils.el +++ b/mu4e/mu4e-utils.el @@ -375,14 +375,19 @@ and offer to create it if it does not exist yet." (defun mu4e-get-bookmark-query (kar) "Get the corresponding bookmarked query for shortcut character KAR, or raise an error if none is found." - (let ((chosen-bm - (find-if - (lambda (bm) - (= kar (nth 2 bm))) - mu4e-bookmarks))) - (if chosen-bm - (nth 0 chosen-bm) - (mu4e-warn "Unknown shortcut '%c'" kar)))) + (let* ((chosen-bm + (or (find-if + (lambda (bm) + (= kar (nth 2 bm))) + mu4e-bookmarks) + (mu4e-warn "Unknown shortcut '%c'" kar))) + (expr (nth 0 chosen-bm)) + (query (eval expr))) + (if (stringp query) + query + (mu4e-warn "Expression must evaluate to query string ('%S')" expr)))) + + ;;; converting flags->string and vice-versa ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index 62952521..32a5b353 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -1862,6 +1862,23 @@ defined in the echo area, with the shortcut key highlighted. So, to invoke the bookmark we just defined (to get the list of "Big Messages"), all you need to type is @kbd{bb}. +@subsection Lisp expressions as bookmarks + +Instead of using strings, it is also possible to use Lisp expressions as +bookmarks. The only requirement is that they evaluate to a query string. + +For example, to get all the messages that are at least a week old in +your inbox: + +@lisp +(add-to-list 'mu4e-bookmarks '( + (concat "maildir:/inbox date:.." + (format-time-string "%Y%m%d" + (subtract-time (current-time) (days-to-time 7)))) + "Messages older than a week" ?O) t) +@end lisp + + @subsection Editing bookmarks before searching There is also @kbd{M-x mu4e-headers-search-bookmark-edit} (key @key{B}), which