org-info.el 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ;;; org-info.el --- Support for links to Info nodes from within Org-Mode
  2. ;; Copyright (C) 2004-2012 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" (filename nodename
  29. &optional no-going-back))
  30. (defvar Info-current-file)
  31. (defvar Info-current-node)
  32. ;; Install the link type
  33. (org-add-link-type "info" 'org-info-open)
  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 (org-make-link "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. (progn
  57. (require 'info)
  58. (if (match-string 2 name) ; If there isn't a node, choose "Top"
  59. (Info-find-node (match-string 1 name) (match-string 2 name))
  60. (Info-find-node (match-string 1 name) "Top")))
  61. (message "Could not open: %s" name)))
  62. (provide 'org-info)
  63. ;;; org-info.el ends here