org-info.el 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. ;;; org-info.el --- Support for links to Info nodes from within Org-Mode
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 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. ;; Version: 1.0
  7. ;;
  8. ;; This file is part of GNU Emacs.
  9. ;;
  10. ;; GNU Emacs is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 3, or (at your option)
  13. ;; any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. ;;
  24. ;;; Commentary:
  25. ;; This file implements links to Info nodes from within Org-mode.
  26. ;; Org-mode loads this module by default - if this is not what you want,
  27. ;; configure the variable `org-modules'.
  28. ;;; Code:
  29. (require 'org)
  30. ;; Declare external functions and variables
  31. (declare-function Info-find-node "info" (filename nodename
  32. &optional no-going-back))
  33. (defvar Info-current-file)
  34. (defvar Info-current-node)
  35. ;; Install the link type
  36. (org-add-link-type "info" 'org-info-open)
  37. (add-hook 'org-store-link-functions 'org-info-store-link)
  38. ;; Implementation
  39. (defun org-info-store-link ()
  40. "Store a link to an Info file and node."
  41. "Store a link to an INFO folder or message."
  42. (when (eq major-mode 'Info-mode)
  43. (let (link desc)
  44. (setq link (org-make-link "info:"
  45. (file-name-nondirectory Info-current-file)
  46. ":" Info-current-node))
  47. (setq desc (concat (file-name-nondirectory Info-current-file)
  48. ":" Info-current-node))
  49. (org-store-link-props :type "info" :file Info-current-file
  50. :node Info-current-node
  51. :link link :desc desc)
  52. link)))
  53. (defun org-info-open (path)
  54. "Follow an Info file and node link specified by PATH."
  55. (org-info-follow-link path))
  56. (defun org-info-follow-link (name)
  57. "Follow an Info file and node link specified by NAME."
  58. (if (or (string-match "\\(.*\\)::?\\(.*\\)" name)
  59. (string-match "\\(.*\\)" name))
  60. (progn
  61. (require 'info)
  62. (if (match-string 2 name) ; If there isn't a node, choose "Top"
  63. (Info-find-node (match-string 1 name) (match-string 2 name))
  64. (Info-find-node (match-string 1 name) "Top")))
  65. (message "Could not open: %s" name)))
  66. (provide 'org-info)
  67. ;;; org-info.el ends here