First off, you can find my entire current config at https://gitlab.com/mordocai/emacs.d/tree/4cfdfd76368aa687a6277a22161b40624e32b8fe, just in case I miss including something.

I currently have my emacs browser config setup like:

(global-set-key (kbd "<f6> w") 'browse-url-at-point)
(setq w3m-coding-system 'utf-8
  w3m-file-coding-system 'utf-8
  w3m-file-name-coding-system 'utf-8
  w3m-input-coding-system 'utf-8
  w3m-output-coding-system 'utf-8
  w3m-terminal-coding-system 'utf-8
  w3m-use-cookies t)

(defun browse-url-at-point-firefox ()
  (let ((browse-url-browser-function 'browse-url-firefox))

(defun browse-url-at-point-default ()
  (let ((browse-url-browser-function 'browse-url-default-browser))

(global-set-key (kbd "<f6> f") 'browse-url-at-point-firefox)
(global-set-key (kbd "<f6> d") 'browse-url-at-point-default)
(global-set-key (kbd "<f6> g")
                (icurry 'browse-url-default-browser "http://www.google.com"))

However, this only works if the link is "written out" like http://www.duckduckgo.com. If the current mode handles links natively (like org mode, gnus article's html view, or elfeed's html rendering) then the display text will be used as the link instead. Something like Google will try to go to http://Google instead of http://www.google.com.

Is it possible to write a function(s) that will allow me to bind it to a key and will actually go to one of the above type of links properly? If so, is it possible to detect which situation is at point and intelligently go to the link? I think I could write this, but I'm not sure how to get the actual link text in the first place.

If there is a package that can do all of this, all the better!

  • In general, I'm afraid not, but in a finite number of cases: yes. Instead of using browse-url-at-point you could write a function which, depending on the value of major-mode would try to discover the URL under point. Quite often, the actual value of the URL can be found in the text properties or in the overlay, but sometimes you would need to dig deeper into the mode internals to figure out how and where the URL is stored. For instance, Org doesn't store that information anywhere, but infers it on the fly based on org-any-link-re matching. – wvxvw Feb 16 '16 at 22:26

Your Answer

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

Browse other questions tagged or ask your own question.