From: Spencer Baugh Date: Sat, 19 Aug 2023 12:24:45 +0000 (-0400) Subject: Expand project file names before storing them X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=255b7e1a046cbf9a745d58080d74983bfe205859;p=emacs.git 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. We only do this for local files, though, to avoid making remote connections; the situation will still be bad for remote projects, but at least this is an improvement. * 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. --- diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 6f35b3cc1b1..32eb3bbb89f 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1597,7 +1597,12 @@ With some possible metadata (to be decided).") (when (file-exists-p filename) (with-temp-buffer (insert-file-contents filename) - (read (current-buffer))))) + (mapcar + (lambda (elem) + (let ((name (car elem))) + (list (if (file-remote-p name) name + (abbreviate-file-name name))))) + (read (current-buffer)))))) (unless (seq-every-p (lambda (elt) (stringp (car-safe elt))) project--list) @@ -1617,7 +1622,12 @@ With some possible metadata (to be decided).") (insert ";;; -*- lisp-data -*-\n") (let ((print-length nil) (print-level nil)) - (pp project--list (current-buffer))) + (pp (mapcar (lambda (elem) + (let ((name (car elem))) + (list (if (file-remote-p name) name + (expand-file-name name))))) + project--list) + (current-buffer))) (write-region nil nil filename nil 'silent)))) ;;;###autoload @@ -1626,7 +1636,7 @@ With some possible metadata (to be decided).") 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)) @@ -1642,7 +1652,7 @@ result in `project-list-file'. Announce the project's removal 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)))