1

I would like to have emacsclient as my default application for opening pdf-files, when openning them from within Emacs, based on a similar post emacsclient opens a file and does eval simultaneously. Moreover I'd like the ability to jump to a specific page in that file, when the file is opened in an org-mode buffer where file-path::pg e.g. [[file:~/myfile.pdf::2][pg 2 of My File]], opens the pdf file on the desired page, when invoking C-c C-o or org-open-at-point.

I'd expect the following in my init.el to effect the desired result:

(setq org-file-apps '(("\\.pdf::\\([0-9]+\\)\\'" . 
                      "emacsclient -e '(progn
                                          (find-file \"%s\")
                                          (pdf-view-goto-page +%1)
                                       )'"
                       )))

The problem is that on execution,find-file \"%s\", the double quotations are not escaped and do not show up in the command that is actually run. i.e. I get find-file /path/to/file instead of find-file "/path/to/file"

Why are the escaped " being ignored and how do I escape them so that they wrap around the %s when the command is run?

Drew
  • 75,699
  • 9
  • 109
  • 225
nyameko
  • 545
  • 2
  • 15
  • You haven't closed your double-quotes, so that shouldn't be working at all? – phils Apr 03 '17 at 11:55
  • If *that* is only a typo in the question, then I would suggest that the escaping is *not* being ignored, but that there is another level of string/quoting evaluation which is subsequently stripping it (possibly in the shell? I haven't checked to see what `org-file-apps` does). Have you tried replacing `\"` with `\\\"` ? – phils Apr 03 '17 at 12:10
  • Thanks @phil, this was a typo in the question, src in init.el was correct. Perculiar behavior with the string substitution %s, stripping adjacent quotations. – nyameko Apr 03 '17 at 13:36
  • [org-pdfview](https://github.com/markus1189/org-pdfview) supports links of the format `pdfview:myfile.pdf::23`, where `23` is the page number you wish to open. – Tyler Apr 03 '17 at 13:47
  • I don't understand your first point. emacsclient is my default application for opening pdf files. I have this set at the OS level, and no further configuration within Emacs is necessary. What code are you trying to eval? – Tyler Apr 03 '17 at 13:48
  • Thanks @Tyler, I updated my question to reflect that I want Emacs to be the default app, specifically when opening pdfs from within Emacs. I both have `pdf-tools` and `org-pdfview` installed, however I am unable to effect the behaviour you've described, i.e. `pdfview:myfile.pdf::pg` – nyameko Apr 06 '17 at 07:46
  • I added a description for setting up org-pdfview here: http://emacs.stackexchange.com/a/24502/262 . If that doesn't work for you, we should be able to fix it! – Tyler Apr 06 '17 at 15:49
  • Perfect! Thank you very much. Please add your suggestions as an answer and I will mark as correct. Perhaps `pdf-tools` and `org-pdfview` should be merged into a single package, and maybe the post emacs.stackexchange.com/a/24502/262, should be reproduced as the langing page readme for `org-pdfview`? Thanks again @Tyler! – nyameko Apr 07 '17 at 08:38
  • Great! If you want to edit your question to be just how to get org-pdfview working, I can add an appropriate answer. At least the title should relate to the answer, otherwise it will be confusing for others who come across the question. – Tyler Apr 07 '17 at 17:50
  • Thanks @Tyler. I've moved to spacemacs so am no longer affected by this, but will mark your answer as correct as it links to the most comprehensive response and this question can be closed. – nyameko Jan 10 '18 at 13:03

1 Answers1

1

String substitution %s does not like adjacent quotation marks. Had to pad the variable with a space and then create a new string with the trailing space removed. i.e.

...
(find-file (substring \"%s \" 0 -1))
...
nyameko
  • 545
  • 2
  • 15