org-docview.el 2.9 KB

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