emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Jan Böcker" <jan.boecker@jboecker.de>
To: Darlan Cavalcante Moreira <darcamo@gmail.com>
Cc: emacs-orgmode@gnu.org, dmg@uvic.ca
Subject: Re: protocol for PDFs?
Date: Sat, 02 Jan 2010 20:23:22 +0100	[thread overview]
Message-ID: <4B3F9D2A.4050408@jboecker.de> (raw)
In-Reply-To: <4b3f6446.0706c00a.4384.ffff8055@mx.google.com>

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

  reply	other threads:[~2010-01-02 19:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-02  8:28 protocol for PDFs? D M German
2010-01-02 15:16 ` Jan Böcker
2010-01-02 20:07   ` D M German
2010-01-02 21:17   ` D M German
     [not found]   ` <86bphbhbmh.fsf@mn.cs.uvic.ca>
2010-01-04 16:09     ` Sebastian Rose
2010-01-02 15:20 ` Darlan Cavalcante Moreira
2010-01-02 19:23   ` Jan Böcker [this message]
2010-01-02 20:17     ` D M German

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B3F9D2A.4050408@jboecker.de \
    --to=jan.boecker@jboecker.de \
    --cc=darcamo@gmail.com \
    --cc=dmg@uvic.ca \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).