org-info.el 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ;;; org-info.el --- Support for links to Info nodes from within Org-Mode
  2. ;; Copyright (C) 2004-2014 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 (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. (message "Could not open: %s" name)))
  69. (provide 'org-info)
  70. ;;; org-info.el ends here