Subject: bug#79480: [PATCH] add `log-view-copy-revision-as-kill' function

From: Timo Myyrä <[email-masked]>
Date: Sun, 21 Sep 2025 12:07:45 +0300

On Sun, Sep 21 2025, Eli Zaretskii wrote:

>> From: Timo Myyrä <[email-masked]>
>> Date: Sun, 21 Sep 2025 11:27:44 +0300
>> 
>> Here is an patch to implement `w' binding in the log-view-mode-map to
>> copy the revision string to kill-ring. Helps when the revision is
>> required in some other command.
>> This tries to follow the same idiom as in the dired mode where `w'
>> copies the filename under point to kill ring.
>
> Thanks.
>
>> --- a/etc/NEWS
>> +++ b/etc/NEWS
>> @@ -2330,6 +2330,12 @@ You can get back the old behavior with something like this:
>>      (with-eval-after-load 'log-view
>>        (keymap-set log-view-mode-map "m" #'log-view-toggle-mark-entry))
>>  
>> +---
>> +*** A new function `log-view-copy-revision-as-kill' added
>
> Heading lines in NEWS must end in a period.  Also, please quote 'like
> this' in NEWS.
>
>> +The log-view now provides new `log-view-copy-revision-as-kill' function
>                                                                   ^^^^^^^^
> "command".
>
> Also, there's no need to tell which package provided the new command.
> So something like
>
>   The new command 'log-view-copy-revision-as-kill' allows copying ...
>
> is better.
>
> And IMO the "-as-kill" part of the command's name is redundant.
>
>> +to copy the revision string under point to the kill-ring. The command is
>> +bound by default to `w' in log-view-mode-map.
>
> Please use "at point", not "under point".  (Actually, I believe a more
> accurate wording is "revision string of the log entry at point".)

Thanks for the quick feedback. I updated the patch accordingly.

I kept the 'as-kill' part as there are multiple commands in emacs with
same suffix. The new command mimics the functionality from dired where
the command is named 'dired-copy-filename-as-kill' so I thought to keep
the similar naming here.

timo

>From 516fc6115575e201bde859ef320392b99f8e7f7a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20Myyr=C3=A4?= <[email-masked]>
Date: Sun, 21 Sep 2025 11:12:55 +0300
Subject: [PATCH] add `log-view-copy-revision-as-kill' command

Add `log-view-copy-revision-as-kill' command to copy revision as string
and bind it `w' key in the log-view-mode-map.
---
 etc/NEWS            | 6 ++++++
 lisp/vc/log-view.el | 7 +++++++
 2 files changed, 13 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 059270bff46..ae7478c28ea 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2330,6 +2330,12 @@ You can get back the old behavior with something like this:
     (with-eval-after-load 'log-view
       (keymap-set log-view-mode-map "m" #'log-view-toggle-mark-entry))
 
+---
+*** A new command 'log-view-copy-revision-as-kill' added.
+The new command 'log-view-copy-revision-as-kill' copies the revision
+string of the log entry at point to the kill-ring. The command is bound
+by default to 'w' in log-view-mode-map.
+
 ** Diff mode
 
 +++
diff --git a/lisp/vc/log-view.el b/lisp/vc/log-view.el
index 3d04676b419..dd610968c7e 100644
--- a/lisp/vc/log-view.el
+++ b/lisp/vc/log-view.el
@@ -136,6 +136,7 @@ log-view-mode-map
   "n" #'log-view-msg-next
   "p" #'log-view-msg-prev
   "TAB" #'log-view-msg-next
+  "w" #'log-view-copy-revision-as-kill
   "<backtab>" #'log-view-msg-prev)
 
 (easy-menu-define log-view-mode-menu log-view-mode-map
@@ -742,6 +743,12 @@ log-view-diff-common
                log-view-vc-fileset)))
      fr to)))
 
+(defun log-view-copy-revision-as-kill ()
+  "Copy the revision string of the log entry at point to the kill-ring."
+  (when-let ((revision (cadr (log-view-current-entry))))
+    (kill-new revision)
+    (message "%s" revision)))
+
 (provide 'log-view)
 
 ;;; log-view.el ends here
-- 
2.50.1