Commit | Line | Data |
---|---|---|
ed21c5c8 CD |
1 | ;;; org-docview.el --- support for links to doc-view-mode buffers |
2 | ||
73b0cd50 | 3 | ;; Copyright (C) 2009-2011 Free Software Foundation, Inc. |
ed21c5c8 | 4 | |
86fbb8ca | 5 | ;; Author: Jan Böcker <jan.boecker at jboecker dot de> |
ed21c5c8 CD |
6 | ;; Keywords: outlines, hypermedia, calendar, wp |
7 | ;; Homepage: http://orgmode.org | |
acedf35c | 8 | ;; Version: 7.4 |
ed21c5c8 CD |
9 | ;; |
10 | ;; This file is part of GNU Emacs. | |
11 | ;; | |
12 | ;; GNU Emacs is free software: you can redistribute it and/or modify | |
13 | ;; it under the terms of the GNU General Public License as published by | |
14 | ;; the Free Software Foundation, either version 3 of the License, or | |
15 | ;; (at your option) any later version. | |
16 | ||
17 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ;; GNU General Public License for more details. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
23 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
24 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
25 | ;; | |
26 | ;;; Commentary: | |
27 | ||
28 | ;; This file implements links to open files in doc-view-mode. | |
29 | ;; Org-mode loads this module by default - if this is not what you want, | |
30 | ;; configure the variable `org-modules'. | |
31 | ||
32 | ;; The links take the form | |
33 | ;; | |
34 | ;; docview:<file path>::<page number> | |
35 | ;; | |
36 | ;; for example: [[docview:~/.elisp/org/doc/org.pdf::1][Org-Mode Manual]] | |
37 | ;; | |
38 | ;; Autocompletion for inserting links is supported; you will be | |
39 | ;; prompted for a file and a page number. | |
40 | ;; | |
41 | ;; If you use org-store-link in a doc-view mode buffer, the stored | |
42 | ;; link will point to the current page. | |
43 | ||
44 | ;;; Code: | |
45 | ||
46 | ||
47 | (require 'org) | |
afe98dfa CD |
48 | |
49 | (declare-function doc-view-goto-page "ext:doc-view" (page)) | |
50 | (declare-function image-mode-window-get "ext:image-mode" | |
51 | (prop &optional winprops)) | |
ed21c5c8 | 52 | |
eeb4145e | 53 | (autoload 'doc-view-goto-page "doc-view") |
ed21c5c8 CD |
54 | |
55 | (org-add-link-type "docview" 'org-docview-open) | |
56 | (add-hook 'org-store-link-functions 'org-docview-store-link) | |
57 | ||
58 | (defun org-docview-open (link) | |
59 | (when (string-match "\\(.*\\)::\\([0-9]+\\)$" link) | |
60 | (let* ((path (match-string 1 link)) | |
61 | (page (string-to-number (match-string 2 link)))) | |
62 | (org-open-file path 1) ;; let org-mode open the file (in-emacs = 1) | |
63 | ;; to ensure org-link-frame-setup is respected | |
64 | (doc-view-goto-page page) | |
65 | ))) | |
66 | ||
67 | (defun org-docview-store-link () | |
86fbb8ca | 68 | "Store a link to a docview buffer." |
ed21c5c8 CD |
69 | (when (eq major-mode 'doc-view-mode) |
70 | ;; This buffer is in doc-view-mode | |
71 | (let* ((path buffer-file-name) | |
afe98dfa | 72 | (page (image-mode-window-get 'page)) |
ed21c5c8 CD |
73 | (link (concat "docview:" path "::" (number-to-string page))) |
74 | (description "")) | |
75 | (org-store-link-props | |
76 | :type "docview" | |
77 | :link link | |
78 | :description path)))) | |
79 | ||
80 | (defun org-docview-complete-link () | |
86fbb8ca CD |
81 | "Use the existing file name completion for file. |
82 | Links to get the file name, then ask the user for the page number | |
83 | and append it." | |
ed21c5c8 CD |
84 | (concat (replace-regexp-in-string "^file:" "docview:" (org-file-complete-link)) |
85 | "::" | |
86 | (read-from-minibuffer "Page:" "1"))) | |
87 | ||
88 | ||
89 | (provide 'org-docview) | |
86fbb8ca | 90 | |
86fbb8ca CD |
91 | |
92 | ;;; org-docview.el ends here |