Dmitry Gutov writes: > I'm pushed the first of your patches, but the second needed some > adjustments. Chiefly because we need to make sure it works with any > value of project-read-file-name-function, so the impl can't be > concentrated in just one of them. > > Check out the amended patch below. Any suggestions on how to do it > more elegantly (without duplicating the add-to-history call) are > welcome too. > > diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el > index e1d14474323..d810d8d9605 100644 > --- a/lisp/progmodes/project.el > +++ b/lisp/progmodes/project.el > @@ -1046,6 +1046,13 @@ project-read-file-name-function > :group 'project > :version "27.1") > > +(defun project--expand-file-name (filename project) > + (when-let ((old-root (get-text-property 0 'project filename))) > + (abbreviate-file-name > + (expand-file-name > + (file-relative-name filename old-root) > + (project-root project))))) > + > (defun project--read-file-cpd-relative (prompt > all-files &optional predicate > hist mb-default) > @@ -1124,9 +1131,18 @@ project-find-file-in > dirs) > (project-files project dirs))) > (completion-ignore-case read-file-name-completion-ignore-case) > - (file (funcall project-read-file-name-function > - "Find file" all-files nil 'file-name-history > - suggested-filename))) > + (file > + (let ((file-name-history (mapcar > + (lambda (f) > + (or (project--expand-file-name > f project) f)) > + file-name-history))) > + (funcall project-read-file-name-function > + "Find file" all-files nil 'file-name-history > + suggested-filename)))) > + (when history-add-new-input > + ;; Have to re-add it here because of the let-binding above. > + (add-to-history 'file-name-history > + (propertize file 'project (project-root project)))) > (if (string= file "") > (user-error "You didn't specify the file") > (find-file file)))) This seems good, sure. But doesn't this make the history entries appear twice? Maybe we should just pull the history-adding functionality out of project-read-file-name-function entirely. I've tried doing that below. Also, I realized just now that this should probably affect project-find-dir as well, as should my previous patch adding project-relative future history. (I actually coincidentally just now got a user request for "switch between projects and stay in the same dir") So here's a revised version of this history change which also affects project-find-dir. In a subsequent mail I'll send a patch for the "future history" behavior of project-find-dir too. (yet to be written)