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?

10
  • You haven't closed your double-quotes, so that shouldn't be working at all?
    – phils
    Apr 3, 2017 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, 2017 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, 2017 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, 2017 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, 2017 at 13:48

1 Answer 1

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

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