Let blocking be turned-off on a per-file basis using local variables
[rgr-org-mode.git] / lisp / org-wl.el
blob3baf976cc52a7d2e7680c6c9b5bdfad5d1f441c2
1 ;;; org-wl.el --- Support for links to Wanderlust messages from within Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
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
9 ;; Version: 6.34trans
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
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.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
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'.
33 ;;; Code:
35 (require 'org)
37 (defgroup org-wl nil
38 "Options concerning the Wanderlust link."
39 :tag "Org Startup"
40 :group 'org-link)
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)
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)
57 (declare-function wl-summary-jump-to-msg-by-message-id "ext:wl-summary"
58 (&optional id))
59 (declare-function wl-summary-line-from "ext:wl-summary" ())
60 (declare-function wl-summary-line-subject "ext:wl-summary" ())
61 (declare-function wl-summary-message-number "ext:wl-summary" ())
62 (declare-function wl-summary-redisplay "ext:wl-summary" (&optional arg))
63 (declare-function wl-summary-registered-temp-mark "ext:wl-action" (number))
64 (declare-function wl-folder-goto-folder-subr "ext:wl-folder"
65 (&optional folder sticky))
66 (defvar wl-init)
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 a 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 (let ((from-field (elmo-message-entity-field wl-message-entity
95 'from)))
96 (if (listp from-field)
97 (car from-field)
98 from-field)))
99 (to (let ((to-field (elmo-message-entity-field wl-message-entity
100 'to)))
101 (if (listp to-field)
102 (car to-field)
103 to-field)))
104 (subject (let (wl-thr-indent-string wl-parent-message-entity)
105 (wl-summary-line-subject)))
106 desc link)
107 ;; remove text properties of subject string to avoid possible bug
108 ;; when formatting the subject
109 (set-text-properties 0 (length subject) nil subject)
111 (org-store-link-props :type "wl" :from from :to to
112 :subject subject :message-id message-id)
113 (setq message-id (org-remove-angle-brackets message-id))
114 (setq desc (org-email-link-description))
115 (setq link (org-make-link "wl:" folder-name
116 "#" message-id))
117 (org-add-link-props :link link :description desc)
118 link)))
120 (defun org-wl-open (path)
121 "Follow the WL message link specified by PATH."
122 (require 'wl)
123 (unless wl-init (wl))
124 ;; XXX: The imap-uw's MH folder names start with "%#".
125 (if (not (string-match "\\`\\(\\(?:%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path))
126 (error "Error in Wanderlust link"))
127 (let ((folder (match-string 1 path))
128 (article (match-string 3 path)))
129 (if (not (elmo-folder-exists-p (org-no-warnings
130 (wl-folder-get-elmo-folder folder))))
131 (error "No such folder: %s" folder))
132 (let ((old-buf (current-buffer))
133 (old-point (point-marker)))
134 (wl-folder-goto-folder-subr folder)
135 (save-excursion
136 ;; XXX: `wl-folder-goto-folder-subr' moves point to the
137 ;; beginning of the current line. So, restore the point
138 ;; in the old buffer.
139 (set-buffer old-buf)
140 (goto-char old-point))
141 (and (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets
142 article))
143 (wl-summary-redisplay)))))
145 (provide 'org-wl)
147 ;; arch-tag: 29b75a0f-ef2e-430b-8abc-acff75bde54a
149 ;;; org-wl.el ends here