org-docview.el 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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: 7.4
  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 "ext:doc-view" (page))
  40. (declare-function image-mode-window-get "ext:image-mode"
  41. (prop &optional winprops))
  42. (autoload 'doc-view-goto-page "doc-view")
  43. (org-add-link-type "docview" 'org-docview-open)
  44. (add-hook 'org-store-link-functions 'org-docview-store-link)
  45. (defun org-docview-open (link)
  46. (when (string-match "\\(.*\\)::\\([0-9]+\\)$" link)
  47. (let* ((path (match-string 1 link))
  48. (page (string-to-number (match-string 2 link))))
  49. (org-open-file path 1) ;; let org-mode open the file (in-emacs = 1)
  50. ;; to ensure org-link-frame-setup is respected
  51. (doc-view-goto-page page)
  52. )))
  53. (defun org-docview-store-link ()
  54. "Store a link to a docview buffer."
  55. (when (eq major-mode 'doc-view-mode)
  56. ;; This buffer is in doc-view-mode
  57. (let* ((path buffer-file-name)
  58. (page (image-mode-window-get 'page))
  59. (link (concat "docview:" path "::" (number-to-string page)))
  60. (description ""))
  61. (org-store-link-props
  62. :type "docview"
  63. :link link
  64. :description path))))
  65. (defun org-docview-complete-link ()
  66. "Use the existing file name completion for file.
  67. Links to get the file name, then ask the user for the page number
  68. and append it."
  69. (concat (replace-regexp-in-string "^file:" "docview:" (org-file-complete-link))
  70. "::"
  71. (read-from-minibuffer "Page:" "1")))
  72. (provide 'org-docview)
  73. ;; arch-tag: dd147a78-cce1-481b-b40a-15869417debe
  74. ;;; org-docview.el ends here