org-contacts: added org-contacts-show-map (requires google-maps-el)
[org-mode.git] / lisp / org-docview.el
blob4b0e439921a30d022b3bb995e53ed62a6263a90a
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.5
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 "ext:doc-view" (page))
50 (declare-function image-mode-window-get "ext:image-mode"
51 (prop &optional winprops))
53 (autoload 'doc-view-goto-page "doc-view")
55 (org-add-link-type "docview" 'org-docview-open)
56 (add-hook 'org-store-link-functions 'org-docview-store-link)
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 )))
67 (defun org-docview-store-link ()
68 "Store a link to a docview buffer."
69 (when (eq major-mode 'doc-view-mode)
70 ;; This buffer is in doc-view-mode
71 (let* ((path buffer-file-name)
72 (page (image-mode-window-get 'page))
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))))
80 (defun org-docview-complete-link ()
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."
84 (concat (replace-regexp-in-string "^file:" "docview:" (org-file-complete-link))
85 "::"
86 (read-from-minibuffer "Page:" "1")))
89 (provide 'org-docview)
91 ;; arch-tag: dd147a78-cce1-481b-b40a-15869417debe
93 ;;; org-docview.el ends here