Docbook export: Implement ordered lists with offset
[org-mode/org-tableheadings.git] / lisp / org-wl.el
blob05343425cdf0f23064ff404e3dc06e19c7d368d5
1 ;;; org-wl.el --- Support for links to Wanderlust messages from within Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: Tokuya Kameshima <kames at fa2 dot so-net dot ne dot jp>
7 ;; David Maus <dmaus at ictsoc dot de>
8 ;; Keywords: outlines, hypermedia, calendar, wp
9 ;; Homepage: http://orgmode.org
10 ;; Version: 6.35trans
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;; Commentary:
30 ;; This file implements links to Wanderlust messages from within Org-mode.
31 ;; Org-mode loads this module by default - if this is not what you want,
32 ;; configure the variable `org-modules'.
34 ;;; Code:
36 (require 'org)
38 (defgroup org-wl nil
39 "Options concerning the Wanderlust link."
40 :tag "Org Startup"
41 :group 'org-link)
43 (defcustom org-wl-link-to-refile-destination t
44 "Create a link to the refile destination if the message is marked as refile."
45 :group 'org-wl
46 :type 'boolean)
48 (defcustom org-wl-link-remove-filter nil
49 "Remove filter condition if message is filter folder."
50 :group 'org-wl
51 :type 'boolean)
53 (defcustom org-wl-shimbun-prefer-web-links nil
54 "If non-nil create web links for shimbun messages."
55 :group 'org-wl
56 :type 'boolean)
58 (defcustom org-wl-nntp-prefer-web-links nil
59 "If non-nil create web links for nntp messages.
60 When folder name contains string \"gmane\" link to gmane,
61 googlegroups otherwise."
62 :type 'boolean
63 :group 'org-wl)
65 (defcustom org-wl-namazu-default-index nil
66 "Default namazu search index."
67 :type 'directory
68 :group 'org-wl)
70 ;; Declare external functions and variables
71 (declare-function elmo-folder-exists-p "ext:elmo" (folder) t)
72 (declare-function elmo-message-entity-field "ext:elmo-msgdb"
73 (entity field &optional type))
74 (declare-function elmo-message-field "ext:elmo"
75 (folder number field &optional type) t)
76 (declare-function elmo-msgdb-overview-get-entity "ext:elmo" (id msgdb) t)
77 ;; Backward compatibility to old version of wl
78 (declare-function wl "ext:wl" () t)
79 (declare-function wl-summary-buffer-msgdb "ext:wl-folder" () t)
80 (declare-function wl-summary-jump-to-msg-by-message-id "ext:wl-summary"
81 (&optional id))
82 (declare-function wl-summary-line-from "ext:wl-summary" ())
83 (declare-function wl-summary-line-subject "ext:wl-summary" ())
84 (declare-function wl-summary-message-number "ext:wl-summary" ())
85 (declare-function wl-summary-redisplay "ext:wl-summary" (&optional arg))
86 (declare-function wl-summary-registered-temp-mark "ext:wl-action" (number))
87 (declare-function wl-folder-goto-folder-subr "ext:wl-folder"
88 (&optional folder sticky))
89 (defvar wl-init)
90 (defvar wl-summary-buffer-elmo-folder)
91 (defvar wl-summary-buffer-folder-name)
93 (defconst org-wl-folder-types
94 '(("%" . imap) ("-" . nntp) ("+" . mh) ("=" . spool)
95 ("$" . archive) ("&" . pop) ("@" . shimbun) ("[" . search)
96 ("*" . multi) ("/" . filter) ("|" . pipe) ("'" . internal))
97 "List of folder indicators. See Wanderlust manual, section 3.")
100 ;; Install the link type
101 (org-add-link-type "wl" 'org-wl-open)
102 (add-hook 'org-store-link-functions 'org-wl-store-link)
104 ;; Implementation
106 (defun org-wl-folder-type (folder)
107 "Return symbol that indicicates the type of FOLDER.
108 FOLDER is the wanderlust folder name. The first character of the
109 folder name determines the the folder type."
110 (let* ((indicator (substring folder 0 1))
111 (type (cdr (assoc indicator org-wl-folder-types))))
112 ;; maybe access or file folder
113 (when (not type)
114 (setq type
115 (cond
116 ((and (>= (length folder) 5)
117 (string= (substring folder 0 5) "file:"))
118 'file)
119 ((and (>= (length folder) 7)
120 (string= (substring folder 0 7) "access:"))
121 'access)
123 nil))))
124 type))
126 (defun org-wl-store-link ()
127 "Store a link to a WL folder or message."
128 (when (eq major-mode 'wl-summary-mode)
129 (let* ((msgnum (wl-summary-message-number))
130 (mark-info (wl-summary-registered-temp-mark msgnum))
131 (folder-name
132 (if (and org-wl-link-to-refile-destination
133 mark-info
134 (equal (nth 1 mark-info) "o")) ; marked as refile
135 (nth 2 mark-info)
136 wl-summary-buffer-folder-name))
137 (folder-type (org-wl-folder-type folder-name))
138 (message-id (elmo-message-field wl-summary-buffer-elmo-folder
139 msgnum 'message-id))
140 (wl-message-entity
141 (if (fboundp 'elmo-message-entity)
142 (elmo-message-entity
143 wl-summary-buffer-elmo-folder msgnum)
144 (elmo-msgdb-overview-get-entity
145 msgnum (wl-summary-buffer-msgdb))))
146 (from (let ((from-field (elmo-message-entity-field wl-message-entity
147 'from)))
148 (if (listp from-field)
149 (car from-field)
150 from-field)))
151 (to (let ((to-field (elmo-message-entity-field wl-message-entity
152 'to)))
153 (if (listp to-field)
154 (car to-field)
155 to-field)))
156 (xref (let ((xref-field (elmo-message-entity-field wl-message-entity
157 'xref)))
158 (if (listp xref-field)
159 (car xref-field)
160 xref-field)))
161 (subject (let (wl-thr-indent-string wl-parent-message-entity)
162 (wl-summary-line-subject)))
163 desc link)
165 ;; remove text properties of subject string to avoid possible bug
166 ;; when formatting the subject
167 ;; (Emacs bug #5306, fixed)
168 (set-text-properties 0 (length subject) nil subject)
170 ;; maybe remove filter condition
171 (when (and (eq folder-type 'filter) org-wl-link-remove-filter)
172 (while (eq (org-wl-folder-type folder-name) 'filter)
173 (setq folder-name
174 (replace-regexp-in-string "^/[^/]+/" "" folder-name))))
176 ;; maybe create http link
177 (cond
178 ((and (eq folder-type 'shimbun) org-wl-shimbun-prefer-web-links xref)
179 (org-store-link-props :type "http" :link xref :description subject
180 :from from :to to :message-id message-id
181 :subject subject))
182 ((and (eq folder-type 'nntp) org-wl-nntp-prefer-web-links)
183 (setq link (format
184 (if (string-match "gmane\\." folder-name)
185 "http://mid.gmane.org/%s"
186 "http://groups.google.com/groups/search?as_umsgid=%s")
187 (org-fixup-message-id-for-http message-id)))
188 (org-store-link-props :type "http" :link link :description subject
189 :from from :to to :message-id message-id
190 :subject subject))
192 (org-store-link-props :type "wl" :from from :to to
193 :subject subject :message-id message-id)
194 (setq message-id (org-remove-angle-brackets message-id))
195 (setq desc (org-email-link-description))
196 (setq link (org-make-link "wl:" folder-name "#" message-id))
197 (org-add-link-props :link link :description desc)))
198 (or link xref))))
200 (defun org-wl-open (path)
201 "Follow the WL message link specified by PATH.
202 When called with one prefix, open message in namazu search folder
203 with `org-wl-namazu-default-index' as search index. When called
204 with two prefixes or `org-wl-namazu-default-index' is nil, ask
205 for namazu index."
206 (require 'wl)
207 (unless wl-init (wl))
208 ;; XXX: The imap-uw's MH folder names start with "%#".
209 (if (not (string-match "\\`\\(\\(?:%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path))
210 (error "Error in Wanderlust link"))
211 (let ((folder (match-string 1 path))
212 (article (match-string 3 path)))
213 ;; maybe open message in namazu search folder
214 (when current-prefix-arg
215 (setq folder (concat "[" article "]"
216 (if (and (equal current-prefix-arg '(4))
217 org-wl-namazu-default-index)
218 org-wl-namazu-default-index
219 (read-directory-name "Namazu index: ")))))
220 (if (not (elmo-folder-exists-p (org-no-warnings
221 (wl-folder-get-elmo-folder folder))))
222 (error "No such folder: %s" folder))
223 (let ((old-buf (current-buffer))
224 (old-point (point-marker)))
225 (wl-folder-goto-folder-subr folder)
226 (with-current-buffer old-buf
227 ;; XXX: `wl-folder-goto-folder-subr' moves point to the
228 ;; beginning of the current line. So, restore the point
229 ;; in the old buffer.
230 (goto-char old-point))
231 (and (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets
232 article))
233 (wl-summary-redisplay)))))
235 (provide 'org-wl)
237 ;; arch-tag: 29b75a0f-ef2e-430b-8abc-acff75bde54a
239 ;;; org-wl.el ends here