When using dired in emacs, how can I open an url file in a web browser outside emacs?
1 Answer
You can add a key binding, such as C-RET
to open any files in system defined default external programs such as xdg-open on Linux and open on macOS. In this way, URL files are opened by default browsers. A detailed approach is available on ErgoEmacs: http://ergoemacs.org/emacs/emacs_dired_open_file_in_ext_apps.html
-
By the way, how did you bind C-RET? When I tried with this:
(global-set-key (kbd "C-return") 'xha-open-in-external-app)
I got the error "C- must prefix a single character, not return"– myotisCommented Dec 6, 2016 at 11:31 -
@myotis
(define-key dired-mode-map (kbd "<C-return>") 'xah-open-in-external-app)
– xuhdevCommented Dec 7, 2016 at 5:47
browse-url-at-point
?(let ((file (dired-get-file-for-visit))) (start-process "my-process" nil "open" "-a" "/Applications/Firefox.app/Contents/MacOS/firefox" file))
. If you are on a different OS, then you can probably eliminate "open" and "-a", but you may need to add something specific to your OS to ensure that the browser receives input focus (if so desired) -- on OSX, that is what the "-a" is for. If you want to open multiple files, then you'll need to usedired-get-marked-files
and loop through the list of marked files.browse-url
should be even better for this.