2023-09-20 21:31:19 +02:00
|
|
|
|
;;; mu4e-bookmarks.el --- Bookmarks handling -*- lexical-binding: t -*-
|
2021-08-29 16:30:10 +02:00
|
|
|
|
|
2023-01-07 14:08:14 +01:00
|
|
|
|
;; Copyright (C) 2011-2023 Dirk-Jan C. Binnema
|
2021-08-29 16:30:10 +02:00
|
|
|
|
|
|
|
|
|
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
|
|
|
|
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
|
|
|
|
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; mu4e is free software: you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; mu4e is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with mu4e. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
(require 'mu4e-helpers)
|
2023-01-07 14:08:14 +01:00
|
|
|
|
(require 'mu4e-modeline)
|
2023-01-09 22:58:10 +01:00
|
|
|
|
(require 'mu4e-folders)
|
|
|
|
|
(require 'mu4e-query-items)
|
2021-08-29 16:30:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Configuration
|
|
|
|
|
|
|
|
|
|
(defgroup mu4e-bookmarks nil
|
|
|
|
|
"Settings for bookmarks."
|
|
|
|
|
:group 'mu4e)
|
|
|
|
|
|
|
|
|
|
(defcustom mu4e-bookmarks
|
|
|
|
|
'(( :name "Unread messages"
|
2023-02-02 22:47:18 +01:00
|
|
|
|
:query "flag:unread AND NOT flag:trashed"
|
|
|
|
|
:key ?u)
|
2021-08-29 16:30:10 +02:00
|
|
|
|
( :name "Today's messages"
|
2023-02-02 22:47:18 +01:00
|
|
|
|
:query "date:today..now"
|
|
|
|
|
:key ?t)
|
2021-08-29 16:30:10 +02:00
|
|
|
|
( :name "Last 7 days"
|
2023-02-02 22:47:18 +01:00
|
|
|
|
:query "date:7d..now"
|
|
|
|
|
:hide-unread t
|
|
|
|
|
:key ?w)
|
2021-08-29 16:30:10 +02:00
|
|
|
|
( :name "Messages with images"
|
2023-02-02 22:47:18 +01:00
|
|
|
|
:query "mime:image/*"
|
|
|
|
|
:key ?p))
|
2021-08-29 16:30:10 +02:00
|
|
|
|
"List of pre-defined queries that are shown on the main screen.
|
|
|
|
|
|
|
|
|
|
Each of the list elements is a plist with at least:
|
|
|
|
|
`:name' - the name of the query
|
2023-03-28 19:57:07 +02:00
|
|
|
|
`:query' - the query expression string or function
|
2023-01-07 14:08:14 +01:00
|
|
|
|
`:key' - the shortcut key (single character)
|
2021-08-29 16:30:10 +02:00
|
|
|
|
|
2023-01-07 14:08:14 +01:00
|
|
|
|
Optionally, you can add the following:
|
2022-01-23 09:29:45 +01:00
|
|
|
|
|
2023-01-07 14:08:14 +01:00
|
|
|
|
- `:favorite' - if t, monitor the results of this query, and make
|
2023-01-14 18:53:48 +01:00
|
|
|
|
it eligible for showing its status in the modeline. At most
|
2023-01-07 14:08:14 +01:00
|
|
|
|
one bookmark should have this set to t (otherwise the _first_
|
2023-01-09 22:58:10 +01:00
|
|
|
|
bookmark is the implicit favorite). The query for the `:favorite'
|
|
|
|
|
item must be unique among `mu4e-bookmarks' and
|
|
|
|
|
`mu4e-maildir-shortcuts'.
|
2023-01-07 14:08:14 +01:00
|
|
|
|
- `:hide' - if t, the bookmark is hidden from the main-view and
|
|
|
|
|
speedbar.
|
|
|
|
|
- `:hide-unread' - do not show the counts of
|
|
|
|
|
unread/total number of matches for the query in the main-view.
|
|
|
|
|
This can be useful if a bookmark uses a very slow query.
|
|
|
|
|
|
|
|
|
|
`:hide-unread' is implied from `:hide'.
|
2022-01-23 09:29:45 +01:00
|
|
|
|
|
|
|
|
|
Note: for efficiency, queries used to determine the unread/all
|
2022-05-12 07:52:10 +02:00
|
|
|
|
counts do not discard duplicate or unreadable messages. Thus, the
|
|
|
|
|
numbers shown may differ from the number you get from a normal
|
|
|
|
|
query."
|
2021-08-29 16:30:10 +02:00
|
|
|
|
:type '(repeat (plist))
|
|
|
|
|
:group 'mu4e-bookmarks)
|
|
|
|
|
|
2023-01-18 23:28:43 +01:00
|
|
|
|
|
2023-01-07 14:08:14 +01:00
|
|
|
|
(defun mu4e-ask-bookmark (prompt)
|
2023-01-09 22:58:10 +01:00
|
|
|
|
"Ask user for bookmark using PROMPT.
|
|
|
|
|
Return the corresponding query. The bookmark are as defined in
|
|
|
|
|
`mu4e-bookmarks'."
|
2021-08-29 16:30:10 +02:00
|
|
|
|
(unless (mu4e-bookmarks) (mu4e-error "No bookmarks defined"))
|
2023-02-14 22:38:24 +01:00
|
|
|
|
(let* ((bmarks (seq-map (lambda (bm)
|
|
|
|
|
(cons (format "%c%s"
|
|
|
|
|
(plist-get bm :key)
|
|
|
|
|
(plist-get bm :name))
|
|
|
|
|
(plist-get bm :query)))
|
|
|
|
|
(mu4e-filter-single-key (mu4e-bookmarks)))))
|
2023-02-15 06:08:39 +01:00
|
|
|
|
(mu4e-read-option prompt bmarks)))
|
2021-08-29 16:30:10 +02:00
|
|
|
|
|
|
|
|
|
(defun mu4e-get-bookmark-query (kar)
|
|
|
|
|
"Get the corresponding bookmarked query for shortcut KAR.
|
|
|
|
|
Raise an error if none is found."
|
2023-01-07 14:08:14 +01:00
|
|
|
|
(let ((chosen-bm
|
|
|
|
|
(or (seq-find
|
|
|
|
|
(lambda (bm)
|
|
|
|
|
(= kar (plist-get bm :key)))
|
|
|
|
|
(mu4e-bookmarks))
|
|
|
|
|
(mu4e-warn "Unknown shortcut '%c'" kar))))
|
|
|
|
|
(mu4e--bookmark-query chosen-bm)))
|
2021-08-29 16:30:10 +02:00
|
|
|
|
|
|
|
|
|
(defun mu4e-bookmark-define (query name key)
|
|
|
|
|
"Define a bookmark for QUERY with NAME and shortcut KEY.
|
|
|
|
|
Append it to `mu4e-bookmarks'. Replaces any existing bookmark
|
|
|
|
|
with KEY."
|
|
|
|
|
(setq mu4e-bookmarks
|
2022-01-23 09:29:45 +01:00
|
|
|
|
(seq-remove
|
2021-08-29 16:30:10 +02:00
|
|
|
|
(lambda (bm)
|
|
|
|
|
(= (plist-get bm :key) key))
|
|
|
|
|
(mu4e-bookmarks)))
|
|
|
|
|
(cl-pushnew `(:name ,name
|
2023-02-02 22:47:18 +01:00
|
|
|
|
:query ,query
|
|
|
|
|
:key ,key)
|
2021-08-29 16:30:10 +02:00
|
|
|
|
mu4e-bookmarks :test 'equal))
|
|
|
|
|
|
|
|
|
|
(defun mu4e-bookmarks ()
|
|
|
|
|
"Get `mu4e-bookmarks' in the (new) format.
|
|
|
|
|
Convert from the old format if needed."
|
2022-01-23 09:29:45 +01:00
|
|
|
|
(seq-map (lambda (item)
|
|
|
|
|
(if (and (listp item) (= (length item) 3))
|
2023-02-02 22:47:18 +01:00
|
|
|
|
`(:name ,(nth 1 item) :query ,(nth 0 item)
|
|
|
|
|
:key ,(nth 2 item))
|
2023-01-07 14:08:14 +01:00
|
|
|
|
item))
|
|
|
|
|
mu4e-bookmarks))
|
|
|
|
|
|
2023-01-09 22:58:10 +01:00
|
|
|
|
(defun mu4e-bookmark-favorite ()
|
|
|
|
|
"Find the favorite bookmark."
|
2023-02-02 22:47:18 +01:00
|
|
|
|
;; note, use query-items, which will have picked a favorite
|
|
|
|
|
;; even if user did not provide one explictly
|
2023-01-07 14:08:14 +01:00
|
|
|
|
(seq-find
|
2023-01-09 22:58:10 +01:00
|
|
|
|
(lambda (item)
|
|
|
|
|
(plist-get item :favorite))
|
|
|
|
|
(mu4e-query-items 'bookmarks)))
|
2023-01-07 14:08:14 +01:00
|
|
|
|
|
|
|
|
|
;; for Zero-Inbox afficionados
|
|
|
|
|
(defvar mu4e-modeline-all-clear '("C:" . "🌀")
|
|
|
|
|
"No more messages at all for this query.")
|
|
|
|
|
(defvar mu4e-modeline-all-read '("R:" . "✅")
|
|
|
|
|
"No unread messages left.")
|
|
|
|
|
(defvar mu4e-modeline-unread-items '("U:" . "📫")
|
|
|
|
|
"There are some unread items.")
|
|
|
|
|
(defvar mu4e-modeline-new-items '("N:" . "🔥")
|
|
|
|
|
"There are some new items after the baseline.
|
|
|
|
|
I.e., very new messages.")
|
|
|
|
|
|
|
|
|
|
(declare-function mu4e-search-bookmark "mu4e-search")
|
|
|
|
|
(defun mu4e-jump-to-favorite ()
|
|
|
|
|
"Jump to to the favorite bookmark, if any."
|
|
|
|
|
(interactive)
|
2023-01-09 22:58:10 +01:00
|
|
|
|
(when-let ((fav (mu4e--bookmark-query (mu4e-bookmark-favorite))))
|
2023-01-07 14:08:14 +01:00
|
|
|
|
(mu4e-search-bookmark fav)))
|
|
|
|
|
|
|
|
|
|
(defun mu4e--bookmarks-modeline-item ()
|
|
|
|
|
"Modeline item showing message counts for the favorite bookmark.
|
|
|
|
|
|
|
|
|
|
This uses the one special ':favorite' bookmark, and if there is
|
|
|
|
|
one, creates a propertized string for display in the modeline."
|
2023-01-08 12:39:42 +01:00
|
|
|
|
(when-let ((fav ;; any results for the favorite bookmark item?
|
|
|
|
|
(seq-find (lambda (bm) (plist-get bm :favorite))
|
2023-01-09 22:58:10 +01:00
|
|
|
|
(mu4e-query-items 'bookmarks))))
|
|
|
|
|
(cl-destructuring-bind (&key unread count delta-unread
|
|
|
|
|
&allow-other-keys) fav
|
2023-01-08 12:39:42 +01:00
|
|
|
|
(propertize
|
2023-01-09 22:58:10 +01:00
|
|
|
|
(format "%s%s "
|
2023-01-08 12:39:42 +01:00
|
|
|
|
(funcall (if mu4e-use-fancy-chars 'cdr 'car)
|
|
|
|
|
(cond
|
2023-01-09 22:58:10 +01:00
|
|
|
|
((> delta-unread 0) mu4e-modeline-new-items)
|
2023-01-08 12:39:42 +01:00
|
|
|
|
((> unread 0) mu4e-modeline-unread-items)
|
|
|
|
|
((> count 0) mu4e-modeline-all-read)
|
|
|
|
|
(t mu4e-modeline-all-clear)))
|
2023-01-09 22:58:10 +01:00
|
|
|
|
(mu4e--query-item-display-counts fav))
|
2023-01-17 20:14:30 +01:00
|
|
|
|
'help-echo
|
|
|
|
|
(format
|
|
|
|
|
(concat
|
|
|
|
|
"mu4e favorite bookmark '%s':\n"
|
|
|
|
|
"\t%s\n\n"
|
|
|
|
|
"number of matches: %d\n"
|
|
|
|
|
"unread messages: %d\n"
|
|
|
|
|
"changes since baseline: %+d\n")
|
|
|
|
|
(plist-get fav :name)
|
|
|
|
|
(mu4e--bookmark-query fav)
|
2023-02-02 22:47:18 +01:00
|
|
|
|
count unread delta-unread)
|
2023-01-08 12:39:42 +01:00
|
|
|
|
'mouse-face 'mode-line-highlight
|
|
|
|
|
'keymap '(mode-line keymap
|
2023-01-17 20:14:30 +01:00
|
|
|
|
(mouse-1 . mu4e-jump-to-favorite)
|
|
|
|
|
(mouse-2 . mu4e-jump-to-favorite)
|
|
|
|
|
(mouse-3 . mu4e-jump-to-favorite))))))
|
2021-08-29 16:30:10 +02:00
|
|
|
|
|
|
|
|
|
(provide 'mu4e-bookmarks)
|
|
|
|
|
;;; mu4e-bookmarks.el ends here
|