(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
[bpt/emacs.git] / lisp / org / org-wl.el
CommitLineData
20908596
CD
1;;; org-wl.el --- Support for links to Wanderlust messages from within Org-mode
2
1e4f816a
CD
3;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4;; Free Software Foundation, Inc.
20908596
CD
5
6;; Author: Tokuya Kameshima <kames at fa2 dot so-net dot ne dot jp>
7;; Keywords: outlines, hypermedia, calendar, wp
8;; Homepage: http://orgmode.org
a2a2e7fb 9;; Version: 6.20g
20908596
CD
10;;
11;; This file is part of GNU Emacs.
12;;
b1fc2b50 13;; GNU Emacs is free software: you can redistribute it and/or modify
20908596 14;; it under the terms of the GNU General Public License as published by
b1fc2b50
GM
15;; the Free Software Foundation, either version 3 of the License, or
16;; (at your option) any later version.
20908596
CD
17
18;; GNU Emacs is distributed in the hope that it will be useful,
19;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;; GNU General Public License for more details.
22
23;; You should have received a copy of the GNU General Public License
b1fc2b50 24;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
20908596
CD
25;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26;;
27;;; Commentary:
28
29;; This file implements links to Wanderlust messages from within Org-mode.
30;; Org-mode loads this module by default - if this is not what you want,
31;; configure the variable `org-modules'.
32
33;;; Code:
34
35(require 'org)
36
37(defgroup org-wl nil
38 "Options concerning the Wanderlust link."
39 :tag "Org Startup"
40 :group 'org-link)
41
42(defcustom org-wl-link-to-refile-destination t
43 "Create a link to the refile destination if the message is marked as refile."
44 :group 'org-wl
45 :type 'boolean)
46
47;; Declare external functions and variables
48(declare-function elmo-folder-exists-p "ext:elmo" (folder) t)
49(declare-function elmo-message-entity-field "ext:elmo-msgdb"
50 (entity field &optional type))
51(declare-function elmo-message-field "ext:elmo"
52 (folder number field &optional type) t)
53(declare-function elmo-msgdb-overview-get-entity "ext:elmo" (id msgdb) t)
54;; Backward compatibility to old version of wl
55(declare-function wl "ext:wl" () t)
56(declare-function wl-summary-buffer-msgdb "ext:wl-folder" () t)
621f83e4
CD
57;(declare-function wl-folder-get-elmo-folder "ext:wl-folder"
58; (entity &optional no-cache))
20908596
CD
59(declare-function wl-summary-goto-folder-subr "ext:wl-summary"
60 (&optional name scan-type other-window sticky interactive
61 scoring force-exit))
62(declare-function wl-summary-jump-to-msg-by-message-id "ext:wl-summary"
63 (&optional id))
64(declare-function wl-summary-line-from "ext:wl-summary" ())
65(declare-function wl-summary-line-subject "ext:wl-summary" ())
66(declare-function wl-summary-message-number "ext:wl-summary" ())
67(declare-function wl-summary-redisplay "ext:wl-summary" (&optional arg))
68(declare-function wl-summary-registered-temp-mark "ext:wl-action" (number))
69(declare-function wl-folder-goto-folder-subr "ext:wl-folder"
70 (&optional folder sticky))
20908596
CD
71(defvar wl-init)
72(defvar wl-summary-buffer-elmo-folder)
73(defvar wl-summary-buffer-folder-name)
74
75;; Install the link type
76(org-add-link-type "wl" 'org-wl-open)
77(add-hook 'org-store-link-functions 'org-wl-store-link)
78
79;; Implementation
80(defun org-wl-store-link ()
81 "Store a link to a WL folder or message."
82 (when (eq major-mode 'wl-summary-mode)
83 (let* ((msgnum (wl-summary-message-number))
84 (mark-info (wl-summary-registered-temp-mark msgnum))
85 (folder-name
86 (if (and org-wl-link-to-refile-destination
87 mark-info
88 (equal (nth 1 mark-info) "o")) ; marked as refile
89 (nth 2 mark-info)
90 wl-summary-buffer-folder-name))
91 (message-id (elmo-message-field wl-summary-buffer-elmo-folder
92 msgnum 'message-id))
93 (wl-message-entity
94 (if (fboundp 'elmo-message-entity)
95 (elmo-message-entity
96 wl-summary-buffer-elmo-folder msgnum)
97 (elmo-msgdb-overview-get-entity
98 msgnum (wl-summary-buffer-msgdb))))
99 (from (wl-summary-line-from))
100 (to (let ((to-field (elmo-message-entity-field wl-message-entity
101 'to)))
102 (if (listp to-field)
103 (car to-field)
104 to-field)))
105 (subject (let (wl-thr-indent-string wl-parent-message-entity)
106 (wl-summary-line-subject)))
107 desc link)
108 (org-store-link-props :type "wl" :from from :to to
109 :subject subject :message-id message-id)
110 (setq message-id (org-remove-angle-brackets message-id))
111 (setq desc (org-email-link-description))
112 (setq link (org-make-link "wl:" folder-name
113 "#" message-id))
114 (org-add-link-props :link link :description desc)
115 link)))
116
117(defun org-wl-open (path)
118 "Follow the WL message link specified by PATH."
119 (require 'wl)
120 (unless wl-init (wl))
121 ;; XXX: The imap-uw's MH folder names start with "%#".
122 (if (not (string-match "\\`\\(\\(?:%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path))
123 (error "Error in Wanderlust link"))
124 (let ((folder (match-string 1 path))
125 (article (match-string 3 path)))
621f83e4
CD
126 (if (not (elmo-folder-exists-p (org-no-warnings
127 (wl-folder-get-elmo-folder folder))))
20908596
CD
128 (error "No such folder: %s" folder))
129 (let ((old-buf (current-buffer))
130 (old-point (point-marker)))
131 (wl-folder-goto-folder-subr folder)
132 (save-excursion
133 ;; XXX: `wl-folder-goto-folder-subr' moves point to the
134 ;; beginning of the current line. So, restore the point
135 ;; in the old buffer.
136 (set-buffer old-buf)
137 (goto-char old-point))
20908596
CD
138 (and (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets
139 article))
140 (wl-summary-redisplay)))))
141
142(provide 'org-wl)
143
88ac7b50 144;; arch-tag: 29b75a0f-ef2e-430b-8abc-acff75bde54a
b349f79f 145
20908596 146;;; org-wl.el ends here