1 ;;; org-notmuch.el --- Links to notmuch messages
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.
45 ;; customisable notmuch open functions
46 (defcustom org-notmuch-open-function
47 'org-notmuch-follow-link
48 "Function used to follow notmuch links.
50 Should accept a notmuch search string as the sole argument."
53 :package-version
'(Org .
"8.0")
56 (defcustom org-notmuch-search-open-function
57 'org-notmuch-search-follow-link
58 "Function used to follow notmuch-search links.
59 Should accept a notmuch search string as the sole argument."
62 :package-version
'(Org .
"8.0")
65 (make-obsolete-variable 'org-notmuch-search-open-function nil
"9.3")
69 ;; Install the link type
70 (org-link-set-parameters "notmuch"
71 :follow
#'org-notmuch-open
72 :store
#'org-notmuch-store-link
)
74 (defun org-notmuch-store-link ()
75 "Store a link to a notmuch search or message."
76 (when (memq major-mode
'(notmuch-show-mode notmuch-tree-mode
))
77 (let* ((message-id (notmuch-show-get-message-id t
))
78 (subject (notmuch-show-get-subject))
79 (to (notmuch-show-get-to))
80 (from (notmuch-show-get-from))
81 (date (org-trim (notmuch-show-get-date)))
83 (org-store-link-props :type
"notmuch" :from from
:to to
:date date
84 :subject subject
:message-id message-id
)
85 (setq desc
(org-email-link-description))
86 (setq link
(concat "notmuch:id:" message-id
))
87 (org-add-link-props :link link
:description desc
)
90 (defun org-notmuch-open (path)
91 "Follow a notmuch message link specified by PATH."
92 (funcall org-notmuch-open-function path
))
94 (defun org-notmuch-follow-link (search)
95 "Follow a notmuch link to SEARCH.
97 Can link to more than one message, if so all matching messages are shown."
99 (notmuch-show search
))
103 (org-link-set-parameters "notmuch-search"
104 :follow
#'org-notmuch-search-open
105 :store
#'org-notmuch-search-store-link
)
107 (defun org-notmuch-search-store-link ()
108 "Store a link to a notmuch search or message."
109 (when (eq major-mode
'notmuch-search-mode
)
110 (let ((link (concat "notmuch-search:" notmuch-search-query-string
))
111 (desc (concat "Notmuch search: " notmuch-search-query-string
)))
112 (org-store-link-props :type
"notmuch-search"
117 (defun org-notmuch-search-open (path)
118 "Follow a notmuch message link specified by PATH."
120 (org-notmuch-search-follow-link path
))
122 (defun org-notmuch-search-follow-link (search)
123 "Follow a notmuch link by displaying SEARCH in notmuch-search mode."
125 (notmuch-search search
))
129 (org-link-set-parameters "notmuch-tree"
130 :follow
#'org-notmuch-tree-open
131 :store
#'org-notmuch-tree-store-link
)
133 (defun org-notmuch-tree-store-link ()
134 "Store a link to a notmuch search or message."
135 (when (eq major-mode
'notmuch-tree-mode
)
136 (let ((link (concat "notmuch-tree:" (notmuch-tree-get-query)))
137 (desc (concat "Notmuch tree: " (notmuch-tree-get-query))))
138 (org-store-link-props :type
"notmuch-tree"
143 (defun org-notmuch-tree-open (path)
144 "Follow a notmuch message link specified by PATH."
146 (org-notmuch-tree-follow-link path
))
148 (defun org-notmuch-tree-follow-link (search)
149 "Follow a notmuch link by displaying SEARCH in notmuch-tree mode."
151 (notmuch-tree search
))
153 (provide 'ol-notmuch
)
155 ;;; ol-notmuch.el ends here