bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#66260: 29.0.92; project.el should support copying a file path relati


From: sbaugh
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)
User-agent: Gnus/5.13 (Gnus v5.13)

Juri Linkov <juri@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.

>From 95bd0a8775284dc59119198b02fcc64b904c4d7f Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]