5

Consider the following link I have in my org-mode file

[[file:./helloworld.py][LinkToFile]]

Emacs always opens source code files inside emacs. Web-links on the other hand are always opened in the browser. How can I get such source code files to be displayed in the browser instead?

  • 3
    Do you want to open all file links in a browser? If not, how will emacs know which to open in Emacs, and which in the browser? – Tyler May 16 '17 at 14:20
5

You can do this with a custom link type, as described here.

The following code minimally does this for your case:

;; a function to open files in the browser:
(defun my-browse-file (path)
  (browse-url
  (concat "file:" path)))

;; add the new link type
(org-add-link-type "hfile" 'my-browse-file)

With this, you can use links in this format:

[[hfile:///home/tws/scratch][my file]]

I think you need to use the absolute path to your file, I don't think you can use relative paths. At least, not when you pass the path to the browser as file:///path/to/file, as is done here. You could alter my-browse-file to insert the /// for you, so your links can skip that bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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