]> code.delx.au - gnu-emacs/blob - lisp/org/org-docview.el
* lisp/org/org-docview.el: Fix copyright years.
[gnu-emacs] / lisp / org / org-docview.el
1 ;;; org-docview.el --- support for links to doc-view-mode buffers
2
3 ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
4
5 ;; Author: Jan Böcker <jan.boecker at jboecker dot de>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;; Version: 6.35i
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)
48
49 (declare-function doc-view-goto-page "doc-view" (page))
50 (declare-function doc-view-current-page "doc-view" (&optional win))
51
52 (org-add-link-type "docview" 'org-docview-open)
53 (add-hook 'org-store-link-functions 'org-docview-store-link)
54
55 (defun org-docview-open (link)
56 (when (string-match "\\(.*\\)::\\([0-9]+\\)$" link)
57 (let* ((path (match-string 1 link))
58 (page (string-to-number (match-string 2 link))))
59 (org-open-file path 1) ;; let org-mode open the file (in-emacs = 1)
60 ;; to ensure org-link-frame-setup is respected
61 (doc-view-goto-page page)
62 )))
63
64 (defun org-docview-store-link ()
65 "Store a link to a docview buffer"
66 (when (eq major-mode 'doc-view-mode)
67 ;; This buffer is in doc-view-mode
68 (let* ((path buffer-file-name)
69 (page (doc-view-current-page))
70 (link (concat "docview:" path "::" (number-to-string page)))
71 (description ""))
72 (org-store-link-props
73 :type "docview"
74 :link link
75 :description path))))
76
77 (defun org-docview-complete-link ()
78 "Use the existing file name completion for file: links to get the file name,
79 then ask the user for the page number and append it."
80 (concat (replace-regexp-in-string "^file:" "docview:" (org-file-complete-link))
81 "::"
82 (read-from-minibuffer "Page:" "1")))
83
84
85 (provide 'org-docview)