mu4e-search: try harder to update baseline
Try to update the query baseline if we're search for the favorite-query, whether as a bookmark or an "organic" query, through a new function mu4e--search-maybe-reset-baseline Note that the query must string-match _exactly_, equivalence is not enough. Some cosmetic updates. Fixes #2775.
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
;;; mu4e-search.el --- Search-related functions -*- lexical-binding: t -*-
|
;;; mu4e-search.el --- Search-related functions -*- lexical-binding: t -*-
|
||||||
|
|
||||||
;; Copyright (C) 2021,2022 Dirk-Jan C. Binnema
|
;; Copyright (C) 2021,2024 Dirk-Jan C. Binnema
|
||||||
|
|
||||||
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
@ -35,7 +35,7 @@
|
|||||||
(require 'mu4e-mark)
|
(require 'mu4e-mark)
|
||||||
(require 'mu4e-query-items)
|
(require 'mu4e-query-items)
|
||||||
|
|
||||||
|
|
||||||
;;; Configuration
|
;;; Configuration
|
||||||
(defgroup mu4e-search nil
|
(defgroup mu4e-search nil
|
||||||
"Search-related settings."
|
"Search-related settings."
|
||||||
@ -115,8 +115,9 @@ chronologically (`:date') by the newest message in the thread."
|
|||||||
:group 'mu4e-search)
|
:group 'mu4e-search)
|
||||||
|
|
||||||
(defcustom mu4e-search-sort-direction 'descending
|
(defcustom mu4e-search-sort-direction 'descending
|
||||||
"Direction to sort by; a symbol either `descending' (sorting
|
"Direction to sort by.
|
||||||
Z->A) or `ascending' (sorting A->Z)."
|
A symbol either `descending' (sorting Z->A) or
|
||||||
|
`ascending' (sorting A->Z)."
|
||||||
:type '(radio (const ascending)
|
:type '(radio (const ascending)
|
||||||
(const descending))
|
(const descending))
|
||||||
:group 'mu4e-search)
|
:group 'mu4e-search)
|
||||||
@ -148,7 +149,7 @@ executed search, not just those that are invoked via bookmarks,
|
|||||||
but also manually invoked searches."
|
but also manually invoked searches."
|
||||||
:type 'hook
|
:type 'hook
|
||||||
:group 'mu4e-search)
|
:group 'mu4e-search)
|
||||||
|
|
||||||
;; Internals
|
;; Internals
|
||||||
|
|
||||||
;;; History
|
;;; History
|
||||||
@ -160,8 +161,6 @@ but also manually invoked searches."
|
|||||||
(defvar mu4e--search-last-query nil
|
(defvar mu4e--search-last-query nil
|
||||||
"The present (most recent) query.")
|
"The present (most recent) query.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;; Interactive functions
|
;;; Interactive functions
|
||||||
(declare-function mu4e--search-execute "mu4e-headers")
|
(declare-function mu4e--search-execute "mu4e-headers")
|
||||||
|
|
||||||
@ -170,6 +169,13 @@ but also manually invoked searches."
|
|||||||
(defvar mu4e--search-msgid-target nil
|
(defvar mu4e--search-msgid-target nil
|
||||||
"Message-id to jump to after the search has finished.")
|
"Message-id to jump to after the search has finished.")
|
||||||
|
|
||||||
|
(defun mu4e--search-maybe-reset-baseline (query)
|
||||||
|
"Reset the baseline if QUERY matches the favorite.
|
||||||
|
Note that the query must match the favorite _exactly_,
|
||||||
|
equivalence is not enough."
|
||||||
|
(when-let* ((fav (mu4e--bookmark-query (mu4e-bookmark-favorite))))
|
||||||
|
(when (and fav (string= fav query))
|
||||||
|
(mu4e--query-items-refresh 'reset-baseline))))
|
||||||
|
|
||||||
(defun mu4e-search (&optional expr prompt edit ignore-history msgid show)
|
(defun mu4e-search (&optional expr prompt edit ignore-history msgid show)
|
||||||
"Search for query EXPR.
|
"Search for query EXPR.
|
||||||
@ -183,7 +189,10 @@ the user edit the query before executing it.
|
|||||||
If IGNORE-HISTORY is true, do *not* update the query history
|
If IGNORE-HISTORY is true, do *not* update the query history
|
||||||
stack. If MSGID is non-nil, attempt to move point to the first
|
stack. If MSGID is non-nil, attempt to move point to the first
|
||||||
message with that message-id after searching. If SHOW is non-nil,
|
message with that message-id after searching. If SHOW is non-nil,
|
||||||
show the message with MSGID."
|
show the message with MSGID.
|
||||||
|
|
||||||
|
Attempts to reset the query baseline if EXPR is an exact match
|
||||||
|
with the favorite bookmark's query."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((prompt (mu4e-format (or prompt "Search for: ")))
|
(let* ((prompt (mu4e-format (or prompt "Search for: ")))
|
||||||
(expr
|
(expr
|
||||||
@ -194,6 +203,7 @@ show the message with MSGID."
|
|||||||
(mu4e--search-execute expr ignore-history)
|
(mu4e--search-execute expr ignore-history)
|
||||||
(setq mu4e--search-msgid-target msgid
|
(setq mu4e--search-msgid-target msgid
|
||||||
mu4e--search-view-target show)
|
mu4e--search-view-target show)
|
||||||
|
(mu4e--search-maybe-reset-baseline expr)
|
||||||
(mu4e--modeline-update)))
|
(mu4e--modeline-update)))
|
||||||
|
|
||||||
(defun mu4e-search-edit ()
|
(defun mu4e-search-edit ()
|
||||||
@ -210,12 +220,7 @@ the search."
|
|||||||
(or expr
|
(or expr
|
||||||
(mu4e-ask-bookmark
|
(mu4e-ask-bookmark
|
||||||
(if edit "Select bookmark: " "Bookmark: "))))
|
(if edit "Select bookmark: " "Bookmark: "))))
|
||||||
(expr (if (functionp expr) (funcall expr) expr))
|
(expr (if (functionp expr) (funcall expr) expr)))
|
||||||
(fav (mu4e--bookmark-query (mu4e-bookmark-favorite))))
|
|
||||||
;; reset baseline when searching for the favorite bookmark query
|
|
||||||
(when (and fav (string= fav expr))
|
|
||||||
(mu4e--query-items-refresh 'reset-baseline))
|
|
||||||
|
|
||||||
(run-hook-with-args 'mu4e-search-bookmark-hook expr)
|
(run-hook-with-args 'mu4e-search-bookmark-hook expr)
|
||||||
(mu4e-search expr (when edit "Edit query: ") edit)))
|
(mu4e-search expr (when edit "Edit query: ") edit)))
|
||||||
|
|
||||||
@ -224,7 +229,6 @@ the search."
|
|||||||
(interactive)
|
(interactive)
|
||||||
(mu4e-search-bookmark nil t))
|
(mu4e-search-bookmark nil t))
|
||||||
|
|
||||||
|
|
||||||
(defun mu4e-search-maildir (maildir &optional edit)
|
(defun mu4e-search-maildir (maildir &optional edit)
|
||||||
"Search the messages in MAILDIR.
|
"Search the messages in MAILDIR.
|
||||||
The user is prompted to ask what maildir. If prefix-argument EDIT
|
The user is prompted to ask what maildir. If prefix-argument EDIT
|
||||||
@ -239,7 +243,7 @@ is given, offer to edit the search query before executing it."
|
|||||||
(mu4e-mark-handle-when-leaving)
|
(mu4e-mark-handle-when-leaving)
|
||||||
(mu4e-search query))))
|
(mu4e-search query))))
|
||||||
|
|
||||||
(defun mu4e-search-narrow(&optional filter)
|
(defun mu4e-search-narrow (&optional filter)
|
||||||
"Narrow the last search.
|
"Narrow the last search.
|
||||||
Do so by appending search expression FILTER to the last search
|
Do so by appending search expression FILTER to the last search
|
||||||
expression. Note that you can go back to the previous
|
expression. Note that you can go back to the previous
|
||||||
@ -328,7 +332,7 @@ either `future' or `past'."
|
|||||||
(defun mu4e-last-query ()
|
(defun mu4e-last-query ()
|
||||||
"Get the most recent query or nil if there is none."
|
"Get the most recent query or nil if there is none."
|
||||||
mu4e--search-last-query)
|
mu4e--search-last-query)
|
||||||
|
|
||||||
;;; Completion for queries
|
;;; Completion for queries
|
||||||
|
|
||||||
(defvar mu4e--search-hist nil "History list of searches.")
|
(defvar mu4e--search-hist nil "History list of searches.")
|
||||||
@ -491,8 +495,7 @@ last search with the new setting."
|
|||||||
(defvar mu4e-search-skip-duplicates-label '("U" . "Ⓤ") ;; 'U' for 'unique'
|
(defvar mu4e-search-skip-duplicates-label '("U" . "Ⓤ") ;; 'U' for 'unique'
|
||||||
"Non-fancy and fancy labels for include-related search in the mode-line.")
|
"Non-fancy and fancy labels for include-related search in the mode-line.")
|
||||||
(defvar mu4e-search-hide-label '("H" . "Ⓗ")
|
(defvar mu4e-search-hide-label '("H" . "Ⓗ")
|
||||||
"Non-fancy and fancy labels to indicate header-hiding is active in
|
"Non-fancy and fancy labels to indicate header-hiding.")
|
||||||
the mode-line.")
|
|
||||||
|
|
||||||
(defun mu4e--search-modeline-item ()
|
(defun mu4e--search-modeline-item ()
|
||||||
"Get mu4e-search modeline item."
|
"Get mu4e-search modeline item."
|
||||||
|
|||||||
Reference in New Issue
Block a user