mu4e: implement mu4e-emacs-bookmark-policy

Allow for creating Emacs bookmarks for either messages (as before & the
default), queries or as the user.
This commit is contained in:
Dirk-Jan C. Binnema
2025-05-20 21:57:40 +03:00
parent bd23e293f5
commit acef5b2381
4 changed files with 97 additions and 36 deletions

View File

@ -288,7 +288,7 @@ user can then choose by typing CHAR. Example:
User now will be presented with a list: \"Choose an animal:
[M]onkey, [G]nu, [x]Moose\".
If optional character KEY is provied, use that instead of asking
If optional character KEY is provided, use that instead of asking
the user.
Function returns the value (cdr) of the matching cell."
@ -520,30 +520,21 @@ Or go to the top level if there is none."
('mu4e-view-mode "(mu4e)Message view")
(_ "mu4e"))))
;;; Emacs bookmarks
(defcustom mu4e-emacs-bookmark-policy 'message
"The policy to decide what kind of Emacs bookmark to create.
;;; bookmarks
(defun mu4e--make-bookmark-record ()
"Create a bookmark for the message at point."
(let* ((msg (mu4e-message-at-point))
(subject (or (plist-get msg :subject) "No subject"))
(date (plist-get msg :date))
(date (if date (format-time-string "%F: " date) ""))
(title (format "%s%s" date subject))
(msgid (or (plist-get msg :message-id)
(mu4e-error
"Cannot bookmark message without message-id"))))
`(,title
,@(bookmark-make-record-default 'no-file 'no-context)
(message-id . ,msgid)
(handler . mu4e--jump-to-bookmark))))
This applies to the Emacs bookmark system command `bookmark-set'.
(declare-function mu4e-view-message-with-message-id "mu4e-view")
(declare-function mu4e-message-at-point "mu4e-message")
(defun mu4e--jump-to-bookmark (bookmark)
"View the message referred to by BOOKMARK."
(when-let* ((msgid (bookmark-prop-get bookmark 'message-id)))
(mu4e-view-message-with-message-id msgid)))
The policy is some symbol; you have the following choices:
- `message': bookmark the message at point
- `query': bookmark the most recent query
- `ask': ask the user interactively"
:type '(choice
(const :tag "Bookmark query at point" message)
(const :tag "Bookmark the last query" query)
(const :tag "Ask user" ask))
:group 'mu4e)
(defun mu4e--popup-lisp-buffer (bufname data)
"Show or hide an s-expression string in a popup-buffer.