org-gnus.el 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ;;; org-gnus.el --- Support for links to Gnus groups and messages from within Org-mode
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 1.0
  7. ;;
  8. ;; This file is part of GNU Emacs.
  9. ;;
  10. ;; GNU Emacs is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 3, or (at your option)
  13. ;; any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. ;;
  24. ;;; Commentary:
  25. ;; This file implements links to Gnus groups and messages from within Org-mode.
  26. ;; Org-mode loads this module by default - if this is not what you want,
  27. ;; configure the variable `org-modules'.
  28. ;;; Code:
  29. (require 'org)
  30. (eval-when-compile
  31. (require 'gnus-sum))
  32. ;; Customization variables
  33. (defcustom org-usenet-links-prefer-google nil
  34. "Non-nil means, `org-store-link' will create web links to Google groups.
  35. When nil, Gnus will be used for such links.
  36. Using a prefix arg to the command \\[org-store-link] (`org-store-link')
  37. negates this setting for the duration of the command."
  38. :group 'org-link-store
  39. :type 'boolean)
  40. ;; Declare external functions and variables
  41. (declare-function gnus-article-show-summary "gnus-art" ())
  42. (declare-function gnus-summary-last-subject "gnus-sum" ())
  43. (defvar gnus-other-frame-object)
  44. (defvar gnus-group-name)
  45. (defvar gnus-article-current)
  46. ;; Install the link type
  47. (org-add-link-type "gnus" 'org-gnus-open)
  48. (add-hook 'org-store-link-functions 'org-gnus-store-link)
  49. ;; Implementation
  50. (defun org-gnus-store-link ()
  51. "Store a link to a Gnus folder or message."
  52. (cond
  53. ((eq major-mode 'gnus-group-mode)
  54. (let ((group (cond ((fboundp 'gnus-group-group-name) ; depending on Gnus
  55. (gnus-group-group-name)) ; version
  56. ((fboundp 'gnus-group-name)
  57. (gnus-group-name))
  58. (t "???")))
  59. desc link)
  60. (unless group (error "Not on a group"))
  61. (org-store-link-props :type "gnus" :group group)
  62. (setq desc (concat
  63. (if (org-xor current-prefix-arg
  64. org-usenet-links-prefer-google)
  65. "http://groups.google.com/groups?group="
  66. "gnus:")
  67. group)
  68. link (org-make-link desc))
  69. (org-add-link-props :link link :description desc)
  70. link))
  71. ((memq major-mode '(gnus-summary-mode gnus-article-mode))
  72. (and (eq major-mode 'gnus-article-mode) (gnus-article-show-summary))
  73. (let* ((group gnus-newsgroup-name)
  74. (article (gnus-summary-article-number))
  75. (header (gnus-summary-article-header article))
  76. (from (mail-header-from header))
  77. (message-id (mail-header-id header))
  78. (date (mail-header-date header))
  79. (subject (gnus-summary-subject-string))
  80. desc link)
  81. (org-store-link-props :type "gnus" :from from :subject subject
  82. :message-id message-id :group group)
  83. (setq desc (org-email-link-description))
  84. (if (org-xor current-prefix-arg org-usenet-links-prefer-google)
  85. (setq link
  86. (concat
  87. desc "\n "
  88. (format "http://groups.google.com/groups?as_umsgid=%s"
  89. (org-fixup-message-id-for-http message-id))))
  90. (setq link (org-make-link "gnus:" group
  91. "#" (number-to-string article))))
  92. (org-add-link-props :link link :description desc)
  93. link))))
  94. (defun org-gnus-open (path)
  95. "Follow the Gnus message or folder link specified by PATH."
  96. (let (group article)
  97. (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path))
  98. (error "Error in Gnus link"))
  99. (setq group (match-string 1 path)
  100. article (match-string 3 path))
  101. (org-gnus-follow-link group article)))
  102. (defun org-gnus-follow-link (&optional group article)
  103. "Follow a Gnus link to GROUP and ARTICLE."
  104. (require 'gnus)
  105. (funcall (cdr (assq 'gnus org-link-frame-setup)))
  106. (if gnus-other-frame-object (select-frame gnus-other-frame-object))
  107. (cond ((and group article)
  108. (gnus-group-read-group 1 nil group)
  109. (gnus-summary-goto-article (string-to-number article) nil t))
  110. (group (gnus-group-jump-to-group group))))
  111. (provide 'org-gnus)
  112. ;;; org-gnus.el ends here