From 190ace557478253f16f713faea0c5676cdd4ecda Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 17 Jan 2023 19:47:55 +0200 Subject: [PATCH] mu4e: show bookmark name in modeline ... if there's a bookmark matching the current query. Controllable through mu4e-modeline-prefer-bookmark-name. Fixes #1318. --- mu4e/mu4e-modeline.el | 8 ++++++++ mu4e/mu4e-search.el | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/mu4e/mu4e-modeline.el b/mu4e/mu4e-modeline.el index 8eb4aab1..2d8b1901 100644 --- a/mu4e/mu4e-modeline.el +++ b/mu4e/mu4e-modeline.el @@ -40,6 +40,14 @@ the search properties and the last query), not the global items :type 'integer :group 'mu4e-modeline) +(defcustom mu4e-modeline-prefer-bookmark-name t + "Show bookmark name rather than query in modeline. + +If non-nil, if the current search query matches some bookmark, +display the bookmark name rather than the query." + :type 'boolean + :group 'mu4e-modeline) + (defvar-local mu4e--modeline-buffer-items nil "List of buffer-local items for the mu4e modeline. Each element is function that evaluates to a string.") diff --git a/mu4e/mu4e-search.el b/mu4e/mu4e-search.el index e736a3da..77631ddd 100644 --- a/mu4e/mu4e-search.el +++ b/mu4e/mu4e-search.el @@ -499,7 +499,17 @@ the mode-line.") "Skip duplicate messages") (,mu4e-search-hide-enabled ,mu4e-search-hide-label - "Enable message hide predicate")))) + "Enable message hide predicate"))) + ;; can we fin find a bookmark corresponding + ;; with this query? + (bookmark + (and mu4e-modeline-prefer-bookmark-name + (seq-find (lambda (item) + (string= + mu4e--search-last-query + (or (plist-get item :effective-query) + (plist-get item :query)))) + (mu4e-query-items 'bookmarks))))) (concat (propertize (mapconcat @@ -516,7 +526,9 @@ the mode-line.") props "\n"))) " [" (propertize - mu4e--search-last-query + (if bookmark ;; show the bookmark name instead of the query? + (plist-get bookmark :name) + mu4e--search-last-query) 'face 'mu4e-title-face 'help-echo (format "mu4e query:\n\t%s" mu4e--search-last-query)) "]")))