GNU bug report logs - #66260
29.0.92; project.el should support copying a file path relative to the project root

Previous Next

Package: emacs;

Reported by: sbaugh <at> catern.com

Date: Thu, 28 Sep 2023 23:28:02 UTC

Severity: wishlist

Found in version 29.0.92

Full log


View this message in rfc822 format

From: sbaugh <at> catern.com
To: Juri Linkov <juri <at> linkov.net>
Cc: 66260 <at> debbugs.gnu.org
Subject: bug#66260: 29.0.92; project.el should support copying a file path relative to the project root
Date: Sat, 30 Sep 2023 13:50:33 +0000 (UTC)
[Message part 1 (text/plain, inline)]
Juri Linkov <juri <at> linkov.net> writes:
> Sometimes an absolute path is needed too even in project directories.
> Maybe it's possible to find a new prefix argument to copy
> a project-root-relative path like 'C-u C-u w'?

I initially considered M-1 w, but that loses the ability to mark files
and then only copy one of them.  C-u C-u seems good.

Here's the implementation.

[0001-Project-support-in-dired-copy-filename-as-kill.patch (text/x-patch, inline)]
From 95bd0a8775284dc59119198b02fcc64b904c4d7f Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh <at> catern.com>
Date: Sat, 30 Sep 2023 09:49:03 -0400
Subject: [PATCH] Project support in dired-copy-filename-as-kill

It is often useful to get a filename relative to project-root; now it
is easier.

* lisp/dired.el (dired-get-filename): Support 'project.
(dired-copy-filename-as-kill): Make C-u C-u pass 'project.
---
 lisp/dired.el | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lisp/dired.el b/lisp/dired.el
index cc8c74839b9..cc2cf24fac2 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -3016,6 +3016,12 @@ dired-get-filename
 	(if (and handler (not (get handler 'safe-magic)))
 	    (concat "/:" file)
 	  file)))
+     ((eq localp 'project)
+      (if-let ((project (project-current nil (dired-current-directory))))
+          (file-relative-name
+           (concat (dired-current-directory) file)
+           (project-root project))
+        (concat (dired-current-directory t) file)))
      (t
       (concat (dired-current-directory localp) file)))))
 
@@ -3240,6 +3246,7 @@ dired-copy-filename-as-kill
 With a zero prefix arg, use the absolute file name of each marked file.
 With \\[universal-argument], use the file name relative to the Dired buffer's
 `default-directory'.  (This still may contain slashes if in a subdirectory.)
+With \\[universal-argument] \\[universal-argument], use the file name relative to `project-root'.
 
 If on a subdir headerline, use absolute subdirname instead;
 prefix arg and marked files are ignored in this case.
@@ -3251,8 +3258,10 @@ dired-copy-filename-as-kill
               (if arg
                   (cond ((zerop (prefix-numeric-value arg))
                          (dired-get-marked-files))
-                        ((consp arg)
+                        ((and (consp arg) (= 4 (prefix-numeric-value arg)))
                          (dired-get-marked-files t))
+                        ((and (consp arg) (>= 16 (prefix-numeric-value arg)))
+                         (dired-get-marked-files 'project))
                         (t
                          (dired-get-marked-files
 			  'no-dir (prefix-numeric-value arg))))
-- 
2.41.0


This bug report was last modified 1 year and 293 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.