org.el (org-read-date-minibuffer-local-map): Check if we are at the beginning of...
[org-mode.git] / contrib / lisp / org-notmuch.el
blobc7f92feba4a409e85838b79347beb61ee8d69c64
1 ;;; org-notmuch.el --- Support for links to notmuch messages from within Org-mode
3 ;; Copyright (C) 2010-2013 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 ;; Install the link type
45 (org-add-link-type "notmuch" 'org-notmuch-open)
46 (add-hook 'org-store-link-functions 'org-notmuch-store-link)
48 (defun org-notmuch-store-link ()
49 "Store a link to a notmuch search or message."
50 (when (eq major-mode 'notmuch-show-mode)
51 (let* ((message-id (notmuch-show-get-prop :id))
52 (subject (notmuch-show-get-subject))
53 (to (notmuch-show-get-to))
54 (from (notmuch-show-get-from))
55 desc link)
56 (org-store-link-props :type "notmuch" :from from :to to
57 :subject subject :message-id message-id)
58 (setq desc (org-email-link-description))
59 (setq link (concat "notmuch:" "id:" message-id))
60 (org-add-link-props :link link :description desc)
61 link)))
63 (defun org-notmuch-open (path)
64 "Follow a notmuch message link specified by PATH."
65 (org-notmuch-follow-link path))
67 (defun org-notmuch-follow-link (search)
68 "Follow a notmuch link to SEARCH.
70 Can link to more than one message, if so all matching messages are shown."
71 (require 'notmuch)
72 (notmuch-show (org-link-unescape search)))
77 (org-add-link-type "notmuch-search" 'org-notmuch-search-open)
78 (add-hook 'org-store-link-functions 'org-notmuch-search-store-link)
80 (defun org-notmuch-search-store-link ()
81 "Store a link to a notmuch search or message."
82 (when (eq major-mode 'notmuch-search-mode)
83 (let ((link (concat "notmuch-search:"
84 (org-link-escape notmuch-search-query-string)))
85 (desc (concat "Notmuch search: " notmuch-search-query-string)))
86 (org-store-link-props :type "notmuch-search"
87 :link link
88 :description desc)
89 link)))
91 (defun org-notmuch-search-open (path)
92 "Follow a notmuch message link specified by PATH."
93 (message path)
94 (org-notmuch-search-follow-link path))
96 (defun org-notmuch-search-follow-link (search)
97 "Follow a notmuch link by displaying SEARCH in notmuch-search mode."
98 (require 'notmuch)
99 (notmuch-search (org-link-unescape search)))
101 (provide 'org-notmuch)
103 ;;; org-notmuch.el ends here