Release 7.01c
[org-mode/org-jambu.git] / lisp / org-docview.el
blob62e35e070d7d4f7c4f1f2aa2f8383b49e4550e20
1 ;;; org-docview.el --- support for links to doc-view-mode buffers
3 ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
5 ;; Author: Jan Böcker <jan.boecker at jboecker dot de>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;; Version: 7.01c
9 ;;
10 ;; This file is part of GNU Emacs.
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.
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.
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 ;;; Commentary:
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'.
32 ;; The links take the form
34 ;; docview:<file path>::<page number>
36 ;; for example: [[docview:~/.elisp/org/doc/org.pdf::1][Org-Mode Manual]]
38 ;; Autocompletion for inserting links is supported; you will be
39 ;; prompted for a file and a page number.
41 ;; If you use org-store-link in a doc-view mode buffer, the stored
42 ;; link will point to the current page.
44 ;;; Code:
47 (require 'org)
49 (declare-function doc-view-goto-page "doc-view" (page))
50 (declare-function doc-view-current-page "doc-view" (&optional win))
52 (org-add-link-type "docview" 'org-docview-open)
53 (add-hook 'org-store-link-functions 'org-docview-store-link)
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 )))
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))))
77 (defun org-docview-complete-link ()
78 "Use the existing file name completion for file.
79 Links to get the file name, then ask the user for the page number
80 and append it."
81 (concat (replace-regexp-in-string "^file:" "docview:" (org-file-complete-link))
82 "::"
83 (read-from-minibuffer "Page:" "1")))
86 (provide 'org-docview)
88 ;; arch-tag: dd147a78-cce1-481b-b40a-15869417debe
90 ;;; org-docview.el ends here