unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: sbaugh@catern.com
To: Juri Linkov <juri@linkov.net>
Cc: 66260@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)	[thread overview]
Message-ID: <8734yv22jb.fsf@catern.com> (raw)
In-Reply-To: <86il7tihzl.fsf@mail.linkov.net> (Juri Linkov's message of "Fri,  29 Sep 2023 09:57:50 +0300")

[-- Attachment #1: Type: text/plain, Size: 373 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Project-support-in-dired-copy-filename-as-kill.patch --]
[-- Type: text/x-patch, Size: 2220 bytes --]

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	other threads:[~2023-09-30 13:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-28 23:26 bug#66260: 29.0.92; project.el should support copying a file path relative to the project root sbaugh
2023-09-29  6:57 ` Juri Linkov
2023-09-30 13:50   ` sbaugh [this message]
2023-09-30 14:47     ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-30 15:17       ` sbaugh
2023-10-01 22:44 ` Dmitry Gutov
2023-10-02  5:57   ` Eli Zaretskii
2023-10-02  6:53     ` Juri Linkov
2023-10-02 11:46       ` Dmitry Gutov
2023-10-03 20:49         ` sbaugh
2023-10-03 21:17           ` Dmitry Gutov
2023-10-02 11:13     ` Rudolf Adamkovič via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-21 13:13   ` sbaugh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8734yv22jb.fsf@catern.com \
    --to=sbaugh@catern.com \
    --cc=66260@debbugs.gnu.org \
    --cc=juri@linkov.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).