This question already has an answer here:

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?

marked as duplicate by Tyler, Drew, Community Jan 10 '18 at 13:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You haven't closed your double-quotes, so that shouldn't be working at all? – phils Apr 3 '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 3 '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 3 '17 at 13:36
  • org-pdfview supports links of the format pdfview:myfile.pdf::23, where 23 is the page number you wish to open. – Tyler Apr 3 '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 3 '17 at 13:48

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))

Not the answer you're looking for? Browse other questions tagged or ask your own question.