From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?ISO-8859-1?Q?Jan_B=F6cker?= Subject: Re: protocol for PDFs? Date: Sat, 02 Jan 2010 20:23:22 +0100 Message-ID: <4B3F9D2A.4050408@jboecker.de> References: <86oclclxlt.fsf@mn.cs.uvic.ca> <4b3f6446.0706c00a.4384.ffff8055@mx.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NR9Zh-0005jV-C0 for emacs-orgmode@gnu.org; Sat, 02 Jan 2010 14:23:45 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NR9Zc-0005gg-Ay for emacs-orgmode@gnu.org; Sat, 02 Jan 2010 14:23:44 -0500 Received: from [199.232.76.173] (port=39774 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NR9Zc-0005gT-2b for emacs-orgmode@gnu.org; Sat, 02 Jan 2010 14:23:40 -0500 Received: from mail7.worldserver.net ([217.13.200.27]:53099) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NR9Zb-0006Ol-H1 for emacs-orgmode@gnu.org; Sat, 02 Jan 2010 14:23:39 -0500 In-Reply-To: <4b3f6446.0706c00a.4384.ffff8055@mx.google.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Darlan Cavalcante Moreira Cc: emacs-orgmode@gnu.org, dmg@uvic.ca On 02.01.2010 16:20, Darlan Cavalcante Moreira wrote: > Evince also has an option ("-p") to open the file in a > given page and this would be enough for a link to a PDF file. Since I prefer > using Evince instead of docview mode I would be very happy to test it. I have implemented an experimental version of org-docview.el which allows you to specify an external PDF viewer. Check out the docview-dev branch at http://github.com/jboecker/org-mode To test this, pull from there or apply the following patch, then: M-x customize-variable org-docview-pdf-app Set it to "evince %s -p %p" and docview: links to PDF files should now open in evince. There may still be bugs lurking here, and I am thinking about generalizing this to use a variable org-docview-apps which would behave like org-file-apps. This would duplicate functionality of file: links again, which bugs me, but on the other hand it would be difficult to reuse org-file-apps for this, as I suggested in my previous email -- when opening a file: link to a PDF, the %p would not get replaced and may confuse the PDF viewer application :( Also, YAGNI may apply here if nobody uses docview: links to link to non-PDF files anyway. ----------- new experimental variable: org-docview-pdf-app External application to open docview: links pointing to a pdf file. Possible values: 'emacs: Visit the file with emacs using doc-view-mode. string: An external PDF viewer application. %s will be replaced by the file name. %p will be replaced by the page number. Example: evince %s -p %p --- lisp/org-docview.el | 39 ++++++++++++++++++++++++++++++++++----- 1 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lisp/org-docview.el b/lisp/org-docview.el index 98da615..f2d0bf2 100644 --- a/lisp/org-docview.el +++ b/lisp/org-docview.el @@ -53,14 +53,43 @@ (org-add-link-type "docview" 'org-docview-open) (add-hook 'org-store-link-functions 'org-docview-store-link) +(defcustom org-docview-pdf-app + 'emacs + "External application to open docview: links pointing to a pdf file. +Possible values: + + 'emacs: Visit the file with emacs using doc-view-mode. + string: An external PDF viewer application. + %s will be replaced by the file name. + %p will be replaced by the page number. + + Example: + evince %s -p %p" + :group 'org-link-follow + :type '(choice (const :tag "Visit with Emacs" emacs) + (string :tag "Command"))) + (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) - ;; to ensure org-link-frame-setup is respected - (doc-view-goto-page page) - ))) + (page-string (match-string 2 link)) + (page (string-to-number page-string))) + + (if (and (not (eq org-docview-pdf-app 'emacs)) + (string-match "\.pdf$" path)) + (let ((cmd (with-temp-buffer + (insert org-docview-pdf-app) + (goto-char 1) + (replace-string "%s" path) + (goto-char 1) + (replace-string "%p" page-string) + (buffer-string)))) + (message cmd) + (start-process-shell-command cmd nil cmd)) + + (org-open-file path 1) ;; let org-mode open the file (in-emacs = 1) + ;; to ensure org-link-frame-setup is respected + (doc-view-goto-page page))))) (defun org-docview-store-link () "Store a link to a docview buffer" -- 1.6.6