6

In my Emacs I have set browse-url-browser-function to eww and org-open-at-point (org-return) will open my links using eww as expected. However, I would like to configure org-mode so that when I press prefix + return (C-u RET) the link is opened using an external browser instead, is this possible without modifying org-open-at-point?

I already have a helper function, user/browse-url-external, that I use in other modes to open URL at-point in an external browser instead of eww. It doesn't work with links in org-mode since browse-url only sees the descriptive text and not the hyperlink.

David Holm
  • 1,179
  • 1
  • 10
  • 10

2 Answers2

8

That's not directly possible, since org-open-at-point already uses the prefix argument for something else. But of course there's nothing preventing you from wrapping org-open-at-point with your own code:

(defun my-org-open-at-point (&optional arg)
  (interactive "P")
  (if (not arg)
      (org-open-at-point)
      (let ((browse-url-browser-function #'browse-url-chromium))
        (org-open-at-point))))

and binding it to C-c C-o:

(define-key org-mode-map (kbd "C-c C-o") #'my-org-open-at-point)

Note that I didn't just advise org-open-at-point, since I'm a little nervous about changing its behaviour — it might break some other parts of Org.

Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
jch
  • 5,680
  • 22
  • 39
0

There is an alternative that should work without any modifications. If you look at the documentation for org-open-at-point:

(defun org-open-at-point (&optional arg)
  "Open link, timestamp, footnote or tags at point.

When point is on a link, follow it.  Normally, files will be
opened by an appropriate application.  If the optional prefix
argument ARG is non-nil, Emacs will visit the file.  With
a double prefix argument, try to open outside of Emacs, in the
application the system uses for this file type.

See that last sentence? Simply pressing C-u C-u RET should open any link with a system application rather than in Emacs.

xeruf
  • 324
  • 1
  • 12
  • You probably can't see it, but there is a deleted answer to this question that your answer duplicates. The comments to that deleted answer indicate that the answer does not work. Have you tried it out? I have not, but apparently it does not do what you think it does. – NickD Mar 19 '21 at 14:49
  • I don't see a deleted answer. I have tried it out using a PDF and it worked as expected. – xeruf Mar 20 '21 at 14:12
  • Did you change your `browse-url-browser-function` to `eww` as the question specifies? – NickD Mar 20 '21 at 15:08