From d5129052df2b1db020465f84ec9c180a3e980405 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 9 Aug 2023 19:55:52 +0300 Subject: [PATCH] mu4e: implement mu4e-search-query Pick a query using completing-read with a new command mu4e-search-query. Update docs. --- NEWS.org | 18 +++++++++++------- mu4e/mu4e-main.el | 3 ++- mu4e/mu4e-query-items.el | 2 +- mu4e/mu4e-search.el | 36 +++++++++++++++++++++++++++++++++++- mu4e/mu4e.texi | 2 ++ 5 files changed, 51 insertions(+), 10 deletions(-) diff --git a/NEWS.org b/NEWS.org index d663f630..c11f7541 100644 --- a/NEWS.org +++ b/NEWS.org @@ -45,6 +45,10 @@ *** mu4e + - New command ~mu4e-search-query~ (bound to =c=) which lets you pick a query + (from bookmark / maildir shortcuts) with completion in main / headers / + view buffers. + - improved support for dealing with attachments and other MIME-parts in the message view; they gained completions support with annotations in the minibuffer @@ -65,14 +69,14 @@ for some (selected) mailing-list archives. - ~mu4e-quit~ now takes a prefix argument which, if provided, causes it to - bury he mu main buffer, rather than quitting mu. ~mu4e~ will now just switch - the mu4e buffer if it exists (otherwise it starts ~mu4e~). + bury the mu main buffer, rather than quitting mu. ~mu4e~ will now just + switch the mu4e buffer if it exists (otherwise it starts ~mu4e~). - - ~mu4e~ benefits from the mentioned speed-ups in querying, and adds some of - its own - e.g., for showing 500 messages (debug build), we went from 642ms - to 247ms. Note, the optimizations are experimental, and for now you can - turn them off by setting =mu4e-mu-allow-temp-file= to =nil= (and restart - ~mu4e~); and reporting. + - ~mu4e~ queries are much snappier now. ~mu4e~ benefits from the mentioned + speed-ups in querying, and adds some of its own - e.g., for showing 500 + messages (debug build), we went from 642ms to 247ms. Note, the + optimizations are experimental, and for now you can turn them off by + setting =mu4e-mu-allow-temp-file= to =nil= (and restart ~mu4e~); and reporting. - after retrieving mail (~mu4e-update-mail-and-index~), save the output of the retrieval command in a buffer =*mu4e-last-update*=, = which can be useful diff --git a/mu4e/mu4e-main.el b/mu4e/mu4e-main.el index 3bc06524..eaf15389 100644 --- a/mu4e/mu4e-main.el +++ b/mu4e/mu4e-main.el @@ -315,7 +315,8 @@ Otherwise, do nothing." (mu4e--main-items 'maildirs max-length) "\n" (propertize " Misc\n\n" 'face 'mu4e-title-face) - + (mu4e--main-action "\t* [@]Choose query\n" + #'mu4e-search-query nil "c") (mu4e--main-action "\t* [@]Switch context\n" #'mu4e-context-switch nil ";") (mu4e--main-action "\t* [@]Update email & database\n" diff --git a/mu4e/mu4e-query-items.el b/mu4e/mu4e-query-items.el index 745b91b8..a86a87a2 100644 --- a/mu4e/mu4e-query-items.el +++ b/mu4e/mu4e-query-items.el @@ -80,7 +80,7 @@ the latest query-items.") (unless (stringp query) (mu4e-warn "Could not get query string from %s" bm)) ;; apparently, non-UTF8 queries exist, i.e., - ;; with maild dir names. + ;; with maildir names. (decode-coding-string query 'utf-8 t)))) (defun mu4e--query-items-pick-favorite (items) diff --git a/mu4e/mu4e-search.el b/mu4e/mu4e-search.el index eaed0c1f..1aedf322 100644 --- a/mu4e/mu4e-search.el +++ b/mu4e/mu4e-search.el @@ -217,7 +217,7 @@ the search." (mu4e--query-items-refresh 'reset-baseline)) (run-hook-with-args 'mu4e-search-bookmark-hook expr) - (mu4e-search expr (when edit "Edit bookmark: ") edit))) + (mu4e-search expr (when edit "Edit query: ") edit))) (defun mu4e-search-bookmark-edit () "Edit an existing bookmark before executing it." @@ -547,6 +547,36 @@ the mode-line.") 'help-echo (format "mu4e query:\n\t%s" mu4e--search-last-query)) "]"))) +(defun mu4e-search-query (&optional edit) + "Select a search query through `completing-read'. + +If prefix-argument EDIT is non-nil, allow for editing the chosen +query before submitting it." + (interactive "P") + (let* ((candidates (seq-map (lambda (item) + (cons (plist-get item :name) item)) + (mu4e-query-items))) + (longest-name + (seq-max (seq-map (lambda (c) (length (car c))) candidates))) + (longest-query + (seq-max (seq-map (lambda (c) (length (plist-get (cdr c) :query))) + candidates))) + + (annotation-func + (lambda (candidate) + (let* ((item (cdr-safe (assoc candidate candidates))) + (name (propertize (or (plist-get item :name) "") + 'face 'mu4e-header-key-face)) + (query (propertize (or (plist-get item :query) "") + 'face 'mu4e-header-value-face))) + (concat + " " + (make-string (- longest-name (length name)) ?\s) + query)))) + (completion-extra-properties + `(:annotation-function ,annotation-func))) + (mu4e-search-bookmark (completing-read "Query: " candidates) edit))) + (define-minor-mode mu4e-search-minor-mode "Mode for searching for messages." :global nil @@ -569,6 +599,8 @@ the mode-line.") (define-key map "b" #'mu4e-search-bookmark) (define-key map "B" #'mu4e-search-bookmark-edit) + (define-key map "c" #'mu4e-search-query) + (define-key map "j" #'mu4e-search-maildir) map)) @@ -580,6 +612,8 @@ the mode-line.") :help "Show messages matching some bookmark query"] ["Search maildir" mu4e-search-maildir :help "Show messages in some maildir"] + ["Choose query" mu4e-search-query + :help "Show messages for some query"] ["Previous query" mu4e-search-prev :help "Run previous query"] ["Next query" mu4e-search-next diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index 0a5ae0b5..bd1e6426 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -987,6 +987,7 @@ S edit last query / narrow the search b search bookmark B edit bookmark before search +c search query with completion j jump to maildir M-left,\ previous query M-right next query @@ -1362,6 +1363,7 @@ S edit last query / narrow the search b search bookmark B edit bookmark before search +c search query with completion j jump to maildir O change sort order