C-cC-o nicely opens the URL under the point in Emacs org-mode.
goto-address-mode
can likewise be added as a minor mode to a program's major mode,
(add-hook 'python-mode-hook #'goto-address-mode)
That works perfectly—with the mouse. Clicking on the URL with the mouse opens the URL. (I am uninterested in using Emacs's internal browser as it is unwieldy, but luckily the link opens in an external browser.)
This is contrary to the spirit of Emacs. I'd rather do everything from the keyboard and seldom touch the mouse.
How can I trigger browse-url-at-point
using C-cC-o on URLs?
If I write
(global-set-key "\C-c\C-o" 'browse-url-at-point)
then this will trigger opening a URL regardless of whether the point is over a URL, which makes it seem like a hack.
(add-hook 'python-mode-hook (lambda () (goto-address-mode)))
is the same as just(add-hook 'python-mode-hook #'goto-address-mode)
.browse-url-at-point
in Emacs or using it (somehow) outside Emacs? 3. "isn't quite right" isn't clear.browse-url-at-point
does try to open whatever is at point, but if there's no URL at point it raises an error. 4. Why mentiongoto-address-mode
- seems unrelated.browse-url-at-point
tries to open non-URLs at point. It's code shows that it usesbrowse-url-url-at-point
to test whether there's a URL at point. I think you need to give an example of a non-URL at point thatbrowse-url-at-point
mis-recognizes as a URL. Also: you can follow whatbrowse-url-url-at-point
does, step by step, by first doingM-x debug-on-entry browse-url-url-at-point
. Finally, useemacs -Q
(no init file), to be sure the problem isn't introduced by your init file.