Controlling link opening in Emacs

submited by
Style Pass
2024-08-12 04:30:04

Multiple Emacs modes recognize URIs so that you can follow them in a web browser, usually with a mouse left click. In modes that do not support it, one can still call browse-url-at-point interactively with the cursor positioned on a URI.

There is no global Emacs concept of following links, so modes deal with them differently. I wanted to use the same key binding everywhere; I went for C-o (“o” for “open”) since I never use open-line. I also wanted the ability to use Eww —the Emacs builtin web browser— when it is convenient. So I added a function to select the secondary browser when the prefix is set. This way C-o opens Firefox, and C-u C-o opens Eww.

Ultimately the function calls browse-url-at-point which identifies the URI under the cursor (i.e. at the current point) and calls browse-url.

Since I use multiple Firefox profiles, I needed the ability to open URIs in the right profile depending of the context. For example links in a professional email read in Gnus should be open in my work context.

Leave a Comment