Dmitry Gutov writes: > On 29/09/2023 02:26, sbaugh@catern.com wrote: >> When communicating with others, it is often useful to copy a file path >> to the current file which is relative to the project root. For example >> I'd rather send someone the path lisp/progmodes/project.el than >> ~/src/emacs/trunk/lisp/progmodes/project.el. >> project.el should have a way to copy this file path. >> Almost good enough is: >> C-x p f ;; project-find-file >> M-n ;; next-history-element >> C-k ;; kill-line >> but with project--read-file-cpd-relative, if all the files in >> project-files start with a common-parent-directory which is a >> subdirectory of project-root, the resulting file path will not be >> relative to the project-root but to the subdirectory. > > A problem with modifying the above function's behavior like that is > that sometimes it is passed a wider range of file names, where not all > of them are inside the project root (M-x > project-or-external-find-file). Oh, what if we just *check* if the common-parent-directory is below the project root, and in that case use the project root instead? That elegantly resolves this without breaking that. Like this: