org-info.el 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ;;; org-info.el --- Support for links to Info nodes from within Org-Mode
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 7.5
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  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.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file implements links to Info nodes from within Org-mode.
  25. ;; Org-mode loads this module by default - if this is not what you want,
  26. ;; configure the variable `org-modules'.
  27. ;;; Code:
  28. (require 'org)
  29. ;; Declare external functions and variables
  30. (declare-function Info-find-node "info" (filename nodename
  31. &optional no-going-back))
  32. (defvar Info-current-file)
  33. (defvar Info-current-node)
  34. ;; Install the link type
  35. (org-add-link-type "info" 'org-info-open)
  36. (add-hook 'org-store-link-functions 'org-info-store-link)
  37. ;; Implementation
  38. (defun org-info-store-link ()
  39. "Store a link to an Info file and node."
  40. (when (eq major-mode 'Info-mode)
  41. (let (link desc)
  42. (setq link (org-make-link "info:"
  43. (file-name-nondirectory Info-current-file)
  44. "#" Info-current-node))
  45. (setq desc (concat (file-name-nondirectory Info-current-file)
  46. "#" Info-current-node))
  47. (org-store-link-props :type "info" :file Info-current-file
  48. :node Info-current-node
  49. :link link :desc desc)
  50. link)))
  51. (defun org-info-open (path)
  52. "Follow an Info file and node link specified by PATH."
  53. (org-info-follow-link path))
  54. (defun org-info-follow-link (name)
  55. "Follow an Info file and node link specified by NAME."
  56. (if (or (string-match "\\(.*\\)[#:]:?\\(.*\\)" name)
  57. (string-match "\\(.*\\)" name))
  58. (progn
  59. (require 'info)
  60. (if (match-string 2 name) ; If there isn't a node, choose "Top"
  61. (Info-find-node (match-string 1 name) (match-string 2 name))
  62. (Info-find-node (match-string 1 name) "Top")))
  63. (message "Could not open: %s" name)))
  64. (provide 'org-info)
  65. ;; arch-tag: 1e289f54-7176-487f-b575-dd4854bab15e
  66. ;;; org-info.el ends here