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
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)
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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'.
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
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
)
62 (defun org-gnus-store-link ()
63 "Store a link to a Gnus folder or message."
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
)
72 (unless group
(error "Not on a group"))
73 (org-store-link-props :type
"gnus" :group group
)
75 (if (org-xor current-prefix-arg
76 org-usenet-links-prefer-google
)
77 "http://groups.google.com/groups?group="
80 link
(org-make-link desc
))
81 (org-add-link-props :link link
:description desc
)
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))
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
)
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
)
108 (defun org-gnus-open (path)
109 "Follow the Gnus message or folder link specified by PATH."
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."
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
))))
129 ;;; org-gnus.el ends here