Skip to content

Instantly share code, notes, and snippets.

@fedxa
Created August 23, 2017 23:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fedxa/fac592424473f1b70ea489cc64e08911 to your computer and use it in GitHub Desktop.
Save fedxa/fac592424473f1b70ea489cc64e08911 to your computer and use it in GitHub Desktop.
Support for links to notmuch mail messages in Org-mode
;;; org-notmuch.el - Support for links to notmuch mail messages in Org
;;;
;;; Author: Fedor Bezrukov <Fedor.Bezrukov@gmail.com>
;;; Date: 23 Aug 2017
;;;
;;; Installation (See Info:org for Hyperlinks)
;;;
;;; Save into ~/.emacs.d/lisp abd add into .emacs
;;;
;;; (add-to-list 'load-path "~/.emacs.d/lisp/")
;;; (require 'org-notmuch)
;;; (global-set-key "\C-cl" 'org-store-link)
;;;
;;; Notmuch links look like "notmuch:id:9187498217132983537" where ID is the message or thread id as used by notmuch
;;;
;;; See also:
;;; http://orgmode.org/
;;; https://notmuchmail.org/
(require 'org)
(require 'notmuch)
;;; For Org versions before 9.0
;; (org-add-link-type "notmuch" 'org-notmuch-open)
;; (add-hook 'org-store-link-functions 'org-notmuch-store-link)
(org-link-set-parameters "notmuch"
:follow 'org-notmuch-open
:store 'org-notmuch-store-link)
(defun org-notmuch-open (id)
"Visit the notmuch message or thread with id ID."
(notmuch-show id))
(defun org-notmuch-store-link ()
"Store a link to a notmuch mail message."
(case major-mode
('notmuch-show-mode
;; Store link to the current message
(let* ((id (notmuch-show-get-message-id))
(link (concat "notmuch:" id))
(description (format "Mail: %s" (notmuch-show-get-subject))))
(org-store-link-props
:type "notmuch"
:link link
:description description)))
('notmuch-search-mode
;; Store link to the thread on the current line
(let* ((id (notmuch-search-find-thread-id))
(link (concat "notmuch:" id))
(description (format "Mail: %s" (notmuch-search-find-subject))))
(org-store-link-props
:type "notmuch"
:link link
:description description)))))
(provide 'org-notmuch)
;;; org-notmuch.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment