Subject: bug#77857: [PATCH] Let eww-copy-page-url append to existing kill

From: James Thomas <[email-masked]>
Date: Mon, 21 Apr 2025 05:43:00 +0530

Eli Zaretskii writes:

>> From: James Thomas
>> Cc: [email-masked],  [email-masked]
>> Date: Sun, 20 Apr 2025 12:29:39 +0530
>> 
>> Eli Zaretskii writes:
>> 
>> >> From: James Thomas
>> >> Cc: Eli Zaretskii,  [email-masked]
>> >> Date: Sat, 19 Apr 2025 14:54:27 +0530
>> >> 
>> >> Stefan Kangas writes:
>> >> 
>> >> > Makes sense to me, but I think we should make it optional somehow.  It's
>> >> > not the typical use case, and it changes current behavior.
>> >> 
>> >> Eli Zaretskii writes:
>> >> 
>> >> > That's an incompatible change in behavior, no?
>> >> 
>> >> Well... no (isn't it?). It only happens with 'C-M-w' before 'w', which
>> >> currently has no effect: (info "(emacs) Appending Kills").
>> >
>> > That's the change: previously Emacs produced different results in this
>> > case.  People might not expect the 'w' command to do that, they might
>> > expect that their previous kill remains intact.
>> 
>> No, I mean, they'd _have_ to press 'C-M-w' for that to happen, right
>> before the 'w' - which they'd do only if they wanted this.
>> 
>> I think we're miscommunicating:
>> 
>>   Previously: C-M-w w: A simple copy (so no one would type the C-M-w).
>>   Now:        C-M-w w: Appended to the previous kill.
>> 
>> (There's no change in 'w's behaviour without an immediately preceding
>> 'C-M-w')
>
> What I have in mind is the sequence "M-w w" or "C-w w".  AFAIU,
> previously, 'w' would start a new kill-ring entry, but with your
> suggestion it will append to whatever C-w/M-w killed before it.
> Right?

The first wouldn't, because 'M-w' is not 'kill-region', and for the
second, one would have to _move out_ of the form field (where the 'C-w'
happened) before pressing 'w'.

But indeed, when I came up with this I hadn't thought of the situation
where 'w' is rebound to a key-chord, perhaps, so that it could be typed
immediately after, in the latter case above. So the question now is
whether it's even desirable in such a (IMO, rare) case. If so, here's an
updated patch with a News entry.

From 64647223e60adb8559c03151027dc20eff323792 Mon Sep 17 00:00:00 2001
From: James Thomas <[email-masked]>
Date: Mon, 21 Apr 2025 05:01:06 +0530
Subject: [PATCH] Let eww-copy-page-url append to existing kill

Author: James Thomas <[email-masked]>
If there was an immediately preceding kill, append to it rather
than creating a new one.  This allows usage with
'append-next-kill'.

* lisp/net/eww.el (eww-copy-page-url): Make the change.
---
 etc/NEWS        | 5 +++++
 lisp/net/eww.el | 7 +++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 00e9e1871cd..d2005469020 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -507,6 +507,11 @@ content-type of Web pages which don't have a valid 'Content-Type'
 header.  The default value is a function that considers a page with an
 HTML 'doctype' declaration to have context-type "text/html".
 
+---
+*** 'eww-copy-page-url' now appends to any immediately preceding kill.
+This is similar to 'kill-ring-save' and means that it may now be used
+with 'append-next-kill'.
+
 ** CC mode
 
 +++
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 0c23ebc19cd..ea3f78d9fbe 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -2233,8 +2233,11 @@ eww-same-page-p
 (defun eww-copy-page-url ()
   "Copy the URL of the current page into the kill ring."
   (interactive nil eww-mode)
-  (message "%s" (plist-get eww-data :url))
-  (kill-new (plist-get eww-data :url)))
+  (let ((str (plist-get eww-data :url)))
+    (message "%s" str)
+    (if (eq last-command 'kill-region)
+        (kill-append str nil)
+      (kill-new str))))
 
 (defun eww-download ()
   "Download URL to `eww-download-directory'.
-- 
2.46.0

--