mu4e: headers/search refactor search a bit

Move some items from mu4e-headers (mu4e--search-execute) to mu4e-search. The
code in mu4e-headers should focus on the output, and mu4e-search on the search
itself.
This commit is contained in:
Dirk-Jan C. Binnema
2025-05-22 08:55:51 +03:00
parent f75e1203d4
commit 3e05452343
2 changed files with 15 additions and 16 deletions

View File

@ -800,15 +800,13 @@ present, don't do anything."
If so, do not attempt to switch buffers. This variable is to be let-bound If so, do not attempt to switch buffers. This variable is to be let-bound
to t before \"automatic\" searches.") to t before \"automatic\" searches.")
(defun mu4e--search-execute (expr ignore-history) (defun mu4e--search-execute (expr &optional _ignore-history)
"Search for query EXPR. "Search for query EXPR.
Switch to the output buffer for the results. If IGNORE-HISTORY is Switch to the output buffer for the results."
true, do *not* update the query history stack."
(let* ((buf (mu4e-get-headers-buffer nil t)) (let* ((buf (mu4e-get-headers-buffer nil t))
(view-window mu4e~headers-view-win) (view-window mu4e~headers-view-win)
(inhibit-read-only t) (inhibit-read-only t)
(rewritten-expr (funcall mu4e-query-rewrite-function expr))
(maxnum (unless mu4e-search-full mu4e-search-results-limit))) (maxnum (unless mu4e-search-full mu4e-search-results-limit)))
(with-current-buffer buf (with-current-buffer buf
;; NOTE: this resets all buffer-local variables, including ;; NOTE: this resets all buffer-local variables, including
@ -816,13 +814,8 @@ true, do *not* update the query history stack."
;; headers buffer already exists when `mu4e-get-headers-buffer' ;; headers buffer already exists when `mu4e-get-headers-buffer'
;; is called. ;; is called.
(mu4e-headers-mode) (mu4e-headers-mode)
(setq mu4e~headers-view-win view-window) (setq mu4e~headers-view-win view-window
(unless ignore-history list-buffers-directory expr)
;; save the old present query to the history list
(when mu4e--search-last-query
(mu4e--search-push-query mu4e--search-last-query 'past)))
(setq mu4e--search-last-query rewritten-expr)
(setq list-buffers-directory rewritten-expr)
(mu4e--modeline-update)) (mu4e--modeline-update))
;; when the buffer is already visible, select it; otherwise, ;; when the buffer is already visible, select it; otherwise,
@ -833,7 +826,7 @@ true, do *not* update the query history stack."
(mu4e~headers-clear mu4e~search-message) (mu4e~headers-clear mu4e~search-message)
(setq mu4e~headers-search-start (float-time)) (setq mu4e~headers-search-start (float-time))
(mu4e--server-find (mu4e--server-find
rewritten-expr expr
mu4e-search-threads mu4e-search-threads
mu4e-search-sort-field mu4e-search-sort-field
mu4e-search-sort-direction mu4e-search-sort-direction

View File

@ -202,13 +202,19 @@ with the favorite bookmark's query."
(expr (expr
(if (or (null expr) edit) (if (or (null expr) edit)
(mu4e-search-read-query prompt expr) (mu4e-search-read-query prompt expr)
expr))) expr))
(expr (if mu4e-query-rewrite-function ;; rewrite?
(funcall mu4e-query-rewrite-function expr) expr)))
(mu4e-mark-handle-when-leaving) (mu4e-mark-handle-when-leaving)
(mu4e--search-execute expr ignore-history) ;; save the old present query to the history list?
(unless ignore-history
(when mu4e--search-last-query
(mu4e--search-push-query mu4e--search-last-query 'past)))
(mu4e--search-execute expr)
(setq mu4e--search-msgid-target msgid (setq mu4e--search-msgid-target msgid
mu4e--search-last-query expr
mu4e--search-view-target show) mu4e--search-view-target show)
(mu4e--search-maybe-reset-baseline expr) (mu4e--search-maybe-reset-baseline expr)))
(mu4e--modeline-update)))
(defun mu4e-search-edit () (defun mu4e-search-edit ()
"Edit the last search expression." "Edit the last search expression."