Subject: bug#76792: closed (Re: bug#76792: [PATCH] dired-copy-filename-as-kill to support project relative names)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 15 Mar 2025 03:08:03 +0000

Your bug report

#76792: [PATCH] dired-copy-filename-as-kill to support project relative names

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
76792: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=76792
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#76792: [PATCH] dired-copy-filename-as-kill to support project relative names
From: Dmitry Gutov <[email-masked]>
To: Stefan Kangas <[email-masked]>
Cc: Eli Zaretskii <[email-masked]>, [email-masked]
Date: Sat, 15 Mar 2025 05:07:23 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Version: 31.1

On 14/03/2025 22:35, Stefan Kangas wrote:
> Dmitry Gutov <[email-masked]> writes:
> 
>> Like you concluded, it would still be supported, except for value ARG=1. We have
>> reserved ARG=0 for a different behavior already, so it seems that ARG is not
>> suitable for programmatic calculation anyway.
> 
> I found use for this new prefix argument today.
> 
> How about installing it now?

Thanks for the encouragement, pushed it now to master, commit 
af81b3af4ce99c.

Just to note that if anybody still disagrees with the prefix convention, 
they are free to refine the behavior, I don't really mind.

Subject: [PATCH] dired-copy-filename-as-kill to support project relative names
From: Dmitry Gutov <[email-masked]>
To: [email-masked]
Date: Fri, 7 Mar 2025 00:39:02 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Here's an implementation for that idea, together with .texi and NEWS 
changes.

Comments welcome!

diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi
index 07142e71713..5fc0c3b4a52 100644
--- a/doc/emacs/dired.texi
+++ b/doc/emacs/dired.texi
@@ -1860,8 +1860,9 @@ Misc Dired Features
 you had killed them with @kbd{C-w}.  The names are separated by a
 space.
 
-  With a zero prefix argument, this uses the absolute file name of
-each marked file.  With just @kbd{C-u} as the prefix argument, it uses
+  With a zero prefix argument, this uses the absolute file name of each
+marked file.  With prefix value, it uses names relative to the current
+project root.  With just @kbd{C-u} as the prefix argument, it uses
 file names relative to the Dired buffer's default directory.  (This
 can still contain slashes if in a subdirectory.)  As a special case,
 if point is on a directory header line, @kbd{w} gives you the absolute
diff --git a/etc/NEWS b/etc/NEWS
index 78a241abfd3..0bae8f4fe35 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1136,6 +1136,10 @@ Without 'dired-hide-details-hide-absolute-location':
 When 'dired-make-directory-clickable' is non-nil, clicking on the base
 name of the directory now reverts the Dired buffer.
 
+*** 'dired-copy-filename-as-kill' supports project-relative names.
+With a new value of the prefix argument (1), this command copies file
+names relative to the root directory of the current project.
+
 ** Grep
 
 +++
diff --git a/lisp/dired.el b/lisp/dired.el
index aa766b6170e..9f92e1cb5f8 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -3477,6 +3477,7 @@ dired-copy-filename-as-kill
 quoting is done.)
 
 With a zero prefix arg, use the absolute file name of each marked file.
+With a prefix value 1, use the names relative to the current project root.
 With \\[universal-argument], use the file name relative to the Dired buffer's
 `default-directory'.  (This still may contain slashes if in a subdirectory.)
 
@@ -3488,8 +3489,13 @@ dired-copy-filename-as-kill
   (let* ((files
           (or (ensure-list (dired-get-subdir))
               (if arg
-                  (cond ((zerop (prefix-numeric-value arg))
+                  (cond ((eql 0 arg)
                          (dired-get-marked-files))
+                        ((eql 1 arg)
+                         (let ((root (project-root (project-current t))))
+                           (mapcar
+                            (lambda (file) (file-relative-name file root))
+                            (dired-get-marked-files))))
                         ((consp arg)
                          (dired-get-marked-files t))
                         (t