From 5713a18374cfde91ce372d8c526531cdfbfaa991 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 15 Jan 2023 16:09:40 +0200 Subject: [PATCH] mu4e: apply query-rewrite-function to query-items too Some users depend on this. --- mu4e/mu4e-query-items.el | 24 ++++++++++++++++++++++++ mu4e/mu4e-search.el | 23 ++--------------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/mu4e/mu4e-query-items.el b/mu4e/mu4e-query-items.el index 004da729..96eba8ef 100644 --- a/mu4e/mu4e-query-items.el +++ b/mu4e/mu4e-query-items.el @@ -34,6 +34,29 @@ (require 'mu4e-helpers) (require 'mu4e-server) + +(defcustom mu4e-query-rewrite-function 'identity + "Function to rewrite a query. + +It takes a search expression string, and returns a possibly + changed search expression string. + +This function is applied on the search expression just before +searching, and allows users to modify the query. + +For instance, we could change and of workmail into +\"maildir:/long-path-to-work-related-emails\", by setting the function + +(setq mu4e-query-rewrite-function + (lambda(expr) + (replace-regexp-in-string \"workmail\" + \"maildir:/long-path-to-work-related-emails\" expr))) + +It is good to remember that the replacement does not understand +anything about the query, it just does text replacement." + :type 'function + :group 'mu4e-search) + (defvar mu4e--query-items-baseline nil "Some previous version of the query-items. This is used as the baseline to track updates by comparing it to @@ -151,6 +174,7 @@ bookmark or maildir." (name (plist-get item :name)) ;; maildir items may have an implicit name ;; which is the maildir value. + (query (funcall mu4e-query-rewrite-function query)) (name (or name (and (equal type 'maildirs) maildir))) (last-results (mu4e-server-query-items)) diff --git a/mu4e/mu4e-search.el b/mu4e/mu4e-search.el index 9b57f071..2a047b36 100644 --- a/mu4e/mu4e-search.el +++ b/mu4e/mu4e-search.el @@ -114,27 +114,8 @@ chronologically (`:date') by the newest message in the thread." :type 'symbol :group 'mu4e-search) -(defcustom mu4e-query-rewrite-function 'identity - "Function to rewrite a query. - -It takes a search expression string, and returns a possibly - changed search expression string. - -This function is applied on the search expression just before -searching, and allows users to modify the query. - -For instance, we could change and of workmail into -\"maildir:/long-path-to-work-related-emails\", by setting the function - -(setq mu4e-query-rewrite-function - (lambda(expr) - (replace-regexp-in-string \"workmail\" - \"maildir:/long-path-to-work-related-emails\" expr))) - -It is good to remember that the replacement does not understand -anything about the query, it just does text replacement." - :type 'function - :group 'mu4e-search) +;; mu4e-query-rewrite-function lives in mu4e-query-items.el +;; to avoid circular deps. (defcustom mu4e-search-bookmark-hook nil "Hook run just after invoking a bookmarked search.