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