Merge branch 'maint'
[org-mode.git] / lisp / org-info.el
blobb9f7ba00622e2904da720c2a340a7ecd86809177
1 ;;; org-info.el --- Support for links to Info nodes from within Org-Mode
3 ;; Copyright (C) 2004-2015 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 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file implements links to Info nodes from within Org-mode.
28 ;; Org-mode loads this module by default - if this is not what you want,
29 ;; configure the variable `org-modules'.
31 ;;; Code:
33 (require 'org)
35 ;; Declare external functions and variables
37 (declare-function Info-find-node "info" (filename nodename
38 &optional no-going-back))
39 (defvar Info-current-file)
40 (defvar Info-current-node)
42 ;; Install the link type
43 (org-add-link-type "info" 'org-info-open 'org-info-export)
44 (add-hook 'org-store-link-functions 'org-info-store-link)
46 ;; Implementation
47 (defun org-info-store-link ()
48 "Store a link to an Info file and node."
49 (when (eq major-mode 'Info-mode)
50 (let (link desc)
51 (setq link (concat "info:"
52 (file-name-nondirectory Info-current-file)
53 "#" Info-current-node))
54 (setq desc (concat (file-name-nondirectory Info-current-file)
55 "#" Info-current-node))
56 (org-store-link-props :type "info" :file Info-current-file
57 :node Info-current-node
58 :link link :desc desc)
59 link)))
61 (defun org-info-open (path)
62 "Follow an Info file and node link specified by PATH."
63 (org-info-follow-link path))
66 (defun org-info-follow-link (name)
67 "Follow an Info file and node link specified by NAME."
68 (if (or (string-match "\\(.*\\)[#:]:?\\(.*\\)" name)
69 (string-match "\\(.*\\)" name))
70 (let ((filename (match-string 1 name))
71 (nodename-or-index (or (match-string 2 name) "Top")))
72 (require 'info)
73 ;; If nodename-or-index is invalid node name, then look it up
74 ;; in the index.
75 (condition-case nil
76 (Info-find-node filename nodename-or-index)
77 (user-error (Info-find-node filename "Top")
78 (condition-case nil
79 (Info-index nodename-or-index)
80 (user-error "Could not find '%s' node or index entry"
81 nodename-or-index)))))
82 (user-error "Could not open: %s" name)))
84 (defun org-info-export (path desc format)
85 "Export an info link.
86 See `org-add-link-type' for details about PATH, DESC and FORMAT."
87 (when (eq format 'html)
88 (or (string-match "\\(.*\\)[#:]:?\\(.*\\)" path)
89 (string-match "\\(.*\\)" path))
90 (let ((filename (match-string 1 path))
91 (node (or (match-string 2 path) "Top")))
92 (format "<a href=\"%s.html#%s\">%s</a>"
93 filename
94 (replace-regexp-in-string " " "-" node)
95 (or desc path)))))
97 (provide 'org-info)
99 ;;; org-info.el ends here