1 ;;; org-notmuch.el --- Support for links to notmuch messages from within Org-mode
3 ;; Copyright (C) 2010-2012 Matthieu Lemerre
5 ;; Author: Matthieu Lemerre <racin@free.fr>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://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; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; This file implements links to notmuch messages and "searchs". A
29 ;; search is a query to be performed by notmuch; it is the equivalent
30 ;; to folders in other mail clients. Similarly, mails are refered to
31 ;; by a query, so both a link can refer to several mails.
33 ;; Links have one the following form
34 ;; notmuch:<search terms>
35 ;; notmuch-search:<search terms>.
37 ;; The first form open the queries in notmuch-show mode, whereas the
38 ;; second link open it in notmuch-search mode. Note that queries are
39 ;; performed at the time the link is opened, and the result may be
40 ;; different from whet the link was stored.
46 ;; Install the link type
47 (org-add-link-type "notmuch" 'org-notmuch-open
)
48 (add-hook 'org-store-link-functions
'org-notmuch-store-link
)
50 (defun org-notmuch-store-link ()
51 "Store a link to a notmuch search or message."
52 (when (eq major-mode
'notmuch-show-mode
)
53 (let* ((message-id (notmuch-show-get-prop :id
))
54 (subject (notmuch-show-get-subject))
55 (to (notmuch-show-get-to))
56 (from (notmuch-show-get-from))
58 (org-store-link-props :type
"notmuch" :from from
:to to
59 :subject subject
:message-id message-id
)
60 (setq desc
(org-email-link-description))
61 (setq link
(org-make-link "notmuch:" "id:" message-id
))
62 (org-add-link-props :link link
:description desc
)
65 (defun org-notmuch-open (path)
66 "Follow a notmuch message link specified by PATH."
67 (org-notmuch-follow-link path
))
69 (defun org-notmuch-follow-link (search)
70 "Follow a notmuch link to SEARCH.
72 Can link to more than one message, if so all matching messages are shown."
74 (notmuch-show (org-link-unescape search
)))
79 (org-add-link-type "notmuch-search" 'org-notmuch-search-open
)
80 (add-hook 'org-store-link-functions
'org-notmuch-search-store-link
)
82 (defun org-notmuch-search-store-link ()
83 "Store a link to a notmuch search or message."
84 (when (eq major-mode
'notmuch-search-mode
)
85 (let ((link (org-make-link "notmuch-search:"
86 (org-link-escape notmuch-search-query-string
)))
87 (desc (concat "Notmuch search: " notmuch-search-query-string
)))
88 (org-store-link-props :type
"notmuch-search"
93 (defun org-notmuch-search-open (path)
94 "Follow a notmuch message link specified by PATH."
96 (org-notmuch-search-follow-link path
))
98 (defun org-notmuch-search-follow-link (search)
99 "Follow a notmuch link by displaying SEARCH in notmuch-search mode."
101 (notmuch-search (org-link-unescape search
)))
103 (provide 'org-notmuch
)
105 ;;; org-notmuch.el ends here