config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

ol-notmuch.el (4898B)


      1 ;;; ol-notmuch.el --- Links to notmuch messages  -*- lexical-binding:t -*-
      2 
      3 ;; Copyright (C) 2010-2011 Matthieu Lemerre
      4 ;; Copyright (C) 2010-2021 The Org Contributors
      5 ;; Copyright (C) 2021-2024 Jonas Bernoulli
      6 
      7 ;; Author: Matthieu Lemerre <racin@free.fr>
      8 ;; Maintainer: Jonas Bernoulli <emacs.ol-notmuch@jonas.bernoulli.dev>
      9 ;; Homepage: https://git.sr.ht/~tarsius/ol-notmuch
     10 ;; Keywords: hypermedia mail
     11 
     12 ;; Package-Version: 2.0.3
     13 ;; Package-Requires: (
     14 ;;     (emacs "26.1")
     15 ;;     (compat "30.0.0.0")
     16 ;;     (notmuch "0.38")
     17 ;;     (org "9.7.4"))
     18 
     19 ;; SPDX-License-Identifier: GPL-3.0-or-later
     20 
     21 ;; This file is free software: you can redistribute it and/or modify
     22 ;; it under the terms of the GNU General Public License as published
     23 ;; by the Free Software Foundation, either version 3 of the License,
     24 ;; or (at your option) any later version.
     25 ;;
     26 ;; This file is distributed in the hope that it will be useful,
     27 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     28 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     29 ;; GNU General Public License for more details.
     30 ;;
     31 ;; You should have received a copy of the GNU General Public License
     32 ;; along with this file.  If not, see <https://www.gnu.org/licenses/>.
     33 
     34 ;;; Commentary:
     35 
     36 ;; This file implements links to notmuch messages and "searches".  A
     37 ;; search is a query to be performed by notmuch; it is the equivalent
     38 ;; to folders in other mail clients.  Similarly, mails are referred to
     39 ;; by a query, so both a link can refer to several mails.
     40 
     41 ;; Links have one of the following forms:
     42 ;; - notmuch:<search terms>
     43 ;; - notmuch-search:<search terms>.
     44 
     45 ;; The first form opens the queries in `notmuch-show-mode', whereas the
     46 ;; second link opens it in `notmuch-search-mode'.  Note that queries are
     47 ;; performed at the time the link is opened, and the result may be
     48 ;; different from when the link was stored.
     49 
     50 ;;; Code:
     51 
     52 (require 'compat)
     53 
     54 (require 'notmuch)
     55 (require 'ol)
     56 
     57 ;;; Message links
     58 
     59 (defcustom org-notmuch-open-function #'org-notmuch-follow-link
     60   "Function used to follow notmuch links.
     61 Should accept a notmuch search string as the sole argument."
     62   :group 'org-notmuch
     63   :type 'function)
     64 
     65 ;;;###autoload
     66 (with-eval-after-load 'org
     67   (org-link-set-parameters "notmuch"
     68                            :store  #'org-notmuch-store-link
     69                            :follow #'org-notmuch-open))
     70 
     71 ;;;###autoload
     72 (defun org-notmuch-store-link ()
     73   "Store a link to one or more notmuch messages."
     74   (when (memq major-mode '(notmuch-show-mode notmuch-tree-mode))
     75     ;; The value is passed around using variable `org-store-link-plist'.
     76     (org-link-store-props
     77      :type       "notmuch"
     78      :message-id (notmuch-show-get-message-id t)
     79      :subject    (notmuch-show-get-subject)
     80      :from       (notmuch-show-get-from)
     81      :to         (notmuch-show-get-to)
     82      :date       (org-trim (notmuch-show-get-date)))
     83     (org-link-add-props :link (org-link-email-description "notmuch:id:%m"))
     84     (org-link-add-props :description (org-link-email-description))
     85     org-store-link-plist))
     86 
     87 ;;;###autoload
     88 (defun org-notmuch-open (path _)
     89   "Follow a notmuch message link specified by PATH."
     90   (funcall org-notmuch-open-function path))
     91 
     92 (defun org-notmuch-follow-link (search)
     93   "Follow a notmuch link to SEARCH.
     94 Can link to more than one message, if so all matching messages are shown."
     95   (notmuch-show search))
     96 
     97 ;;; Search links
     98 
     99 ;;;###autoload
    100 (with-eval-after-load 'org
    101   (org-link-set-parameters "notmuch-search"
    102                            :store  #'org-notmuch-search-store-link
    103                            :follow #'org-notmuch-search-open))
    104 
    105 ;;;###autoload
    106 (defun org-notmuch-search-store-link ()
    107   "Store a link to a notmuch search."
    108   (when (eq major-mode 'notmuch-search-mode)
    109     (org-link-store-props
    110      :type        "notmuch-search"
    111      :link        (concat "notmuch-search:"  notmuch-search-query-string)
    112      :description (concat "Notmuch search: " notmuch-search-query-string))))
    113 
    114 ;;;###autoload
    115 (defun org-notmuch-search-open (path _)
    116   "Follow a notmuch search link specified by PATH."
    117   (notmuch-search path))
    118 
    119 ;;; Tree links
    120 
    121 ;;;###autoload
    122 (with-eval-after-load 'org
    123   (org-link-set-parameters "notmuch-tree"
    124                            :store  #'org-notmuch-tree-store-link
    125                            :follow #'org-notmuch-tree-open))
    126 
    127 ;;;###autoload
    128 (defun org-notmuch-tree-store-link ()
    129   "Store a link to a notmuch tree."
    130   (when (eq major-mode 'notmuch-tree-mode)
    131     (org-link-store-props
    132      :type        "notmuch-tree"
    133      :link        (concat "notmuch-tree:"  (notmuch-tree-get-query))
    134      :description (concat "Notmuch tree: " (notmuch-tree-get-query)))))
    135 
    136 ;;;###autoload
    137 (defun org-notmuch-tree-open (path _)
    138   "Follow a notmuch tree link specified by PATH."
    139   (notmuch-tree path))
    140 
    141 ;;; _
    142 (provide 'ol-notmuch)
    143 ;; Local Variables:
    144 ;; indent-tabs-mode: nil
    145 ;; End:
    146 ;;; ol-notmuch.el ends here