org-table: Fix durations extracted from node properties
[org-mode.git] / contrib / lisp / org-notmuch.el
blobae9b50b47aeea3482907f8676712068412e6d2e2
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: 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)
14 ;; any later version.
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/>.
24 ;;; Commentary:
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.
40 ;;; Code:
42 (require 'org)
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."
50 :group 'org-notmuch
51 :version "24.4"
52 :package-version '(Org . "8.0")
53 :type 'function)
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."
60 :group 'org-notmuch
61 :version "24.4"
62 :package-version '(Org . "8.0")
63 :type 'function)
67 ;; Install the link type
68 (org-add-link-type "notmuch" 'org-notmuch-open)
69 (add-hook 'org-store-link-functions 'org-notmuch-store-link)
71 (defun org-notmuch-store-link ()
72 "Store a link to a notmuch search or message."
73 (when (eq major-mode 'notmuch-show-mode)
74 (let* ((message-id (notmuch-show-get-prop :id))
75 (subject (notmuch-show-get-subject))
76 (to (notmuch-show-get-to))
77 (from (notmuch-show-get-from))
78 desc link)
79 (org-store-link-props :type "notmuch" :from from :to to
80 :subject subject :message-id message-id)
81 (setq desc (org-email-link-description))
82 (setq link (concat "notmuch:" "id:" message-id))
83 (org-add-link-props :link link :description desc)
84 link)))
86 (defun org-notmuch-open (path)
87 "Follow a notmuch message link specified by PATH."
88 (funcall org-notmuch-open-function path))
90 (defun org-notmuch-follow-link (search)
91 "Follow a notmuch link to SEARCH.
93 Can link to more than one message, if so all matching messages are shown."
94 (require 'notmuch)
95 (notmuch-show (org-link-unescape search)))
100 (org-add-link-type "notmuch-search" 'org-notmuch-search-open)
101 (add-hook 'org-store-link-functions 'org-notmuch-search-store-link)
103 (defun org-notmuch-search-store-link ()
104 "Store a link to a notmuch search or message."
105 (when (eq major-mode 'notmuch-search-mode)
106 (let ((link (concat "notmuch-search:"
107 (org-link-escape notmuch-search-query-string)))
108 (desc (concat "Notmuch search: " notmuch-search-query-string)))
109 (org-store-link-props :type "notmuch-search"
110 :link link
111 :description desc)
112 link)))
114 (defun org-notmuch-search-open (path)
115 "Follow a notmuch message link specified by PATH."
116 (message path)
117 (funcall org-notmuch-search-open-function path))
119 (defun org-notmuch-search-follow-link (search)
120 "Follow a notmuch link by displaying SEARCH in notmuch-search mode."
121 (require 'notmuch)
122 (notmuch-search (org-link-unescape search)))
126 (defun org-notmuch-tree-follow-link (search)
127 "Follow a notmuch link by displaying SEARCH in notmuch-tree mode."
128 (require 'notmuch)
129 (notmuch-tree (org-link-unescape search)))
131 (provide 'org-notmuch)
133 ;;; org-notmuch.el ends here