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

From: Timo Myyrä <[email-masked]>
Date: Sun, 21 Sep 2025 11:27:44 +0300

Tags: patch

Hi,

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.

Timo

In GNU Emacs 30.1.90 (build 1, x86_64-unknown-openbsd, X toolkit, cairo
 version 1.18.4, Xaw3d scroll bars) of 2025-05-25 built on
 asteroid.bittivirhe.fi
Windowing system distributor 'The X.Org Foundation', version 11.0.12101018
System Description: OpenBSD asteroid.bittivirhe.fi 7.7 GENERIC.MP#99 amd64

Configured using:
 'configure --build=amd64-unknown-openbsd
 --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/30.1.90/site-lisp:/usr/local/share/emacs/site-lisp
 --without-sound --with-x-toolkit=athena --prefix=/usr/local
 --sysconfdir=/etc --mandir=/usr/local/man --infodir=/usr/local/info
 --localstatedir=/var --disable-silent-rules --disable-gtk-doc
 'CFLAGS=-O2 -pipe -g' CPPFLAGS=-I/usr/local/include
 'LDFLAGS=-L/usr/local/lib -g''

>From 86575949dc6b83959d118874bde5056dbc2639e4 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' function

Add `log-view-copy-revision-as-kill' function 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..70614b0b324 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 function `log-view-copy-revision-as-kill' added
+The log-view now provides new `log-view-copy-revision-as-kill' function
+to copy the revision string under 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..bbfcc200192 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 under 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