Hello,

the new doc-view-mode in emacs 23 can be used to view DVI, PDF and PostScript files. I have written a custom link type for org-mode to allow linking to those files from org-mode.

This is the first thing besides .emacs customization that I have written in elisp; as such, any feedback would be much appreciated. I have only tested it with PDF files so far, but it should work with anything doc-view-mode can display.

The attached file adds support for org-store-link inside doc-view-mode buffers. The link syntax is:
        docview:/path/to/file.pdf:<page>
where <page> is the page number to visit.

To use it, copy it to your load path as org-docview.el and add

        (require 'org-docview)

to your .emacs file.

I'd also like to suggest to integrate this functionality into the standard org-mode distribution, as emacs 23 includes doc-view-mode by default.

I am releasing the code under the terms of the GNU General Public License, Version 3 or later.

Jan Böcker
;;; org-docview.el --- support for links to doc-view-mode buffers

(require 'org)

(org-add-link-type "docview" 'org-docview-open)
(add-hook 'org-store-link-functions 'org-docview-store-link)

(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) ;; let org-mode open the file (in-emacs = 1)
      ;; so that org-link-frame-setup is respected
      (doc-view-goto-page page)
      )))

(defun org-docview-store-link ()
  "Store a link to a docview buffer"
  (when (eq major-mode 'doc-view-mode)
    ;; This buffer is in doc-view-mode
    (let* ((path buffer-file-name)
           (page (doc-view-current-page))
           (link (concat "docview:" path ":" (number-to-string page)))
           (description ""))
      (org-store-link-props
       :type "docview"
       :link link))))

(provide 'org-docview)
_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

Reply via email to