Skip to content

Commit

Permalink
magit-{browse,visit}-thing: Handle raw URL links
Browse files Browse the repository at this point in the history
Every once in a while, someone suggests that it should be possible to
follow URL links (often those displayed by user hooks and thus in the
process buffer), which I used to decline, on the grounds that it would
be way too costly to do that, for too little gain, and that the
workaround (using `browse-url') was simple and obvious enough.

By adding support for urls to `magit-browse-thing' (because that is
where it belongs, according to Magit's browse|visit distinction) and
`magit-visit-thing' (because that (i.e., "RET") is what users are
likely to try using), we get the desired behavior -- without having
to spend time looking for urls ahead while washing process output.

So now "RET" visits links, unless `magit-visit-thing' is remapped to
something else, that is.  The mouse still cannot be used.

Closes #5134.
  • Loading branch information
tarsius committed May 2, 2024
1 parent f72a02f commit d98e935
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lisp/magit-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,9 @@ which actually visits the thing at point."
(interactive)
(if (eq transient-current-command 'magit-dispatch)
(call-interactively (key-binding (this-command-keys)))
(user-error "There is no thing at point that could be visited")))
(if-let ((url (browse-url-url-at-point)))
(browse-url url)
(user-error "There is no thing at point that could be visited"))))
(put 'magit-visit-thing 'completion-predicate #'ignore)

(defun magit-edit-thing ()
Expand All @@ -436,11 +438,13 @@ buffer."
(put 'magit-edit-thing 'completion-predicate #'ignore)

(defun magit-browse-thing ()
"This is a placeholder command, which signals an error if called.
"This is a placeholder command, which may signals an error if called.
Where applicable, other keymaps remap this command to another,
which actually visits thing at point using `browse-url'."
(interactive)
(user-error "There is no thing at point that could be browsed"))
(if-let ((url (browse-url-url-at-point)))
(browse-url url)
(user-error "There is no thing at point that could be browsed")))
(put 'magit-browse-thing 'completion-predicate #'ignore)

(defun magit-copy-thing ()
Expand Down

0 comments on commit d98e935

Please sign in to comment.