From 59022e066de4fa68c39c77bd5345de1d5d309307 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 29 May 2022 12:31:39 +0300 Subject: [PATCH] mu4e: revamp emacs bookmark support The support for emacs in bookmarks in mu4e-contrib has been broken for a while; we removed it an now re-implement it as part of mu4e-proper. Fixes: issue #2255. --- mu4e/mu4e-headers.el | 3 +++ mu4e/mu4e-helpers.el | 27 ++++++++++++++++++++++++++- mu4e/mu4e-view.el | 5 +++++ mu4e/mu4e.texi | 11 +++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/mu4e/mu4e-headers.el b/mu4e/mu4e-headers.el index b59d47df..9cd7f3ba 100644 --- a/mu4e/mu4e-headers.el +++ b/mu4e/mu4e-headers.el @@ -1190,6 +1190,9 @@ The following specs are supported: (add-function :before-until (local 'eldoc-documentation-function) #'mu4e-headers-eldoc-function)))) + ;; support bookmarks. + (set (make-local-variable 'bookmark-make-record-function) + 'mu4e--make-bookmark-record) ;; maybe update the current headers upon indexing changes (add-hook 'mu4e-index-updated-hook #'mu4e~headers-maybe-auto-update) (setq diff --git a/mu4e/mu4e-helpers.el b/mu4e/mu4e-helpers.el index 79999aec..0ead5a0b 100644 --- a/mu4e/mu4e-helpers.el +++ b/mu4e/mu4e-helpers.el @@ -1,6 +1,6 @@ ;;; mu4e-helpers.el -- part of mu4e -*- lexical-binding: t -*- -;; Copyright (C) 2021 Dirk-Jan C. Binnema +;; Copyright (C) 2022 Dirk-Jan C. Binnema ;; Author: Dirk-Jan C. Binnema ;; Maintainer: Dirk-Jan C. Binnema @@ -30,6 +30,7 @@ (require 'seq) (require 'ido) (require 'cl-lib) +(require 'bookmark) (require 'mu4e-config) @@ -521,6 +522,30 @@ Or go to the top level if there is none." ('mu4e-view-mode "(mu4e)Message view") (_ "mu4e")))) + +;;; 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)))) + +(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))) + ;;; Macros (defmacro mu4e-setq-if-nil (var val) diff --git a/mu4e/mu4e-view.el b/mu4e/mu4e-view.el index 2b309b4b..4854d780 100644 --- a/mu4e/mu4e-view.el +++ b/mu4e/mu4e-view.el @@ -1052,6 +1052,11 @@ Based on Gnus' article-mode." (mu4e-context-minor-mode) (mu4e-search-minor-mode) (setq buffer-undo-list t);; don't record undo info + + ;; support bookmarks. + (set (make-local-variable 'bookmark-make-record-function) + 'mu4e--make-bookmark-record) + ;; autopair mode gives error when pressing RET ;; turn it off (when (boundp 'autopair-dont-activate) diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index 47a0f66f..c5d86a79 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -2996,6 +2996,7 @@ with other tools. @menu * Emacs default::Making mu4e the default emacs e-mail program +* Emacs bookmarks::Using Emacs' bookmark system * Org-mode links::Adding mu4e to your organized life * Org-contacts::Hooking up with org-contacts * BBDB::Hooking up with the Insidious Big Brother Database @@ -3028,6 +3029,16 @@ mail, customize the variable @code{read-mail-command}. (@pxref{Top,,Emacs,Sending Mail, Mail Methods}) + +@node Emacs bookmarks +@section Emacs bookmarks + +@t{mu4e} supports linking to the message-at-point through the normal +Emacs built-in bookmark system. The links are based on the message's +message-id, and thus the bookmarks stay valid even if you move the +message around. + + @node Org-mode links @section Org-mode links