Open an URL in Safari From Emacs

When I edit my tools' configuration files I usually put in them the website from where I stole that nifty trick, months later I can remember why I did something that way.
Opening an URL from a text editor usually involves this steps:

  1. Select the URL
  2. Copy the URL
  3. Switch to the browser
  4. Paste the URL and hit enter

Emacs has the Browse-URL package, it allows us to open URLs we encounter in a browser. To do this put the following snippet of code in your .emacs file.

;; Set the default browser command
(setq browse-url-browser-function 'browse-url-generic
      browse-url-generic-program "open")
;; Set a keybind
(global-set-key (kbd "C-c C-o") 'browse-url)

You can read more about open on the man page.

Now you can open an URL with C-c C-o, if the cursor is hover something that resemble an URL that URL is used as default.

Open an URL like a boss

  • 夏普牛

    thank you , it is useful