release 6.01b
[org-mode/org-tableheadings.git] / lisp / org-gnus.el
blob61bc12181850971964767c138513c0add10a1742
1 ;;; org-gnus.el --- Support for links to Gnus groups and messages from within 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: 6.01b
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 Gnus groups and messages from within Org-mode.
31 ;; Org-mode loads this module by default - if this is not what you want,
32 ;; configure the variable `org-modules'.
34 ;;; Code:
36 (require 'org)
37 (eval-when-compile
38 (require 'gnus-sum))
40 ;; Customization variables
42 (defcustom org-usenet-links-prefer-google nil
43 "Non-nil means, `org-store-link' will create web links to Google groups.
44 When nil, Gnus will be used for such links.
45 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
46 negates this setting for the duration of the command."
47 :group 'org-link-store
48 :type 'boolean)
50 ;; Declare external functions and variables
51 (declare-function gnus-article-show-summary "gnus-art" ())
52 (declare-function gnus-summary-last-subject "gnus-sum" ())
53 (defvar gnus-other-frame-object)
54 (defvar gnus-group-name)
55 (defvar gnus-article-current)
57 ;; Install the link type
58 (org-add-link-type "gnus" 'org-gnus-open)
59 (add-hook 'org-store-link-functions 'org-gnus-store-link)
61 ;; Implementation
62 (defun org-gnus-store-link ()
63 "Store a link to a Gnus folder or message."
64 (cond
65 ((eq major-mode 'gnus-group-mode)
66 (let ((group (cond ((fboundp 'gnus-group-group-name) ; depending on Gnus
67 (gnus-group-group-name)) ; version
68 ((fboundp 'gnus-group-name)
69 (gnus-group-name))
70 (t "???")))
71 desc link)
72 (unless group (error "Not on a group"))
73 (org-store-link-props :type "gnus" :group group)
74 (setq desc (concat
75 (if (org-xor current-prefix-arg
76 org-usenet-links-prefer-google)
77 "http://groups.google.com/groups?group="
78 "gnus:")
79 group)
80 link (org-make-link desc))
81 (org-add-link-props :link link :description desc)
82 link))
84 ((memq major-mode '(gnus-summary-mode gnus-article-mode))
85 (and (eq major-mode 'gnus-article-mode) (gnus-article-show-summary))
86 (let* ((group gnus-newsgroup-name)
87 (article (gnus-summary-article-number))
88 (header (gnus-summary-article-header article))
89 (from (mail-header-from header))
90 (message-id (mail-header-id header))
91 (date (mail-header-date header))
92 (subject (gnus-summary-subject-string))
93 desc link)
94 (org-store-link-props :type "gnus" :from from :subject subject
95 :message-id message-id :group group)
96 (setq desc (org-email-link-description))
97 (if (org-xor current-prefix-arg org-usenet-links-prefer-google)
98 (setq link
99 (concat
100 desc "\n "
101 (format "http://groups.google.com/groups?as_umsgid=%s"
102 (org-fixup-message-id-for-http message-id))))
103 (setq link (org-make-link "gnus:" group
104 "#" (number-to-string article))))
105 (org-add-link-props :link link :description desc)
106 link))))
108 (defun org-gnus-open (path)
109 "Follow the Gnus message or folder link specified by PATH."
110 (let (group article)
111 (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path))
112 (error "Error in Gnus link"))
113 (setq group (match-string 1 path)
114 article (match-string 3 path))
115 (org-gnus-follow-link group article)))
117 (defun org-gnus-follow-link (&optional group article)
118 "Follow a Gnus link to GROUP and ARTICLE."
119 (require 'gnus)
120 (funcall (cdr (assq 'gnus org-link-frame-setup)))
121 (if gnus-other-frame-object (select-frame gnus-other-frame-object))
122 (cond ((and group article)
123 (gnus-group-read-group 1 nil group)
124 (gnus-summary-goto-article (string-to-number article) nil t))
125 (group (gnus-group-jump-to-group group))))
127 (provide 'org-gnus)
129 ;;; org-gnus.el ends here