Emacs Init: Setup Default Browser

By Xah Lee. Date: . Last updated: .

When you click on a link or Alt+x find-file-at-point when cursor is on a URL, emacs will call Operating System's default browser. [see Emacs: Open File Path Under Cursor 🚀]

You can tell emacs to use a specific browser (For example, Firefox, Google Chrome).

Here's how to set specific browser to open links.

put this in your Emacs Init File:

;; set browser to emacs default
(setq browse-url-browser-function 'browse-url-default-browser)

;; set browser to emacs browser
(setq browse-url-browser-function 'eww-browse-url)

;; set browser to firefox
(setq browse-url-browser-function 'browse-url-firefox)

;; set browser to google's browser
(setq browse-url-browser-function 'browse-url-chrome)

You can also set up a regex list to open specific browser depending on URL.

;; use diff browsers depending on url
(setq
 browse-url-handlers
 '(("wikipedia\\.org" . browse-url-firefox)
   ;; ("github" . browse-url-chromium)
   ("github" . browse-url-chrome)
   ("thefreedictionary\\.com" . eww-browse-url)
   ("." . browse-url-default-browser)))

[see Emacs: Regular Expression]

To see more browsers, Alt+x describe-variable then browse-url-browser-function, then click on the link to jump to the source code definition.

Emacs, Web Browser