123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- (require 'org)
- (require 'doc-view)
- (declare-function doc-view-goto-page "doc-view" (page))
- (declare-function image-mode-window-get "image-mode" (prop &optional winprops))
- (org-add-link-type "docview" 'org-docview-open 'org-docview-export)
- (add-hook 'org-store-link-functions 'org-docview-store-link)
- (defun org-docview-export (link description format)
- "Export a docview link from Org files."
- (let* ((path (when (string-match "\\(.+\\)::.+" link)
- (match-string 1 link)))
- (desc (or description link)))
- (when (stringp path)
- (setq path (org-link-escape (expand-file-name path)))
- (cond
- ((eq format 'html) (format "<a href=\"%s\">%s</a>" path desc))
- ((eq format 'latex) (format "\href{%s}{%s}" path desc))
- ((eq format 'ascii) (format "%s (%s)" desc path))
- (t path)))))
- (defun org-docview-open (link)
- (when (string-match "\\(.*\\)::\\([0-9]+\\)$" link)
- (let* ((path (match-string 1 link))
- (page (string-to-number (match-string 2 link))))
- (org-open-file path 1)
-
- (doc-view-goto-page page)
- )))
- (defun org-docview-store-link ()
- "Store a link to a docview buffer."
- (when (eq major-mode 'doc-view-mode)
-
- (let* ((path buffer-file-name)
- (page (image-mode-window-get 'page))
- (link (concat "docview:" path "::" (number-to-string page)))
- (description ""))
- (org-store-link-props
- :type "docview"
- :link link
- :description path))))
- (defun org-docview-complete-link ()
- "Use the existing file name completion for file.
- Links to get the file name, then ask the user for the page number
- and append it."
- (concat (replace-regexp-in-string "^file:" "docview:" (org-file-complete-link))
- "::"
- (read-from-minibuffer "Page:" "1")))
- (provide 'org-docview)
|