1

I've already asked this question here but the context I proposed was maybe too restrictive. Here is what I'm looking for on a more behavioral level.

I have configured org-mode to open links with the return key. For instance, if a link points to a pdf, I have configured org-mode to open it with certain external pdf viewer (in fact Skim in Mac OS).

From time to time, I want to open pdf links with Inkscape, for instance, when I want to edit a pdf figure. For now, I'm globally changing my setting to open all pdf with inkscape, a setting that I have next to revert to return to my config with a common PDF viewer if I don't want to edit pdf anymore.

Since I find this setting change a bit heavy, I was wondering if there is a starting point or a solution that would allow me to keep both file opening systems, inkscape + pdf viewer, coexisting.

I think, for instance, to a solution that

  • keeps the common behavior of opening a pdf with a pdf viewer by clicking (or pressing return) on a pdf link;
  • opens this link with inkscape only if I press a given key when I click (or press return) on such a link.

I believe that such a solution could be of interest for other persons, in the combination of two applications on the same file extension (for instance, html link to be open either with a browser and an html editor to read the code)

Thank you in advance.


[Update 10/3/2023]

From the discussion below with the handy dalanicolai's advice, emerged the following solution (for Mac OS only).

First, set the mailcap-user-mime-data to open pdf files with inkscape :

(setq mailcap-user-mime-data '(("pdf"
                                (viewer . "inkscape %s")
                                (type . "application/pdf")
                                (test . window-system))))

Next, reconfigure org-file-apps-macos (set by default in org.el and called by org--file-default-apps) with

(defconst org-file-apps-macos
  '((remote . emacs)
    (system . mailcap)
    ("ps.gz"  . "gv %s")
    ("eps.gz" . "gv %s")
    ("dvi"    . "xdvi %s")
    ("fig"    . "xfig %s")
    (t . "open %s"))
  "Default file applications on a macOS system.
The system \"open\" is known as a default, but we use X11 applications
for some files for which the OS does not have a good default.
See `org-file-apps'.")

Now,

  • clicking or hitting return key on a link to a pdf file open this with the pdf viewer defined in Mac OS (I use Skim),
  • using the modifier C-u C-u before this click/return key, open the same pdf inside inkscape

I'm sure this solution could be adapted to many other pairs of applications applied to the same file extension.

For more information on the rationale of this solution, see the discussion below.

1 Answer 1

2

You can prefix a click/RET on an org link with a single or a double universal-argument (i.e. press C-u once/twice). For links, org delegates the execution to org-link-open passing the arguments. org-link-open further delegates to org-link-open-as-file which again delegates to org-open-file, each time passing the arguments. The relevant info for your solution you can find in the docstring of org-open-file.

So, with a double universal argument, org uses the 'system' configuration, which is the value returned by: M-: (mailcap-mime-info "application/pdf"). This value can be configured via the variable mailcap-user-mime-data. However, it seems that the docstring for that variable is incorrect (see below).

Without prefix, org uses the app as configured in the customizable variable org-file-apps. You can configure it as shown in the image below enter image description here

With a single universal argument, org tries to open the link in Emacs.

Now for the configuration of the mailcap-user-mime-data; it seems that the format as explained in the docstring does not get interpreted correctly (by the mailcap-select-preferred-viewer function). It seems that you should use a format as used in the variable mailcap-mime-data, e.g.:

(setq mailcap-user-mime-data '(("pdf"
                                (viewer . "skim %s")
                                (type . "application/pdf")
                                (test . window-system))))
8
  • It would be great if you could report a (documentation) bug about the incorrect docstring of the mailcap-user-mime-data variable, using M-x report-emacs-bug. If you do, then you could refer to this answer. And then also, Thanks! :) Commented Mar 2, 2023 at 12:47
  • Thank you for your detailed answer! I followed your procedure however I may have not configured it properly. First, I set up (add-to-list 'org-file-apps '("\\.pdf\\'" . default)) so that without any prefix c-u a pdf link will be open with the default os pdf viewer (skim in my case). Next, I set up mailcap-user-mime-data to inkscape according to your code above. This seems correctly interpreted because M-: (mailcap-mime-info "application/pdf") displays inkscape %s now. However, if I hit C-u C-u + enter on a pdf link, it still opens it with skim. Am I wrong somewhere? Commented Mar 4, 2023 at 14:48
  • 1
    It sounds like you are doing it right. I guess 'enter' is bound to org-open-at-point, otherwise you can try C-u C-u C-c C-o. Also, you should check that the value of (org--file-default-apps) contains (system . mailcap). If that list contains that cons, then I don't know why it does not work. In that case, I recommend you to quickly read how to use edebug, and subsequently, edebug the org-open-file function (while prefixing with double C-u). Would be nice to know what you find. Good luck! Commented Mar 5, 2023 at 8:15
  • Thanks. Indeed, the content of (org--file-default-apps) is ((remote . emacs) (system . open %s) (ps.gz . gv %s) (eps.gz . gv %s) (dvi . xdvi %s) (fig . xfig %s) (t . open %s)). I'm going to see how to fix this. Commented Mar 8, 2023 at 6:59
  • 1
    Ok, thanks to your help dalanicolai I got it working. In addition to the config of mailcap-user-mime-data above, I had to reconfigure org-file-apps-macos, which is called by (org--file-default-apps) on macos according to org.el. So I just replaced (system . "open %s") in the config of org-file-apps-macos by (system . mailcap) and now I have skim opened without modifier C-u, and inkscape with C-u C-u. Great! Thank you again. Commented Mar 10, 2023 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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