0

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.

4
  • FYI: (add-hook 'python-mode-hook (lambda () (goto-address-mode))) is the same as just (add-hook 'python-mode-hook #'goto-address-mode).
    – Drew
    Sep 20, 2023 at 15:35
  • The question isn't clear to me. 1. The title says "within programs" - what does that mean? 2. You say "using the default external browser, not within Emacs", but you say "at point". What do you mean? Is this about using 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 mention goto-address-mode - seems unrelated.
    – Drew
    Sep 20, 2023 at 15:44
  • @Drew Edited. Is this better?
    – Sam7919
    Sep 20, 2023 at 15:56
  • Yes, thanks, but title is still not clear ("within programs"?). But you still don't say why browse-url-at-point tries to open non-URLs at point. It's code shows that it uses browse-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 that browse-url-at-point mis-recognizes as a URL. Also: you can follow what browse-url-url-at-point does, step by step, by first doing M-x debug-on-entry browse-url-url-at-point. Finally, use emacs -Q (no init file), to be sure the problem isn't introduced by your init file.
    – Drew
    Sep 20, 2023 at 18:22

1 Answer 1

0

C-cRET will open a URL, and only a URL.

Remembering distinct key mappings for the same operation in different modes is not ideal, but this is at least a starter.

3
  • "You"? You are the OP. Please say what C-c RET does that's different, and how it's "what you want", as opposed to what browse-url-at-point does.
    – Drew
    Sep 20, 2023 at 18:24
  • @Drew Oddly, I keep referring to this answer (my answer), as I tend to type C-c C-o (as I do in org-mode) to open URLs from source code files. But returning here yet one more time I'm puzzled at your indignation. The standard on all SE sites is to target questions and answers to people who are in a hurry. Almost no one in the audience at large notices, let alone cares, that the person who asked and the person who answered are the same. They just want to know. For this reason self-answers addressing the question in the third person are as frequent as those addressing oneself, and the former ..
    – Sam7919
    Jan 30 at 14:10
  • @Drew make much more sense for someone who's here in a hurry to find a quick answer and move on.
    – Sam7919
    Jan 30 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.