Merge pull request #2081 from danielfleischer/link-description

Customize the mu4e org link description
This commit is contained in:
Dirk-Jan C. Binnema
2021-08-09 07:58:31 +03:00
committed by GitHub
2 changed files with 22 additions and 2 deletions

View File

@ -36,6 +36,25 @@
:group 'mu4e :group 'mu4e
:group 'org) :group 'org)
(defcustom mu4e-org-link-desc-func
(lambda (msg) (or (plist-get msg :subject) "No subject"))
"Function that takes a msg and returns a description.
This can be used in org capture templates and storing links.
Example usage:
(defun my-link-descr (msg)
(let ((subject (or (plist-get msg :subject)
\"No subject\"))
(date (or (format-time-string mu4e-headers-date-format
(mu4e-msg-field msg :date))
\"No date\")))
(concat subject \" \" date)))
(setq org-mu4e-link-desc-func 'my-link-descr)"
:type '(function)
:group 'mu4e-org)
(defvar mu4e-org-link-query-in-headers-mode nil (defvar mu4e-org-link-query-in-headers-mode nil
"Prefer linking to the query rather than to the message. "Prefer linking to the query rather than to the message.
If non-nil, `org-store-link' in `mu4e-headers-mode' links to the If non-nil, `org-store-link' in `mu4e-headers-mode' links to the
@ -79,7 +98,7 @@ the current query; otherwise, it links to the message at point.")
:to (when to :to (when to
(mu4e~org-address to)) (mu4e~org-address to))
:link (concat "mu4e:msgid:" msgid) :link (concat "mu4e:msgid:" msgid)
:description (or (plist-get msg :subject) "No subject")))) :description (funcall mu4e-org-link-desc-func msg))))
(defun mu4e-org-store-link () (defun mu4e-org-store-link ()
"Store a link to a mu4e message or query. "Store a link to a mu4e message or query.

View File

@ -3544,7 +3544,8 @@ You can use the normal @t{org-mode} mechanisms to store links:
you are in @ref{Message view}. When you are in @ref{Headers view}, you are in @ref{Message view}. When you are in @ref{Headers view},
@kbd{M-x org-store-link} links to the @emph{query} if @kbd{M-x org-store-link} links to the @emph{query} if
@code{mu4e-org-link-query-in-headers-mode} is non-@code{nil}, and to @code{mu4e-org-link-query-in-headers-mode} is non-@code{nil}, and to
the particular message otherwise (which is the default). the particular message otherwise (which is the default). You can
customize the link description using @code{mu4e-org-link-desc-func}.
You can insert this link later with @kbd{M-x org-insert-link}. From You can insert this link later with @kbd{M-x org-insert-link}. From
@t{org-mode}, you can go to the query or message the link points to @t{org-mode}, you can go to the query or message the link points to