Make org-store-link point to directory in a dired buffer
[rgr-org-mode.git] / lisp / org-docview.el
blob3a11f3c226cfff7f06d0bde4c09f5b04fb3493a1
1 ;;; org-docview.el --- support for links to doc-view-mode buffers
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; Author: Jan Böcker <jan.boecker at jboecker dot de>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
9 ;; Version: 6.34trans
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
29 ;; This file implements links to open files in doc-view-mode.
30 ;; Org-mode loads this module by default - if this is not what you want,
31 ;; configure the variable `org-modules'.
33 ;; The links take the form
35 ;; docview:<file path>::<page number>
37 ;; for example: [[docview:~/.elisp/org/doc/org.pdf::1][Org-Mode Manual]]
39 ;; Autocompletion for inserting links is supported; you will be
40 ;; prompted for a file and a page number.
42 ;; If you use org-store-link in a doc-view mode buffer, the stored
43 ;; link will point to the current page.
45 ;;; Code:
48 (require 'org)
50 (declare-function doc-view-goto-page "doc-view" (page))
51 (declare-function doc-view-current-page "doc-view" (&optional win))
53 (org-add-link-type "docview" 'org-docview-open)
54 (add-hook 'org-store-link-functions 'org-docview-store-link)
56 (defun org-docview-open (link)
57 (when (string-match "\\(.*\\)::\\([0-9]+\\)$" link)
58 (let* ((path (match-string 1 link))
59 (page (string-to-number (match-string 2 link))))
60 (org-open-file path 1) ;; let org-mode open the file (in-emacs = 1)
61 ;; to ensure org-link-frame-setup is respected
62 (doc-view-goto-page page)
63 )))
65 (defun org-docview-store-link ()
66 "Store a link to a docview buffer"
67 (when (eq major-mode 'doc-view-mode)
68 ;; This buffer is in doc-view-mode
69 (let* ((path buffer-file-name)
70 (page (doc-view-current-page))
71 (link (concat "docview:" path "::" (number-to-string page)))
72 (description ""))
73 (org-store-link-props
74 :type "docview"
75 :link link
76 :description path))))
78 (defun org-docview-complete-link ()
79 "Use the existing file name completion for file: links to get the file name,
80 then ask the user for the page number 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)