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 of the License, or
15 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;; This file implements links to Gnus groups and messages from within Org-mode.
29 ;; Org-mode loads this module by default - if this is not what you want,
30 ;; configure the variable `org-modules'.
38 ;; Customization variables
40 (defcustom org-usenet-links-prefer-google nil
41 "Non-nil means, `org-store-link' will create web links to Google groups.
42 When nil, Gnus will be used for such links.
43 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
44 negates this setting for the duration of the command."
45 :group
'org-link-store
48 ;; Declare external functions and variables
49 (declare-function gnus-article-show-summary
"gnus-art" ())
50 (declare-function gnus-summary-last-subject
"gnus-sum" ())
51 (defvar gnus-other-frame-object
)
52 (defvar gnus-group-name
)
53 (defvar gnus-article-current
)
55 ;; Install the link type
56 (org-add-link-type "gnus" 'org-gnus-open
)
57 (add-hook 'org-store-link-functions
'org-gnus-store-link
)
60 (defun org-gnus-store-link ()
61 "Store a link to a Gnus folder or message."
63 ((eq major-mode
'gnus-group-mode
)
64 (let ((group (cond ((fboundp 'gnus-group-group-name
) ; depending on Gnus
65 (gnus-group-group-name)) ; version
66 ((fboundp 'gnus-group-name
)
70 (unless group
(error "Not on a group"))
71 (org-store-link-props :type
"gnus" :group group
)
73 (if (org-xor current-prefix-arg
74 org-usenet-links-prefer-google
)
75 "http://groups.google.com/groups?group="
78 link
(org-make-link desc
))
79 (org-add-link-props :link link
:description desc
)
82 ((memq major-mode
'(gnus-summary-mode gnus-article-mode
))
83 (and (eq major-mode
'gnus-article-mode
) (gnus-article-show-summary))
84 (let* ((group gnus-newsgroup-name
)
85 (article (gnus-summary-article-number))
86 (header (gnus-summary-article-header article
))
87 (from (mail-header-from header
))
88 (message-id (mail-header-id header
))
89 (date (mail-header-date header
))
90 (subject (gnus-summary-subject-string))
92 (org-store-link-props :type
"gnus" :from from
:subject subject
93 :message-id message-id
:group group
)
94 (setq desc
(org-email-link-description))
95 (if (org-xor current-prefix-arg org-usenet-links-prefer-google
)
99 (format "http://groups.google.com/groups?as_umsgid=%s"
100 (org-fixup-message-id-for-http message-id
))))
101 (setq link
(org-make-link "gnus:" group
102 "#" (number-to-string article
))))
103 (org-add-link-props :link link
:description desc
)
106 (defun org-gnus-open (path)
107 "Follow the Gnus message or folder link specified by PATH."
109 (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path
))
110 (error "Error in Gnus link"))
111 (setq group
(match-string 1 path
)
112 article
(match-string 3 path
))
113 (org-gnus-follow-link group article
)))
115 (defun org-gnus-follow-link (&optional group article
)
116 "Follow a Gnus link to GROUP and ARTICLE."
118 (funcall (cdr (assq 'gnus org-link-frame-setup
)))
119 (if gnus-other-frame-object
(select-frame gnus-other-frame-object
))
120 (cond ((and group article
)
121 (gnus-group-read-group 1 nil group
)
122 (gnus-summary-goto-article (string-to-number article
) nil t
))
123 (group (gnus-group-jump-to-group group
))))
127 ;; arch-tag: 512e0840-58fa-45b3-b456-71e10fa2376d
129 ;;; org-gnus.el ends here