2019-03-01 19:01:32 -05:00
|
|
|
|
;;; org-notmuch.el --- Links to notmuch messages
|
2011-02-12 10:53:10 -05:00
|
|
|
|
|
2014-01-07 08:18:17 -05:00
|
|
|
|
;; Copyright (C) 2010-2014 Matthieu Lemerre
|
2011-02-12 10:53:10 -05:00
|
|
|
|
|
|
|
|
|
;; Author: Matthieu Lemerre <racin@free.fr>
|
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
2018-01-16 11:22:00 -05:00
|
|
|
|
;; Homepage: https://orgmode.org
|
2011-02-12 10:53:10 -05:00
|
|
|
|
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; This file is free software; you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
;; any later version.
|
|
|
|
|
|
|
|
|
|
;; This file is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2013-03-10 12:57:47 -04:00
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2011-02-12 10:53:10 -05:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
2019-11-12 08:44:05 -05:00
|
|
|
|
;; This file implements links to notmuch messages and "searches". A
|
2011-02-12 10:53:10 -05:00
|
|
|
|
;; search is a query to be performed by notmuch; it is the equivalent
|
2019-11-12 08:44:05 -05:00
|
|
|
|
;; to folders in other mail clients. Similarly, mails are referred to
|
2011-02-12 10:53:10 -05:00
|
|
|
|
;; by a query, so both a link can refer to several mails.
|
|
|
|
|
|
|
|
|
|
;; Links have one the following form
|
|
|
|
|
;; notmuch:<search terms>
|
2012-03-19 16:38:12 -04:00
|
|
|
|
;; notmuch-search:<search terms>.
|
2011-02-12 10:53:10 -05:00
|
|
|
|
|
|
|
|
|
;; The first form open the queries in notmuch-show mode, whereas the
|
|
|
|
|
;; second link open it in notmuch-search mode. Note that queries are
|
|
|
|
|
;; performed at the time the link is opened, and the result may be
|
2019-11-12 08:44:05 -05:00
|
|
|
|
;; different from when the link was stored.
|
2011-02-12 10:53:10 -05:00
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2019-03-01 19:01:32 -05:00
|
|
|
|
(require 'ol)
|
2011-04-16 08:00:41 -04:00
|
|
|
|
(require 'org)
|
|
|
|
|
|
2014-07-16 12:08:36 -04:00
|
|
|
|
;; customisable notmuch open functions
|
|
|
|
|
(defcustom org-notmuch-open-function
|
|
|
|
|
'org-notmuch-follow-link
|
|
|
|
|
"Function used to follow notmuch links.
|
|
|
|
|
|
|
|
|
|
Should accept a notmuch search string as the sole argument."
|
|
|
|
|
:group 'org-notmuch
|
|
|
|
|
:version "24.4"
|
|
|
|
|
:package-version '(Org . "8.0")
|
|
|
|
|
:type 'function)
|
|
|
|
|
|
|
|
|
|
(defcustom org-notmuch-search-open-function
|
|
|
|
|
'org-notmuch-search-follow-link
|
|
|
|
|
"Function used to follow notmuch-search links.
|
|
|
|
|
Should accept a notmuch search string as the sole argument."
|
|
|
|
|
:group 'org-notmuch
|
|
|
|
|
:version "24.4"
|
|
|
|
|
:package-version '(Org . "8.0")
|
|
|
|
|
:type 'function)
|
|
|
|
|
|
2019-04-09 13:15:22 -04:00
|
|
|
|
(make-obsolete-variable 'org-notmuch-search-open-function nil "9.3")
|
|
|
|
|
|
2014-07-16 12:08:36 -04:00
|
|
|
|
|
|
|
|
|
|
2011-02-12 10:53:10 -05:00
|
|
|
|
;; Install the link type
|
2016-08-07 21:24:23 -04:00
|
|
|
|
(org-link-set-parameters "notmuch"
|
|
|
|
|
:follow #'org-notmuch-open
|
|
|
|
|
:store #'org-notmuch-store-link)
|
2011-02-12 10:53:10 -05:00
|
|
|
|
|
|
|
|
|
(defun org-notmuch-store-link ()
|
|
|
|
|
"Store a link to a notmuch search or message."
|
2019-04-03 06:54:53 -04:00
|
|
|
|
(when (memq major-mode '(notmuch-show-mode notmuch-tree-mode))
|
2015-12-27 09:54:17 -05:00
|
|
|
|
(let* ((message-id (notmuch-show-get-message-id t))
|
2011-02-12 10:53:10 -05:00
|
|
|
|
(subject (notmuch-show-get-subject))
|
|
|
|
|
(to (notmuch-show-get-to))
|
|
|
|
|
(from (notmuch-show-get-from))
|
2015-12-27 09:54:17 -05:00
|
|
|
|
(date (org-trim (notmuch-show-get-date)))
|
2011-02-12 10:53:10 -05:00
|
|
|
|
desc link)
|
2015-12-27 09:54:17 -05:00
|
|
|
|
(org-store-link-props :type "notmuch" :from from :to to :date date
|
2011-02-12 10:53:10 -05:00
|
|
|
|
:subject subject :message-id message-id)
|
|
|
|
|
(setq desc (org-email-link-description))
|
2015-12-27 09:54:17 -05:00
|
|
|
|
(setq link (concat "notmuch:id:" message-id))
|
2011-02-12 10:53:10 -05:00
|
|
|
|
(org-add-link-props :link link :description desc)
|
|
|
|
|
link)))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
|
2011-02-12 10:53:10 -05:00
|
|
|
|
(defun org-notmuch-open (path)
|
|
|
|
|
"Follow a notmuch message link specified by PATH."
|
2014-07-16 12:08:36 -04:00
|
|
|
|
(funcall org-notmuch-open-function path))
|
2011-02-12 10:53:10 -05:00
|
|
|
|
|
|
|
|
|
(defun org-notmuch-follow-link (search)
|
2012-03-19 16:38:12 -04:00
|
|
|
|
"Follow a notmuch link to SEARCH.
|
2011-02-12 10:53:10 -05:00
|
|
|
|
|
|
|
|
|
Can link to more than one message, if so all matching messages are shown."
|
|
|
|
|
(require 'notmuch)
|
2016-09-30 04:00:18 -04:00
|
|
|
|
(notmuch-show search))
|
2011-02-12 10:53:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-07 21:24:23 -04:00
|
|
|
|
(org-link-set-parameters "notmuch-search"
|
|
|
|
|
:follow #'org-notmuch-search-open
|
|
|
|
|
:store #'org-notmuch-search-store-link)
|
2011-02-12 10:53:10 -05:00
|
|
|
|
|
|
|
|
|
(defun org-notmuch-search-store-link ()
|
|
|
|
|
"Store a link to a notmuch search or message."
|
|
|
|
|
(when (eq major-mode 'notmuch-search-mode)
|
2019-02-27 14:22:51 -05:00
|
|
|
|
(let ((link (concat "notmuch-search:" notmuch-search-query-string))
|
2011-02-12 10:53:10 -05:00
|
|
|
|
(desc (concat "Notmuch search: " notmuch-search-query-string)))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
(org-store-link-props :type "notmuch-search"
|
2011-02-12 10:53:10 -05:00
|
|
|
|
:link link
|
|
|
|
|
:description desc)
|
|
|
|
|
link)))
|
|
|
|
|
|
|
|
|
|
(defun org-notmuch-search-open (path)
|
|
|
|
|
"Follow a notmuch message link specified by PATH."
|
2015-05-15 12:11:45 -04:00
|
|
|
|
(message "%s" path)
|
2019-04-09 13:15:22 -04:00
|
|
|
|
(org-notmuch-search-follow-link path))
|
2011-02-12 10:53:10 -05:00
|
|
|
|
|
|
|
|
|
(defun org-notmuch-search-follow-link (search)
|
|
|
|
|
"Follow a notmuch link by displaying SEARCH in notmuch-search mode."
|
|
|
|
|
(require 'notmuch)
|
2019-02-27 14:22:51 -05:00
|
|
|
|
(notmuch-search search))
|
2011-02-12 10:53:10 -05:00
|
|
|
|
|
2014-07-16 12:17:56 -04:00
|
|
|
|
|
|
|
|
|
|
2019-04-09 13:15:22 -04:00
|
|
|
|
(org-link-set-parameters "notmuch-tree"
|
|
|
|
|
:follow #'org-notmuch-tree-open
|
|
|
|
|
:store #'org-notmuch-tree-store-link)
|
|
|
|
|
|
|
|
|
|
(defun org-notmuch-tree-store-link ()
|
|
|
|
|
"Store a link to a notmuch search or message."
|
|
|
|
|
(when (eq major-mode 'notmuch-tree-mode)
|
|
|
|
|
(let ((link (concat "notmuch-tree:" (notmuch-tree-get-query)))
|
|
|
|
|
(desc (concat "Notmuch tree: " (notmuch-tree-get-query))))
|
|
|
|
|
(org-store-link-props :type "notmuch-tree"
|
|
|
|
|
:link link
|
|
|
|
|
:description desc)
|
|
|
|
|
link)))
|
|
|
|
|
|
|
|
|
|
(defun org-notmuch-tree-open (path)
|
|
|
|
|
"Follow a notmuch message link specified by PATH."
|
|
|
|
|
(message "%s" path)
|
|
|
|
|
(org-notmuch-tree-follow-link path))
|
|
|
|
|
|
2014-07-16 12:17:56 -04:00
|
|
|
|
(defun org-notmuch-tree-follow-link (search)
|
|
|
|
|
"Follow a notmuch link by displaying SEARCH in notmuch-tree mode."
|
|
|
|
|
(require 'notmuch)
|
2019-02-27 14:22:51 -05:00
|
|
|
|
(notmuch-tree search))
|
2014-07-16 12:17:56 -04:00
|
|
|
|
|
2019-03-01 19:01:32 -05:00
|
|
|
|
(provide 'ol-notmuch)
|
2011-02-12 10:53:10 -05:00
|
|
|
|
|
2019-03-01 19:01:32 -05:00
|
|
|
|
;;; ol-notmuch.el ends here
|