Commit | Line | Data |
---|---|---|
ed21c5c8 CD |
1 | ;;; org-docview.el --- support for links to doc-view-mode buffers |
2 | ||
ab422c4d | 3 | ;; Copyright (C) 2009-2013 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 | |
ed21c5c8 CD |
8 | ;; |
9 | ;; This file is part of GNU Emacs. | |
10 | ;; | |
11 | ;; GNU Emacs is free software: you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
13 | ;; the Free Software Foundation, either version 3 of the License, or | |
14 | ;; (at your option) any later version. | |
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 | |
22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
23 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
24 | ;; | |
25 | ;;; Commentary: | |
26 | ||
27 | ;; This file implements links to open files in doc-view-mode. | |
28 | ;; Org-mode loads this module by default - if this is not what you want, | |
29 | ;; configure the variable `org-modules'. | |
30 | ||
31 | ;; The links take the form | |
32 | ;; | |
33 | ;; docview:<file path>::<page number> | |
34 | ;; | |
35 | ;; for example: [[docview:~/.elisp/org/doc/org.pdf::1][Org-Mode Manual]] | |
36 | ;; | |
37 | ;; Autocompletion for inserting links is supported; you will be | |
38 | ;; prompted for a file and a page number. | |
39 | ;; | |
40 | ;; If you use org-store-link in a doc-view mode buffer, the stored | |
41 | ;; link will point to the current page. | |
42 | ||
43 | ;;; Code: | |
44 | ||
45 | ||
46 | (require 'org) | |
afe98dfa CD |
47 | |
48 | (declare-function doc-view-goto-page "ext:doc-view" (page)) | |
49 | (declare-function image-mode-window-get "ext:image-mode" | |
50 | (prop &optional winprops)) | |
ed21c5c8 | 51 | |
8a28a5b8 | 52 | (org-autoload "doc-view" '(doc-view-goto-page)) |
ed21c5c8 CD |
53 | |
54 | (org-add-link-type "docview" 'org-docview-open) | |
55 | (add-hook 'org-store-link-functions 'org-docview-store-link) | |
56 | ||
57 | (defun org-docview-open (link) | |
58 | (when (string-match "\\(.*\\)::\\([0-9]+\\)$" link) | |
59 | (let* ((path (match-string 1 link)) | |
60 | (page (string-to-number (match-string 2 link)))) | |
61 | (org-open-file path 1) ;; let org-mode open the file (in-emacs = 1) | |
62 | ;; to ensure org-link-frame-setup is respected | |
63 | (doc-view-goto-page page) | |
64 | ))) | |
65 | ||
66 | (defun org-docview-store-link () | |
86fbb8ca | 67 | "Store a link to a docview buffer." |
ed21c5c8 CD |
68 | (when (eq major-mode 'doc-view-mode) |
69 | ;; This buffer is in doc-view-mode | |
70 | (let* ((path buffer-file-name) | |
afe98dfa | 71 | (page (image-mode-window-get 'page)) |
ed21c5c8 CD |
72 | (link (concat "docview:" path "::" (number-to-string page))) |
73 | (description "")) | |
74 | (org-store-link-props | |
75 | :type "docview" | |
76 | :link link | |
77 | :description path)))) | |
78 | ||
79 | (defun org-docview-complete-link () | |
86fbb8ca CD |
80 | "Use the existing file name completion for file. |
81 | Links to get the file name, then ask the user for the page number | |
82 | and append it." | |
ed21c5c8 CD |
83 | (concat (replace-regexp-in-string "^file:" "docview:" (org-file-complete-link)) |
84 | "::" | |
85 | (read-from-minibuffer "Page:" "1"))) | |
86 | ||
87 | ||
88 | (provide 'org-docview) | |
86fbb8ca | 89 | |
86fbb8ca | 90 | ;;; org-docview.el ends here |