org-info.el 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ;;; org-info.el --- Support for Links to Info Nodes -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2004-2016 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file implements links to Info nodes from within Org-mode.
  23. ;; Org-mode loads this module by default - if this is not what you want,
  24. ;; configure the variable `org-modules'.
  25. ;;; Code:
  26. (require 'org)
  27. ;; Declare external functions and variables
  28. (declare-function Info-find-node "info"
  29. (filename nodename &optional no-going-back strict-case))
  30. (defvar Info-current-file)
  31. (defvar Info-current-node)
  32. ;; Install the link type
  33. (org-add-link-type "info" 'org-info-open 'org-info-export)
  34. (add-hook 'org-store-link-functions 'org-info-store-link)
  35. ;; Implementation
  36. (defun org-info-store-link ()
  37. "Store a link to an Info file and node."
  38. (when (eq major-mode 'Info-mode)
  39. (let ((link (concat "info:"
  40. (file-name-nondirectory Info-current-file)
  41. "#" Info-current-node))
  42. (desc (concat (file-name-nondirectory Info-current-file)
  43. "#" Info-current-node)))
  44. (org-store-link-props :type "info" :file Info-current-file
  45. :node Info-current-node
  46. :link link :desc desc)
  47. link)))
  48. (defun org-info-open (path)
  49. "Follow an Info file and node link specified by PATH."
  50. (org-info-follow-link path))
  51. (defun org-info-follow-link (name)
  52. "Follow an Info file and node link specified by NAME."
  53. (if (or (string-match "\\(.*\\)[#:]:?\\(.*\\)" name)
  54. (string-match "\\(.*\\)" name))
  55. (let ((filename (match-string 1 name))
  56. (nodename-or-index (or (match-string 2 name) "Top")))
  57. (require 'info)
  58. ;; If nodename-or-index is invalid node name, then look it up
  59. ;; in the index.
  60. (condition-case nil
  61. (Info-find-node filename nodename-or-index)
  62. (user-error (Info-find-node filename "Top")
  63. (condition-case nil
  64. (Info-index nodename-or-index)
  65. (user-error "Could not find '%s' node or index entry"
  66. nodename-or-index)))))
  67. (user-error "Could not open: %s" name)))
  68. (defconst org-info-emacs-documents
  69. '("ada-mode" "auth" "autotype" "bovine" "calc" "ccmode" "cl" "dbus" "dired-x"
  70. "ebrowse" "ede" "ediff" "edt" "efaq-w32" "efaq" "eieio" "eintr" "elisp"
  71. "emacs-gnutls" "emacs-mime" "emacs" "epa" "erc" "ert" "eshell" "eudc" "eww"
  72. "flymake" "forms" "gnus" "htmlfontify" "idlwave" "ido" "info" "mairix-el"
  73. "message" "mh-e" "newsticker" "nxml-mode" "octave-mode" "org" "pcl-cvs"
  74. "pgg" "rcirc" "reftex" "remember" "sasl" "sc" "semantic" "ses" "sieve"
  75. "smtpmail" "speedbar" "srecode" "todo-mode" "tramp" "url" "vip" "viper"
  76. "widget" "wisent" "woman")
  77. "List of emacs documents available.
  78. Taken from <http://www.gnu.org/software/emacs/manual/html_mono/.>")
  79. (defconst org-info-other-documents
  80. '(("libc" . "http://www.gnu.org/software/libc/manual/html_mono/libc.html")
  81. ("make" . "http://www.gnu.org/software/make/manual/make.html"))
  82. "Alist of documents generated from texinfo source.
  83. When converting info links to html, links to any one of these manuals are
  84. converted to use these URL's.")
  85. (defun org-info-map-html-url (filename)
  86. "Given info FILENAME, either return it (plus '.html' suffix added) or convert
  87. it to URL pointing to the official page on internet, e.g., use gnu.org for all
  88. emacs related documents. See `org-info-official-gnu-document' and
  89. `org-info-other-documents' for details."
  90. (if (member filename org-info-emacs-documents)
  91. (format "http://www.gnu.org/software/emacs/manual/html_mono/%s.html"
  92. filename)
  93. (let ((url (cdr (assoc filename org-info-other-documents))))
  94. (or url (concat filename ".html")))))
  95. (defun org-info-export (path desc format)
  96. "Export an info link.
  97. See `org-add-link-type' for details about PATH, DESC and FORMAT."
  98. (when (eq format 'html)
  99. (or (string-match "\\(.*\\)[#:]:?\\(.*\\)" path)
  100. (string-match "\\(.*\\)" path))
  101. (let ((filename (match-string 1 path))
  102. (node (or (match-string 2 path) "Top")))
  103. (format "<a href=\"%s#%s\">%s</a>"
  104. (org-info-map-html-url filename)
  105. (replace-regexp-in-string " " "-" node)
  106. (or desc path)))))
  107. (provide 'org-info)
  108. ;;; org-info.el ends here