Allow headings inside tables without splicing them.
[org-mode/org-tableheadings.git] / contrib / lisp / ol-notmuch.el
blob3ad82984c70bbdabe683e0a24ded5fe53ab197dc
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)
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 'ol)
43 (require 'org)
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."
51 :group 'org-notmuch
52 :version "24.4"
53 :package-version '(Org . "8.0")
54 :type 'function)
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."
60 :group 'org-notmuch
61 :version "24.4"
62 :package-version '(Org . "8.0")
63 :type 'function)
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)))
82 desc link)
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)
88 link)))
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."
98 (require 'notmuch)
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"
113 :link link
114 :description desc)
115 link)))
117 (defun org-notmuch-search-open (path)
118 "Follow a notmuch message link specified by PATH."
119 (message "%s" 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."
124 (require 'notmuch)
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"
139 :link link
140 :description desc)
141 link)))
143 (defun org-notmuch-tree-open (path)
144 "Follow a notmuch message link specified by PATH."
145 (message "%s" 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."
150 (require 'notmuch)
151 (notmuch-tree search))
153 (provide 'ol-notmuch)
155 ;;; ol-notmuch.el ends here