From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Bremner Subject: [PATCH 1/2] Initial version of link support for the notmuch mail system. Date: Mon, 5 Apr 2010 21:42:55 -0300 Message-ID: <1270514576-12432-2-git-send-email-bremner@unb.ca> References: Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NywtI-0006q2-68 for emacs-orgmode@gnu.org; Mon, 05 Apr 2010 20:43:40 -0400 Received: from [140.186.70.92] (port=39749 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NywtG-0006pE-6h for emacs-orgmode@gnu.org; Mon, 05 Apr 2010 20:43:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NywtE-0000bU-Hd for emacs-orgmode@gnu.org; Mon, 05 Apr 2010 20:43:38 -0400 Received: from pivot.cs.unb.ca ([131.202.240.57]:33860) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NywtE-0000bQ-CI for emacs-orgmode@gnu.org; Mon, 05 Apr 2010 20:43:36 -0400 In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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 +;; 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