1 ;;; org-notmuch.el --- Support for links to notmuch messages from within Org-mode
3 ;; Copyright (C) 2010-2014 Matthieu Lemerre
5 ;; Author: Matthieu Lemerre <racin@free.fr>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: https://orgmode.org
9 ;; This file is not part of GNU Emacs.
11 ;; This file is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; This file is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This file implements links to notmuch messages and "searchs". A
27 ;; search is a query to be performed by notmuch; it is the equivalent
28 ;; to folders in other mail clients. Similarly, mails are refered to
29 ;; by a query, so both a link can refer to several mails.
31 ;; Links have one the following form
32 ;; notmuch:<search terms>
33 ;; notmuch-search:<search terms>.
35 ;; The first form open the queries in notmuch-show mode, whereas the
36 ;; second link open it in notmuch-search mode. Note that queries are
37 ;; performed at the time the link is opened, and the result may be
38 ;; different from whet the link was stored.
44 ;; customisable notmuch open functions
45 (defcustom org-notmuch-open-function
46 'org-notmuch-follow-link
47 "Function used to follow notmuch links.
49 Should accept a notmuch search string as the sole argument."
52 :package-version
'(Org .
"8.0")
55 (defcustom org-notmuch-search-open-function
56 'org-notmuch-search-follow-link
57 "Function used to follow notmuch-search links.
59 Should accept a notmuch search string as the sole argument."
62 :package-version
'(Org .
"8.0")
67 ;; Install the link type
68 (org-link-set-parameters "notmuch"
69 :follow
#'org-notmuch-open
70 :store
#'org-notmuch-store-link
)
72 (defun org-notmuch-store-link ()
73 "Store a link to a notmuch search or message."
74 (when (eq major-mode
'notmuch-show-mode
)
75 (let* ((message-id (notmuch-show-get-message-id t
))
76 (subject (notmuch-show-get-subject))
77 (to (notmuch-show-get-to))
78 (from (notmuch-show-get-from))
79 (date (org-trim (notmuch-show-get-date)))
81 (org-store-link-props :type
"notmuch" :from from
:to to
:date date
82 :subject subject
:message-id message-id
)
83 (setq desc
(org-email-link-description))
84 (setq link
(concat "notmuch:id:" message-id
))
85 (org-add-link-props :link link
:description desc
)
88 (defun org-notmuch-open (path)
89 "Follow a notmuch message link specified by PATH."
90 (funcall org-notmuch-open-function path
))
92 (defun org-notmuch-follow-link (search)
93 "Follow a notmuch link to SEARCH.
95 Can link to more than one message, if so all matching messages are shown."
97 (notmuch-show search
))
101 (org-link-set-parameters "notmuch-search"
102 :follow
#'org-notmuch-search-open
103 :store
#'org-notmuch-search-store-link
)
105 (defun org-notmuch-search-store-link ()
106 "Store a link to a notmuch search or message."
107 (when (eq major-mode
'notmuch-search-mode
)
108 (let ((link (concat "notmuch-search:"
109 (org-link-escape notmuch-search-query-string
)))
110 (desc (concat "Notmuch search: " notmuch-search-query-string
)))
111 (org-store-link-props :type
"notmuch-search"
116 (defun org-notmuch-search-open (path)
117 "Follow a notmuch message link specified by PATH."
119 (funcall org-notmuch-search-open-function path
))
121 (defun org-notmuch-search-follow-link (search)
122 "Follow a notmuch link by displaying SEARCH in notmuch-search mode."
124 (notmuch-search (org-link-unescape search
)))
128 (defun org-notmuch-tree-follow-link (search)
129 "Follow a notmuch link by displaying SEARCH in notmuch-tree mode."
131 (notmuch-tree (org-link-unescape search
)))
133 (provide 'org-notmuch
)
135 ;;; org-notmuch.el ends here