The url-get-url-at-point
function from the url-util
(emacs built-in) package should do the job for you. It is used in interactive commands like browse-url-at-point
.
(require 'url-util)
(defun my/kill-url-at-point ()
"Kill the url at point."
(interactive)
(kill-new (url-get-url-at-point)))
If you need to copy URL from an HTML page while in an emacs browser like eww
, you can use the shr-copy-url
command directly. The fun thing is that if you consecutively call that command twice while the point is on a hyperlink, it removes the link re-directions too!
From C-h f shr-copy-url
:
shr-copy-url is an interactive compiled Lisp function in `shr.el'.
(shr-copy-url &optional IMAGE-URL)
For more information check the manuals.
Copy the URL under point to the kill ring.
If IMAGE-URL (the prefix) is non-nil, or there is no link under
point, but there is an image under point then copy the URL of the
image under point instead.
If called twice, then try to fetch the URL and see whether it
redirects somewhere else.
Here's an example of how I use shr-copy-url
in one of my eww snippets.
nxml-mode
highlight the links in any special way? (If so, you could use the face or some other text property to pick out the link w/o parsing). Is this something you need fornxml-mode
only? (There's a way to do that in some other modes, such asw3m
andorg-mode
).