org-wl.el 5.1 KB

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