Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF always opens on p. 1! #10

Closed
Keks-Dose opened this issue Apr 5, 2016 · 15 comments
Closed

PDF always opens on p. 1! #10

Keks-Dose opened this issue Apr 5, 2016 · 15 comments

Comments

@Keks-Dose
Copy link

Hi!

Linux, Orgmode 8.3.4, org-file with many links.

I'd like to

  1. open via a given link from inside the org-file using C-c C-o
  2. the PDF with pdf-tools
  3. on a given page.

The link is something like: [[./localfile.pdf::5][Description]]

Result: PDF is being opened, but always on p. 1 instead of e.g. page 5!

.emacs:
(eval-after-load 'org '(require 'org-pdfview))
(delete '(".pdf'" . default) org-file-apps)
(add-to-list 'org-file-apps '(".pdf'" . org-pdfview-open))
(add-to-list 'org-file-apps '(".pdf::([[:digit:]]+)'" . org-pdfview-open))

What am I doing the wrong way?

Same setup works under windows with other viewer. So probably there is an
error in those lines above. Any hints? -- Thank you!

@markus1189
Copy link
Owner

Unfortunately I won't be able to test this until the weekend, so until then I will try to guess what the problem is ;)

Your elisp for emacs looks like you are missing some backslashes inside the strings, e.g.

(add-to-list 'org-file-apps '("\.pdf\'" . org-pdfview-open))

here you only have \. while it should be \\. like this:

(add-to-list 'org-file-apps '("\\.pdf\\'" . org-pdfview-open))

@Keks-Dose
Copy link
Author

I have no idea, why the code was copied from my .emacs without double backlashes, but the lines in my .emacs are:

(eval-after-load 'org '(require 'org-pdfview))
(delete '("\\.pdf\\'" . default) org-file-apps)
(add-to-list 'org-file-apps '("\\.pdf\\'" . org-pdfview-open))
(add-to-list 'org-file-apps '("\\.pdf::\\([[:digit:]]+\\)\\'" . org-pdfview-open))

If org-pdfview should open PDF on the given page, I'll search in my installation for the error.

@markus1189
Copy link
Owner

At least for me it worked. As said above I can't test it currently so I can come back to you on the weekend unless you find an error in your installation.

@Keks-Dose
Copy link
Author

Did it work for you with current orgmode installation?

@markus1189
Copy link
Owner

Well... I have to admit that I totally forgot about that during the weekend, sorry! I will make sure to test this on Thursday.

@markus1189
Copy link
Owner

Just tested it and it works here. Not sure why it does not work for you, but you might want to jump to org-pdfview.el and call eval-defun with a prefix argument (C-u C-M-X for me) to instrument it for debugging. Then you should be able to see what the page variable is by trying to open the link and stepping through the code.

@Keks-Dose
Copy link
Author

OK, I get a message:
Making pre-command-hook local to XY.pdf while let-bound!
?

@markus1189
Copy link
Owner

Now idea where that comes from. Do you see that while debugging or while opening a link?

@Keks-Dose
Copy link
Author

I open org-pdfview.el and type C-u C-M-X. Then I open the org-file with the link and try to open the link using C-c C-o. Then the message appears.

@markus1189
Copy link
Owner

And if you then step through the code and inspect what the bound value of
page is? Org link for edebug in case you don't know it:
[[info:elisp#Edebug][info:elisp#Edebug]]

On Fri, Apr 15, 2016 at 3:39 PM, Keks-Dose notifications@github.com wrote:

I open org-pdfview.el and type C-u C-M-X. Then I open the org-file with
the link and try to open the link using C-c C-o. Then the message appears.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#10 (comment)

@Keks-Dose
Copy link
Author

Keks-Dose commented Apr 15, 2016

Took some minutes. Point inside org-pdfview.el to (defun org-pdfview-open..., C-u C-M-X, open the *.org-file, C-c C-o on the link and get the message: pdf-view-goto-page: No such page: 0 So somehow the page of the link is wrong.

@markus1189
Copy link
Owner

Hard to say what is the issue here. You could try to start emacs as emacs -Q, eval the required definitions and see if you can reproduce it there, if it is the case you can send me a step-by-step list so I can try to reproduce the error.

@Keks-Dose
Copy link
Author

OK, I'll restart with a clean .emacs and see. Thank you for your help!

@Keks-Dose
Copy link
Author

Pablo S. Casas published a solution on the emacs-orgmode mailinglist on July, 24. My initial setup, which did not work with Emacs 24.5 and orgmode 8.2 / 8.3:

(eval-after-load 'org '(require 'org-pdfview))
(delete '("\\.pdf\\'" . default) org-file-apps)
(add-to-list 'org-file-apps '("\\.pdf\\'" . org-pdfview-open))
(add-to-list 'org-file-apps '("\\.pdf::\\([[:digit:]]+\\)\\'" . org-pdfview-
open))

Setup now and working (PDF opened on a given page):

 (eval-after-load 'org '(require 'org-pdfview))
 (delete '("\\.pdf\\'" . default) org-file-apps)

(add-to-list 'org-file-apps '("\\.pdf\\'" . (org-pdfview-open link)))
(add-to-list 'org-file-apps '("\\.pdf::\\(\\d+\\)\\'" . (org-pdfview-open 
link)))

Unfortunately there is no more "sexp" case in `org-file-apps' in development version, as the maintainer wrote in the next post. So the whole thing will be back on the agenda with the next major update of orgmode. But for the time being I close the question.

@miroba
Copy link

miroba commented May 23, 2017

For anyone looking to get this working with orgmode version 9.0.

Use:
(add-to-list 'org-file-apps '("\\.pdf\\'" . (lambda (file link) (org-pdfview-open link)))) (add-to-list 'org-file-apps '("\\.pdf::\\([[:digit:]]+\\)\\'" . (lambda (file link) (org-pdfview-open link))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants