Commit | Line | Data |
---|---|---|
20908596 CD |
1 | ;;; org-info.el --- Support for links to Info nodes from within Org-Mode |
2 | ||
ba318903 | 3 | ;; Copyright (C) 2004-2014 Free Software Foundation, Inc. |
20908596 CD |
4 | |
5 | ;; Author: Carsten Dominik <carsten at orgmode dot org> | |
6 | ;; Keywords: outlines, hypermedia, calendar, wp | |
7 | ;; Homepage: http://orgmode.org | |
20908596 CD |
8 | ;; |
9 | ;; This file is part of GNU Emacs. | |
10 | ;; | |
b1fc2b50 | 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
20908596 | 12 | ;; it under the terms of the GNU General Public License as published by |
b1fc2b50 GM |
13 | ;; the Free Software Foundation, either version 3 of the License, or |
14 | ;; (at your option) any later version. | |
20908596 CD |
15 | |
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
b1fc2b50 | 22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
20908596 CD |
23 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
24 | ;; | |
25 | ;;; Commentary: | |
26 | ||
27 | ;; This file implements links to Info nodes from within Org-mode. | |
28 | ;; Org-mode loads this module by default - if this is not what you want, | |
29 | ;; configure the variable `org-modules'. | |
30 | ||
31 | ;;; Code: | |
32 | ||
33 | (require 'org) | |
34 | ||
35 | ;; Declare external functions and variables | |
36 | ||
37 | (declare-function Info-find-node "info" (filename nodename | |
38 | &optional no-going-back)) | |
39 | (defvar Info-current-file) | |
40 | (defvar Info-current-node) | |
41 | ||
42 | ;; Install the link type | |
43 | (org-add-link-type "info" 'org-info-open) | |
44 | (add-hook 'org-store-link-functions 'org-info-store-link) | |
45 | ||
46 | ;; Implementation | |
47 | (defun org-info-store-link () | |
48 | "Store a link to an Info file and node." | |
20908596 CD |
49 | (when (eq major-mode 'Info-mode) |
50 | (let (link desc) | |
8223b1d2 BG |
51 | (setq link (concat "info:" |
52 | (file-name-nondirectory Info-current-file) | |
53 | "#" Info-current-node)) | |
20908596 | 54 | (setq desc (concat (file-name-nondirectory Info-current-file) |
3ab2c837 | 55 | "#" Info-current-node)) |
20908596 CD |
56 | (org-store-link-props :type "info" :file Info-current-file |
57 | :node Info-current-node | |
58 | :link link :desc desc) | |
59 | link))) | |
60 | ||
61 | (defun org-info-open (path) | |
62 | "Follow an Info file and node link specified by PATH." | |
63 | (org-info-follow-link path)) | |
64 | ||
65 | ||
66 | (defun org-info-follow-link (name) | |
67 | "Follow an Info file and node link specified by NAME." | |
3ab2c837 | 68 | (if (or (string-match "\\(.*\\)[#:]:?\\(.*\\)" name) |
20908596 CD |
69 | (string-match "\\(.*\\)" name)) |
70 | (progn | |
71 | (require 'info) | |
72 | (if (match-string 2 name) ; If there isn't a node, choose "Top" | |
73 | (Info-find-node (match-string 1 name) (match-string 2 name)) | |
74 | (Info-find-node (match-string 1 name) "Top"))) | |
75 | (message "Could not open: %s" name))) | |
76 | ||
77 | (provide 'org-info) | |
78 | ||
79 | ;;; org-info.el ends here |