Reduce the cluttering in the agenda display due to ISO weeks.
[org-mode.git] / org-wl.el
blobbf3b90cc9df086cef4f00a489c634d6f4e3ea269
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 ;; Declare external functions and variables
37 (declare-function elmo-folder-exists-p "ext:elmo" (folder) t)
38 (declare-function elmo-message-entity-field "ext:elmo-msgdb"
39 (entity field &optional type))
40 (declare-function elmo-message-field "ext:elmo"
41 (folder number field &optional type) t)
42 (declare-function elmo-msgdb-overview-get-entity "ext:elmo" (&rest unknown) t)
43 ;; Backward compatibility to old version of wl
44 (declare-function wl-summary-buffer-msgdb "ext:wl-folder" (&rest unknown) t)
45 (declare-function wl-folder-get-elmo-folder "ext:wl-folder"
46 (entity &optional no-cache))
47 (declare-function wl-summary-goto-folder-subr "ext:wl-summary"
48 (&optional name scan-type other-window sticky interactive
49 scoring force-exit))
50 (declare-function wl-summary-jump-to-msg-by-message-id "ext:wl-summary"
51 (&optional id))
52 (declare-function wl-summary-line-from "ext:wl-summary" ())
53 (declare-function wl-summary-line-subject "ext:wl-summary" ())
54 (declare-function wl-summary-message-number "ext:wl-summary" ())
55 (declare-function wl-summary-redisplay "ext:wl-summary" (&optional arg))
56 (defvar wl-summary-buffer-elmo-folder)
57 (defvar wl-summary-buffer-folder-name)
59 ;; Install the link type
60 (org-add-link-type "wl" 'org-wl-open)
61 (add-hook 'org-store-link-functions 'org-wl-store-link)
63 ;; Implementation
64 (defun org-wl-store-link ()
65 "Store a link to an WL folder or message."
66 (when (eq major-mode 'wl-summary-mode)
67 (let* ((msgnum (wl-summary-message-number))
68 (message-id (elmo-message-field wl-summary-buffer-elmo-folder
69 msgnum 'message-id))
70 (wl-message-entity
71 (if (fboundp 'elmo-message-entity)
72 (elmo-message-entity
73 wl-summary-buffer-elmo-folder msgnum)
74 (elmo-msgdb-overview-get-entity
75 msgnum (wl-summary-buffer-msgdb))))
76 (from (wl-summary-line-from))
77 (to (car (elmo-message-entity-field wl-message-entity 'to)))
78 (subject (let (wl-thr-indent-string wl-parent-message-entity)
79 (wl-summary-line-subject)))
80 desc link)
81 (org-store-link-props :type "wl" :from from :to to
82 :subject subject :message-id message-id)
83 (setq message-id (org-remove-angle-brackets message-id))
84 (setq desc (org-email-link-description))
85 (setq link (org-make-link "wl:" wl-summary-buffer-folder-name
86 "#" message-id))
87 (org-add-link-props :link link :description desc)
88 link)))
90 (defun org-wl-open (path)
91 "Follow an WL message link."
92 (let (folder article)
93 (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path))
94 (error "Error in Wanderlust link"))
95 (setq folder (match-string 1 path)
96 article (match-string 3 path))
97 (org-wl-follow-link folder article)))
99 (defun org-wl-follow-link (folder article)
100 "Follow a Wanderlust link to FOLDER and ARTICLE."
101 (if (and (string= folder "%")
102 article
103 (string-match "^\\([^#]+\\)\\(#\\(.*\\)\\)?" article))
104 ;; XXX: imap-uw supports folders starting with '#' such as "#mh/inbox".
105 ;; Thus, we recompose folder and article ids.
106 (setq folder (format "%s#%s" folder (match-string 1 article))
107 article (match-string 3 article)))
108 (if (not (elmo-folder-exists-p (wl-folder-get-elmo-folder folder)))
109 (error "No such folder: %s" folder))
110 (wl-summary-goto-folder-subr folder 'no-sync t nil t nil nil)
111 (and article
112 (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets article))
113 (wl-summary-redisplay)))
115 (provide 'org-wl)
117 ;;; org-wl.el ends here