Selective tag inheritance.
[org-mode/org-tableheadings.git] / org-wl.el
blob7389a222edc65b64186041feb960fe376e018931
1 ;;; org-wl.el - Support for links to Wanderlust messages in Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;; Version: 1.0
9 ;;
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;; Commentary:
30 ;; This file implements links to Wanderlust messages for Org-mode.
31 ;; Org-mode loads this module by default - if this is not what you want,
32 ;; configure the variable `org-modules'.
34 (require 'org)
36 (defgroup org-wl nil
37 "Options concerning the Wanderlust link."
38 :tag "Org Startup"
39 :group 'org-link)
41 (defcustom org-wl-link-to-refile-destination t
42 "Create a link to the refile destination if the message is marked as refile."
43 :group 'org-wl
44 :type 'boolean)
46 ;; Declare external functions and variables
47 (declare-function elmo-folder-exists-p "ext:elmo" (folder) t)
48 (declare-function elmo-message-entity-field "ext:elmo-msgdb"
49 (entity field &optional type))
50 (declare-function elmo-message-field "ext:elmo"
51 (folder number field &optional type) t)
52 (declare-function elmo-msgdb-overview-get-entity "ext:elmo" (&rest unknown) t)
53 ;; Backward compatibility to old version of wl
54 (declare-function wl-summary-buffer-msgdb "ext:wl-folder" (&rest unknown) t)
55 (declare-function wl-folder-get-elmo-folder "ext:wl-folder"
56 (entity &optional no-cache))
57 (declare-function wl-summary-goto-folder-subr "ext:wl-summary"
58 (&optional name scan-type other-window sticky interactive
59 scoring force-exit))
60 (declare-function wl-summary-jump-to-msg-by-message-id "ext:wl-summary"
61 (&optional id))
62 (declare-function wl-summary-line-from "ext:wl-summary" ())
63 (declare-function wl-summary-line-subject "ext:wl-summary" ())
64 (declare-function wl-summary-message-number "ext:wl-summary" ())
65 (declare-function wl-summary-redisplay "ext:wl-summary" (&optional arg))
66 (declare-function wl-summary-registered-temp-mark "ext:wl-action" (number))
67 (defvar wl-summary-buffer-elmo-folder)
68 (defvar wl-summary-buffer-folder-name)
70 ;; Install the link type
71 (org-add-link-type "wl" 'org-wl-open)
72 (add-hook 'org-store-link-functions 'org-wl-store-link)
74 ;; Implementation
75 (defun org-wl-store-link ()
76 "Store a link to an WL folder or message."
77 (when (eq major-mode 'wl-summary-mode)
78 (let* ((msgnum (wl-summary-message-number))
79 (mark-info (wl-summary-registered-temp-mark msgnum))
80 (folder-name
81 (if (and org-wl-link-to-refile-destination
82 mark-info
83 (equal (nth 1 mark-info) "o")) ; marked as refile
84 (nth 2 mark-info)
85 wl-summary-buffer-folder-name))
86 (message-id (elmo-message-field wl-summary-buffer-elmo-folder
87 msgnum 'message-id))
88 (wl-message-entity
89 (if (fboundp 'elmo-message-entity)
90 (elmo-message-entity
91 wl-summary-buffer-elmo-folder msgnum)
92 (elmo-msgdb-overview-get-entity
93 msgnum (wl-summary-buffer-msgdb))))
94 (from (wl-summary-line-from))
95 (to (let ((to-field (elmo-message-entity-field wl-message-entity
96 'to)))
97 (if (listp to-field)
98 (car to-field)
99 to-field)))
100 (subject (let (wl-thr-indent-string wl-parent-message-entity)
101 (wl-summary-line-subject)))
102 desc link)
103 (org-store-link-props :type "wl" :from from :to to
104 :subject subject :message-id message-id)
105 (setq message-id (org-remove-angle-brackets message-id))
106 (setq desc (org-email-link-description))
107 (setq link (org-make-link "wl:" folder-name
108 "#" message-id))
109 (org-add-link-props :link link :description desc)
110 link)))
112 (defun org-wl-open (path)
113 "Follow an WL message link."
114 ;; XXX: The imap-uw's MH folder names start with "%#".
115 (if (not (string-match "\\`\\(\\(?:%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path))
116 (error "Error in Wanderlust link"))
117 (let ((folder (match-string 1 path))
118 (article (match-string 3 path)))
119 (if (not (elmo-folder-exists-p (wl-folder-get-elmo-folder folder)))
120 (error "No such folder: %s" folder))
121 (let ((old-buf (current-buffer))
122 (old-point (point-marker)))
123 (wl-folder-goto-folder-subr folder)
124 (save-excursion
125 ;; XXX: `wl-folder-goto-folder-subr' moves point to the
126 ;; beginning of the current line. So, restore the point
127 ;; in the old buffer.
128 (set-buffer old-buf)
129 (goto-char old-point))
130 (wl-thread-open-all)
131 (and (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets
132 article))
133 (wl-summary-redisplay)))))
135 (provide 'org-wl)
137 ;;; org-wl.el ends here