org-eww: Fix docstrings
[org-mode/org-tableheadings.git] / lisp / org-info.el
blob8765c533c0722255d69fae74d51ea1eada1e80a0
1 ;;; org-info.el --- Support for Links to Info Nodes -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2004-2016 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"
38 (filename nodename &optional no-going-back strict-case))
39 (defvar Info-current-file)
40 (defvar Info-current-node)
42 ;; Install the link type
43 (org-link-set-parameters "info"
44 :follow #'org-info-open
45 :export #'org-info-export
46 :store #'org-info-store-link)
48 ;; Implementation
49 (defun org-info-store-link ()
50 "Store a link to an Info file and node."
51 (when (eq major-mode 'Info-mode)
52 (let ((link (concat "info:"
53 (file-name-nondirectory Info-current-file)
54 "#" Info-current-node))
55 (desc (concat (file-name-nondirectory Info-current-file)
56 "#" Info-current-node)))
57 (org-store-link-props :type "info" :file Info-current-file
58 :node Info-current-node
59 :link link :desc desc)
60 link)))
62 (defun org-info-open (path)
63 "Follow an Info file and node link specified by PATH."
64 (org-info-follow-link path))
67 (defun org-info-follow-link (name)
68 "Follow an Info file and node link specified by NAME."
69 (if (or (string-match "\\(.*\\)[#:]:?\\(.*\\)" name)
70 (string-match "\\(.*\\)" name))
71 (let ((filename (match-string 1 name))
72 (nodename-or-index (or (match-string 2 name) "Top")))
73 (require 'info)
74 ;; If nodename-or-index is invalid node name, then look it up
75 ;; in the index.
76 (condition-case nil
77 (Info-find-node filename nodename-or-index)
78 (user-error (Info-find-node filename "Top")
79 (condition-case nil
80 (Info-index nodename-or-index)
81 (user-error "Could not find '%s' node or index entry"
82 nodename-or-index)))))
83 (user-error "Could not open: %s" name)))
85 (defconst org-info-emacs-documents
86 '("ada-mode" "auth" "autotype" "bovine" "calc" "ccmode" "cl" "dbus" "dired-x"
87 "ebrowse" "ede" "ediff" "edt" "efaq-w32" "efaq" "eieio" "eintr" "elisp"
88 "emacs-gnutls" "emacs-mime" "emacs" "epa" "erc" "ert" "eshell" "eudc" "eww"
89 "flymake" "forms" "gnus" "htmlfontify" "idlwave" "ido" "info" "mairix-el"
90 "message" "mh-e" "newsticker" "nxml-mode" "octave-mode" "org" "pcl-cvs"
91 "pgg" "rcirc" "reftex" "remember" "sasl" "sc" "semantic" "ses" "sieve"
92 "smtpmail" "speedbar" "srecode" "todo-mode" "tramp" "url" "vip" "viper"
93 "widget" "wisent" "woman")
94 "List of emacs documents available.
95 Taken from <http://www.gnu.org/software/emacs/manual/html_mono/.>")
97 (defconst org-info-other-documents
98 '(("libc" . "http://www.gnu.org/software/libc/manual/html_mono/libc.html")
99 ("make" . "http://www.gnu.org/software/make/manual/make.html"))
100 "Alist of documents generated from texinfo source.
102 When converting info links to html, links to any one of these manuals are
103 converted to use these URL's.")
105 (defun org-info-map-html-url (filename)
106 "Given info FILENAME, either return it (plus '.html' suffix added) or convert
107 it to URL pointing to the official page on internet, e.g., use gnu.org for all
108 emacs related documents. See `org-info-official-gnu-document' and
109 `org-info-other-documents' for details."
110 (if (member filename org-info-emacs-documents)
111 (format "http://www.gnu.org/software/emacs/manual/html_mono/%s.html"
112 filename)
113 (let ((url (cdr (assoc filename org-info-other-documents))))
114 (or url (concat filename ".html")))))
116 (defun org-info-export (path desc format)
117 "Export an info link.
118 See `org-link-parameters' for details about PATH, DESC and FORMAT."
119 (when (eq format 'html)
120 (or (string-match "\\(.*\\)[#:]:?\\(.*\\)" path)
121 (string-match "\\(.*\\)" path))
122 (let ((filename (match-string 1 path))
123 (node (or (match-string 2 path) "Top")))
124 (format "<a href=\"%s#%s\">%s</a>"
125 (org-info-map-html-url filename)
126 (replace-regexp-in-string " " "-" node)
127 (or desc path)))))
129 (provide 'org-info)
131 ;;; org-info.el ends here