* lisp/cedet/semantic/wisent/comp.el: Remove unnecessary eval-when-compiles.
[bpt/emacs.git] / lisp / org / org-docview.el
CommitLineData
ed21c5c8
CD
1;;; org-docview.el --- support for links to doc-view-mode buffers
2
d1fef179 3;; Copyright (C) 2009, 2010 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
86fbb8ca 8;; Version: 7.01
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)
eeb4145e 48(eval-when-compile (require 'doc-view)) ; doc-view-current-page macro
ed21c5c8 49
eeb4145e 50(autoload 'doc-view-goto-page "doc-view")
ed21c5c8
CD
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 ()
86fbb8ca 65 "Store a link to a docview buffer."
ed21c5c8
CD
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 ()
86fbb8ca
CD
78 "Use the existing file name completion for file.
79Links to get the file name, then ask the user for the page number
80and append it."
ed21c5c8
CD
81 (concat (replace-regexp-in-string "^file:" "docview:" (org-file-complete-link))
82 "::"
83 (read-from-minibuffer "Page:" "1")))
84
85
86(provide 'org-docview)
86fbb8ca
CD
87
88;; arch-tag: dd147a78-cce1-481b-b40a-15869417debe
89
90;;; org-docview.el ends here