org-wl.el 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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.30trans
  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-folder-get-elmo-folder "ext:wl-folder"
  48. ; (entity &optional no-cache))
  49. (declare-function wl-summary-goto-folder-subr "ext:wl-summary"
  50. (&optional name scan-type other-window sticky interactive
  51. scoring force-exit))
  52. (declare-function wl-summary-jump-to-msg-by-message-id "ext:wl-summary"
  53. (&optional id))
  54. (declare-function wl-summary-line-from "ext:wl-summary" ())
  55. (declare-function wl-summary-line-subject "ext:wl-summary" ())
  56. (declare-function wl-summary-message-number "ext:wl-summary" ())
  57. (declare-function wl-summary-redisplay "ext:wl-summary" (&optional arg))
  58. (declare-function wl-summary-registered-temp-mark "ext:wl-action" (number))
  59. (declare-function wl-folder-goto-folder-subr "ext:wl-folder"
  60. (&optional folder sticky))
  61. (defvar wl-init)
  62. (defvar wl-summary-buffer-elmo-folder)
  63. (defvar wl-summary-buffer-folder-name)
  64. ;; Install the link type
  65. (org-add-link-type "wl" 'org-wl-open)
  66. (add-hook 'org-store-link-functions 'org-wl-store-link)
  67. ;; Implementation
  68. (defun org-wl-store-link ()
  69. "Store a link to a WL folder or message."
  70. (when (eq major-mode 'wl-summary-mode)
  71. (let* ((msgnum (wl-summary-message-number))
  72. (mark-info (wl-summary-registered-temp-mark msgnum))
  73. (folder-name
  74. (if (and org-wl-link-to-refile-destination
  75. mark-info
  76. (equal (nth 1 mark-info) "o")) ; marked as refile
  77. (nth 2 mark-info)
  78. wl-summary-buffer-folder-name))
  79. (message-id (elmo-message-field wl-summary-buffer-elmo-folder
  80. msgnum 'message-id))
  81. (wl-message-entity
  82. (if (fboundp 'elmo-message-entity)
  83. (elmo-message-entity
  84. wl-summary-buffer-elmo-folder msgnum)
  85. (elmo-msgdb-overview-get-entity
  86. msgnum (wl-summary-buffer-msgdb))))
  87. (from (wl-summary-line-from))
  88. (to (let ((to-field (elmo-message-entity-field wl-message-entity
  89. 'to)))
  90. (if (listp to-field)
  91. (car to-field)
  92. to-field)))
  93. (subject (let (wl-thr-indent-string wl-parent-message-entity)
  94. (wl-summary-line-subject)))
  95. desc link)
  96. (org-store-link-props :type "wl" :from from :to to
  97. :subject subject :message-id message-id)
  98. (setq message-id (org-remove-angle-brackets message-id))
  99. (setq desc (org-email-link-description))
  100. (setq link (org-make-link "wl:" folder-name
  101. "#" message-id))
  102. (org-add-link-props :link link :description desc)
  103. link)))
  104. (defun org-wl-open (path)
  105. "Follow the WL message link specified by PATH."
  106. (require 'wl)
  107. (unless wl-init (wl))
  108. ;; XXX: The imap-uw's MH folder names start with "%#".
  109. (if (not (string-match "\\`\\(\\(?:%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path))
  110. (error "Error in Wanderlust link"))
  111. (let ((folder (match-string 1 path))
  112. (article (match-string 3 path)))
  113. (if (not (elmo-folder-exists-p (org-no-warnings
  114. (wl-folder-get-elmo-folder folder))))
  115. (error "No such folder: %s" folder))
  116. (let ((old-buf (current-buffer))
  117. (old-point (point-marker)))
  118. (wl-folder-goto-folder-subr folder)
  119. (save-excursion
  120. ;; XXX: `wl-folder-goto-folder-subr' moves point to the
  121. ;; beginning of the current line. So, restore the point
  122. ;; in the old buffer.
  123. (set-buffer old-buf)
  124. (goto-char old-point))
  125. (and (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets
  126. article))
  127. (wl-summary-redisplay)))))
  128. (provide 'org-wl)
  129. ;; arch-tag: 29b75a0f-ef2e-430b-8abc-acff75bde54a
  130. ;;; org-wl.el ends here