From 193a105b40b3a002f51e1f59dd2a3d48443e11fe Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Sat, 19 Aug 2023 08:24:45 -0400 Subject: [PATCH] Expand project file names before storing them Before, whatever project-root returned, we stored as the root directory of the project in project-list and project-list-file. This could lead to duplicate entries or bad behavior if projects were accessed by different file names, e.g. both /home/user/src/emacs and ~/src/emacs. Now project-list-file contains only expanded paths and project--list contains only abbreviated paths. We abbreviate filenames before setting project--list, and expand filenames before writing to project-list-file. * lisp/progmodes/project.el (project--write-project-list): Call expand-file-name. (project--read-project-list, project-remember-project) (project--remove-from-project-list): Call abbreviate-file-name. --- lisp/progmodes/project.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 11fa93fb70d..e99a9061275 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1586,7 +1586,7 @@ project--read-project-list (when (file-exists-p filename) (with-temp-buffer (insert-file-contents filename) - (read (current-buffer))))) + (mapcar #'abbreviate-file-name (read (current-buffer)))))) (unless (seq-every-p (lambda (elt) (stringp (car-safe elt))) project--list) @@ -1606,7 +1606,7 @@ project--write-project-list (insert ";;; -*- lisp-data -*-\n") (let ((print-length nil) (print-level nil)) - (pp project--list (current-buffer))) + (pp (mapcar #'expand-file-name project--list) (current-buffer))) (write-region nil nil filename nil 'silent)))) ;;;###autoload @@ -1615,7 +1615,7 @@ project-remember-project Save the result in `project-list-file' if the list of projects has changed, and NO-WRITE is nil." (project--ensure-read-project-list) - (let ((dir (project-root pr))) + (let ((dir (abbreviate-file-name (project-root pr)))) (unless (equal (caar project--list) dir) (dolist (ent project--list) (when (equal dir (car ent)) @@ -1631,7 +1631,7 @@ project--remove-from-project-list from the list using REPORT-MESSAGE, which is a format string passed to `message' as its first argument." (project--ensure-read-project-list) - (when-let ((ent (assoc project-root project--list))) + (when-let ((ent (assoc (abbreviate-file-name project-root) project--list))) (setq project--list (delq ent project--list)) (message report-message project-root) (project--write-project-list))) -- 2.41.0