org-gnus.el 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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: 6.11a
  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 of the License, or
  13. ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21. ;;
  22. ;;; Commentary:
  23. ;; This file implements links to Gnus groups and messages from within Org-mode.
  24. ;; Org-mode loads this module by default - if this is not what you want,
  25. ;; configure the variable `org-modules'.
  26. ;;; Code:
  27. (require 'org)
  28. (eval-when-compile
  29. (require 'gnus-sum))
  30. ;; Customization variables
  31. (defcustom org-usenet-links-prefer-google nil
  32. "Non-nil means, `org-store-link' will create web links to Google groups.
  33. When nil, Gnus will be used for such links.
  34. Using a prefix arg to the command \\[org-store-link] (`org-store-link')
  35. negates this setting for the duration of the command."
  36. :group 'org-link-store
  37. :type 'boolean)
  38. ;; Declare external functions and variables
  39. (declare-function gnus-article-show-summary "gnus-art" ())
  40. (declare-function gnus-summary-last-subject "gnus-sum" ())
  41. (defvar gnus-other-frame-object)
  42. (defvar gnus-group-name)
  43. (defvar gnus-article-current)
  44. ;; Install the link type
  45. (org-add-link-type "gnus" 'org-gnus-open)
  46. (add-hook 'org-store-link-functions 'org-gnus-store-link)
  47. ;; Implementation
  48. (defun org-gnus-store-link ()
  49. "Store a link to a Gnus folder or message."
  50. (cond
  51. ((eq major-mode 'gnus-group-mode)
  52. (let ((group (cond ((fboundp 'gnus-group-group-name) ; depending on Gnus
  53. (gnus-group-group-name)) ; version
  54. ((fboundp 'gnus-group-name)
  55. (gnus-group-name))
  56. (t "???")))
  57. desc link)
  58. (unless group (error "Not on a group"))
  59. (org-store-link-props :type "gnus" :group group)
  60. (setq desc (concat
  61. (if (org-xor current-prefix-arg
  62. org-usenet-links-prefer-google)
  63. "http://groups.google.com/groups?group="
  64. "gnus:")
  65. group)
  66. link (org-make-link desc))
  67. (org-add-link-props :link link :description desc)
  68. link))
  69. ((memq major-mode '(gnus-summary-mode gnus-article-mode))
  70. (and (eq major-mode 'gnus-article-mode) (gnus-article-show-summary))
  71. (let* ((group gnus-newsgroup-name)
  72. (article (gnus-summary-article-number))
  73. (header (gnus-summary-article-header article))
  74. (from (mail-header-from header))
  75. (message-id (mail-header-id header))
  76. (date (mail-header-date header))
  77. (extra (mail-header-extra header))
  78. (to (cdr (assoc 'To extra)))
  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 :to to)
  83. (setq desc (org-email-link-description))
  84. (if (org-xor current-prefix-arg org-usenet-links-prefer-google)
  85. (setq link
  86. (format "http://groups.google.com/groups?as_umsgid=%s"
  87. (org-fixup-message-id-for-http message-id)))
  88. (setq link (org-make-link "gnus:" group "#"
  89. (or message-id
  90. (number-to-string article)))))
  91. (org-add-link-props :link link :description desc)
  92. link))))
  93. (defun org-gnus-open (path)
  94. "Follow the Gnus message or folder link specified by PATH."
  95. (let (group article)
  96. (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path))
  97. (error "Error in Gnus link"))
  98. (setq group (match-string 1 path)
  99. article (match-string 3 path))
  100. (org-gnus-follow-link group article)))
  101. (defun org-gnus-follow-link (&optional group article)
  102. "Follow a Gnus link to GROUP and ARTICLE."
  103. (require 'gnus)
  104. (funcall (cdr (assq 'gnus org-link-frame-setup)))
  105. (if gnus-other-frame-object (select-frame gnus-other-frame-object))
  106. (cond ((and group article)
  107. (gnus-group-read-group 1 nil group)
  108. (gnus-summary-goto-article
  109. (if (string-match "[^0-9]" article)
  110. article
  111. (string-to-number article))
  112. nil t))
  113. (group (gnus-group-jump-to-group group))))
  114. (defun org-gnus-no-new-news ()
  115. "Like `M-x gnus' but doesn't check for new news."
  116. (if (not (gnus-alive-p)) (gnus)))
  117. (provide 'org-gnus)
  118. ;; arch-tag: 512e0840-58fa-45b3-b456-71e10fa2376d
  119. ;;; org-gnus.el ends here