From c5b2e49cc8117e063d9e16a9072eb07ddff8aaa5 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Sat, 21 Oct 2023 09:11:52 -0400 Subject: [PATCH] Use project-root in project-find-file if all files are below it project-files can return a list of files all of whom are in a subdirectory of project-root. We should still use project-root in project--read-file-cpd-relative in that case, for several reasons: - Now M-n will always bring up the full path of the current file for copying - Now if the user wants to manually type in a path starting at the root, they can. * lisp/progmodes/project.el (project--read-file-cpd-relative): Always use project-root if all files are below that. (bug#66260) --- lisp/progmodes/project.el | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 0d6539113cc..dcd1cab4f96 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1117,9 +1117,16 @@ project--read-file-cpd-relative MB-DEFAULT is used as part of \"future history\", to be inserted by the user at will." (let* ((common-parent-directory - (let ((common-prefix (try-completion "" all-files))) - (if (> (length common-prefix) 0) - (file-name-directory common-prefix)))) + (let* ((common-prefix (try-completion "" all-files)) + (root (project-root (project-current))) + (expand-root (expand-file-name root)) + (abbrev-root (abbreviate-file-name root))) + (cond + ;; We try use the project-root even if all the files have + ;; a c-p-d below the project-root. + ((string-prefix-p expand-root common-prefix) expand-root) + ((string-prefix-p abbrev-root common-prefix) abbrev-root) + ((> (length common-prefix) 0) (file-name-directory common-prefix))))) (cpd-length (length common-parent-directory)) (prompt (if (zerop cpd-length) prompt -- 2.41.0