org-info.el 5.0 KB

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