Subject: 29.1; [PATCH] Add function eww-copy-point-link-url to eww.

From: Osmo Karppinen <[email-masked]>
Date: Sun, 03 Dec 2023 17:13:23 +0200

Tags: patch

New function eww-copy-point-link-url will copy URL of link pointed by
the pointer to the killring in eww. Patch adds also new key binding for
the function and also menuitem. I think that key "c" is good for this
operation.

Why? Sometimes it is needed to get url from link at the point to your
killring. Data behind the url could be in form what eww or emacs can't
handle well. So it is not quite handy to load page and then copy it's
url to the killring with eww-copy-page-url.

GNU Emacs 30.0.50 Development version fb4b0b30a24e on master branch;
build date 2023-12-03.

>From 10c3a26ace07f2e2d9a2c55839c0ccfa3a1fad32 Mon Sep 17 00:00:00 2001
From: Osmo Karppinen <[email-masked]>
Date: Sun, 3 Dec 2023 16:23:36 +0200
Subject: [PATCH] Add function eww-copy-point-link-url to eww.

Function will copy URL of link pointed by the pointer to the killring in
eww. Also new key binding and menu item added for the function. I think
that key "c" is good key for this.
---
 lisp/net/eww.el | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 77bb6be..80b56b1 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -1102,6 +1102,7 @@ eww-mode-map
   "&" #'eww-browse-with-external-browser
   "d" #'eww-download
   "w" #'eww-copy-page-url
+  "c" #'eww-copy-point-link-url
   "A" #'eww-copy-alternate-url
   "C" #'url-cookie-list
   "v" #'eww-view-source
@@ -1136,6 +1137,7 @@ eww-mode-map
           ["Download" eww-download t]
           ["View page source" eww-view-source]
           ["Copy page URL" eww-copy-page-url t]
+          ["Copy link URL pointed" eww-copy-point-link-url t]
           ["List histories" eww-list-histories t]
           ["Switch to buffer" eww-switch-to-buffer t]
           ["List buffers" eww-list-buffers t]
@@ -1984,6 +1986,17 @@ eww-copy-page-url
   (message "%s" (plist-get eww-data :url))
   (kill-new (plist-get eww-data :url)))
 
+(defun eww-copy-point-link-url ()
+  "Copy the URL of the link pointed by the pointer to the killring."
+  (interactive nil eww-mode)
+  (let ((url (get-text-property (point) 'shr-url)))
+    (if url
+        (progn
+          (kill-new url)
+          (message "%s" url))
+      (progn (message "No url at the point.")
+             nil))))
+
 (defun eww-download ()
   "Download URL to `eww-download-directory'.
 Use link at point if there is one, else the current page's URL."
-- 
2.42.0

With thanks,
Osmo Karppinen