org-info.el 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ;;; org-info.el - Support for links to Info nodes in 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 for Org-mode.
  26. ;; Org-mode loads this module by default - if this is not what you want,
  27. ;; configure the variable `org-modules'.
  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 folder or message."
  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. (defun org-info-open (path)
  51. "Follow an INFO message link."
  52. (org-info-follow-link path))
  53. (defun org-info-follow-link (name)
  54. "Follow an info file & node link to NAME."
  55. (if (or (string-match "\\(.*\\)::?\\(.*\\)" name)
  56. (string-match "\\(.*\\)" name))
  57. (progn
  58. (require 'info)
  59. (if (match-string 2 name) ; If there isn't a node, choose "Top"
  60. (Info-find-node (match-string 1 name) (match-string 2 name))
  61. (Info-find-node (match-string 1 name) "Top")))
  62. (message "Could not open: %s" name)))
  63. (provide 'org-info)
  64. ;;; org-info.el ends here