emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: David Bremner <bremner@unb.ca>
To: emacs-orgmode@gnu.org
Subject: [PATCH 1/2] Initial version of link support for the notmuch mail system.
Date: Mon,  5 Apr 2010 21:42:55 -0300	[thread overview]
Message-ID: <1270514576-12432-2-git-send-email-bremner@unb.ca> (raw)
In-Reply-To: <A5378CDF-0E6D-4BE9-A9FB-9901157FF841@gmail.com>

It requires a version of notmuch from git after April 5 2010.  The
code here is based on org-wl.el. One thing to note is that links to
threads are faked as a collection of message ids. This is because
notmuch thread-ids are currently not stable between dump/restore of
the database.
---
 lisp/org-notmuch.el |   87 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)
 create mode 100644 lisp/org-notmuch.el

diff --git a/lisp/org-notmuch.el b/lisp/org-notmuch.el
new file mode 100644
index 0000000..82c31a5
--- /dev/null
+++ b/lisp/org-notmuch.el
@@ -0,0 +1,87 @@
+;;; org-notmuch.el --- Support for links to notmuch messages from within Org-mode
+;; Author: David Bremner <david@tethera.net>
+;; License: GPL3+
+;;; Commentary:
+
+;; This file implements links to notmuch messages from within Org-mode.
+;; Link types supported include 
+;; - notmuch:id:message-id
+;; - notmuch:show:search-terms
+;; - notmuch:search:search-terms
+;;
+;; The latter two pass the search terms to the corresponding notmuch-*
+;; function.  'id:' is an abbreviation for 'show:id:' search-terms is
+;; a space delimited list of notmuch search-terms.
+;;
+;; Currently storing links is supported in notmuch-search and
+;; notmuch-show mode.  It might make sense to support notmuch-folder
+;; mode too.  Because threads-ids are currently not save/restore safe,
+;; they are converted into a list of message-ids.
+;;
+;; Org-mode loads this module by default - if this is not what you want,
+;; configure the variable `org-modules'.
+;;; Code:
+
+;; Install the link type
+(org-add-link-type "notmuch" 'org-notmuch-open)
+(add-hook 'org-store-link-functions 'org-notmuch-store-link)
+
+;; Configuration
+(defvar org-notmuch-mid-limit 10
+  "Maximum number of message ids to store for a thread")
+
+;; Implementation
+(defun org-notmuch-store-link ()
+  "Store a link to the currently selected thread."
+  (require 'notmuch)
+  (when (memq major-mode '(notmuch-show-mode notmuch-search-mode))
+    (if (equal major-mode 'notmuch-search-mode)
+	(org-notmuch-do-store-link 
+	 (org-notmuch-build-thread-link)
+	 (notmuch-search-find-authors)
+	 (notmuch-search-find-subject))
+      (org-notmuch-do-store-link  (notmuch-show-get-message-id)
+				  (notmuch-show-get-from)
+				  (notmuch-show-get-subject)))))
+
+;; sigh. there doesn't seem to be such a function.
+(defun org-notmuch-n-first (list n)
+  (if (> n 0)
+      (cons (car list)
+	    (org-notmuch-n-first (cdr list) (1- n)))
+    nil))
+
+(defun org-notmuch-build-thread-link ()
+  "Expand the thread-id on the current line to a list of message-ids"
+  (require 'notmuch-query)
+  (let* ((current-thread (or (notmuch-search-find-thread-id) 
+			    (error "End of search results")))
+	 (message-ids 
+	  (org-notmuch-n-first 
+	   (notmuch-query-get-message-ids current-thread)
+	   org-notmuch-mid-limit)))
+    (concat "show:" 
+	    (mapconcat (lambda (id) (concat "id:" id)) message-ids " "))))
+
+(defun org-notmuch-do-store-link (id author subject)
+  (let ((link  (org-make-link "notmuch:" id)))
+    (org-store-link-props :type "notmuch" :from author :subject subject)
+    (org-add-link-props :link link :description (org-email-link-description))
+    link))
+
+
+(defun org-notmuch-open (link)
+  "Open a link with notmuch. id: or show: links are opened directly with notmuch-show
+otherwise notmuch-search is used to give an index view"
+  (require 'notmuch)
+  (cond 
+   ((string-match "^show:\\(.*\\)" link)
+    (notmuch-show (match-string 1 link)))
+   ((string-match "^search:\\(.*\\)" link)
+    (notmuch-search (match-string 1 link)))
+   ((string-match "^id:.*" link)
+    (notmuch-show link))
+   (t (notmuch-search link))))
+
+    
+(provide 'org-notmuch)
-- 
1.7.0

  parent reply	other threads:[~2010-04-06  0:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-18 10:54 Notmuch: An emacs interface for fast global search and tagging of email Carl Worth
2009-11-18 13:16 ` Giovanni Ridolfi
2009-11-18 14:13   ` Jan Janak
2009-11-18 16:39     ` Tassilo Horn
2009-11-18 17:39     ` Carsten Dominik
2009-11-19  0:12       ` Carl Worth
2009-11-19 13:15         ` Carsten Dominik
2010-04-06  0:42           ` Updated patches for linking to notmuch mail from org David Bremner
2010-04-06 10:13             ` Carsten Dominik
2010-04-06 11:22               ` David Bremner
2010-04-06 12:53                 ` Carsten Dominik
2010-04-06  0:42           ` David Bremner [this message]
2010-04-06  0:42           ` [PATCH 2/2] Add org-notmuch.el to Makefile and to org-modules David Bremner
2009-11-19 14:26         ` Notmuch: An emacs interface for fast global search and tagging of email Richard Riley
2009-12-05 16:40         ` David Bremner
2009-12-08 16:56           ` Carsten Dominik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1270514576-12432-2-git-send-email-bremner@unb.ca \
    --to=bremner@unb.ca \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).