mirror of
https://github.com/djcb/mu.git
synced 2024-06-28 07:41:04 +02:00
Merge pull request #1338 from ibizaman/bookmark-function
mu4e: allow :query to accept a function returning a query string
This commit is contained in:
commit
e6c24c28a3
|
@ -454,7 +454,9 @@ KAR, or raise an error if none is found."
|
||||||
(mu4e-bookmarks))
|
(mu4e-bookmarks))
|
||||||
(mu4e-warn "Unknown shortcut '%c'" kar)))
|
(mu4e-warn "Unknown shortcut '%c'" kar)))
|
||||||
(expr (mu4e-bookmark-query chosen-bm))
|
(expr (mu4e-bookmark-query chosen-bm))
|
||||||
(query (eval expr)))
|
(expr (if (not (functionp expr)) expr
|
||||||
|
(funcall expr)))
|
||||||
|
(query (eval expr)))
|
||||||
(if (stringp query)
|
(if (stringp query)
|
||||||
query
|
query
|
||||||
(mu4e-warn "Expression must evaluate to query string ('%S')" expr))))
|
(mu4e-warn "Expression must evaluate to query string ('%S')" expr))))
|
||||||
|
|
|
@ -2012,10 +2012,11 @@ 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
|
bookmark we just defined (to get the list of "Big Messages"), all you need to
|
||||||
type is @kbd{bb}.
|
type is @kbd{bb}.
|
||||||
|
|
||||||
@subsection Lisp expressions as bookmarks
|
@subsection Lisp expressions or functions as bookmarks
|
||||||
|
|
||||||
Instead of using strings, it is also possible to use Lisp expressions as
|
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.
|
bookmarks. Either the expression evaluates to a query string or the expression
|
||||||
|
is a function taking no argument that returns a query string.
|
||||||
|
|
||||||
For example, to get all the messages that are at most a week old in your
|
For example, to get all the messages that are at most a week old in your
|
||||||
inbox:
|
inbox:
|
||||||
|
@ -2024,12 +2025,31 @@ inbox:
|
||||||
(add-to-list 'mu4e-bookmarks
|
(add-to-list 'mu4e-bookmarks
|
||||||
(make-mu4e-bookmark
|
(make-mu4e-bookmark
|
||||||
:name "Inbox messages in the last 7 days"
|
:name "Inbox messages in the last 7 days"
|
||||||
:query (concat "maildir:/inbox AND date:"
|
:query (lambda () (concat "maildir:/inbox AND date:"
|
||||||
(format-time-string "%Y%m%d"
|
(format-time-string "%Y%m%d"
|
||||||
(subtract-time (current-time) (days-to-time 7))))
|
(subtract-time (current-time) (days-to-time 7)))))
|
||||||
:key ?w) t)
|
:key ?w) t)
|
||||||
@end lisp
|
@end lisp
|
||||||
|
|
||||||
|
Another example where the user is prompted how many days old messages should be
|
||||||
|
shown:
|
||||||
|
|
||||||
|
@lisp
|
||||||
|
(defun my/mu4e-bookmark-num-days-old-query (days-old)
|
||||||
|
(interactive (list (read-number "Show days old messages: " 7)))
|
||||||
|
(let ((start-date (subtract-time (current-time) (days-to-time days-old))))
|
||||||
|
(concat "maildir:/inbox AND date:"
|
||||||
|
(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)
|
||||||
|
@end lisp
|
||||||
|
|
||||||
|
It is defining a function to make the code more readable.
|
||||||
|
|
||||||
@subsection Editing bookmarks before searching
|
@subsection Editing bookmarks before searching
|
||||||
|
|
||||||
There is also @kbd{M-x mu4e-headers-search-bookmark-edit} (key @key{B}), which
|
There is also @kbd{M-x mu4e-headers-search-bookmark-edit} (key @key{B}), which
|
||||||
|
|
Loading…
Reference in New Issue
Block a user