]> git.eshelyaron.com Git - emacs.git/commitdiff
Save project list as lisp data
authorSimen Heggestøyl <simenheg@gmail.com>
Fri, 5 Jun 2020 17:32:30 +0000 (19:32 +0200)
committerSimen Heggestøyl <simenheg@gmail.com>
Tue, 9 Jun 2020 18:45:55 +0000 (20:45 +0200)
Save the project list file as lisp data instead of line separated
strings to make it more extendable in the future.

* lisp/progmodes/project.el (project--read-project-list)
(project--write-project-list, project--add-to-project-list-front)
(project--remove-from-project-list): Adjust to `project--list' now
being an alist.

lisp/progmodes/project.el

index 4d57fb25fda8637a25b7ec88347b78289abac7cd..0cca518d26154274ffc070ee057adf901d61f8b3 100644 (file)
@@ -763,13 +763,8 @@ Arguments the same as in `compile'."
           (when (file-exists-p filename)
             (with-temp-buffer
               (insert-file-contents filename)
-              (let ((dirs (split-string (buffer-string) "\n" t))
-                    (project-list '()))
-                (dolist (dir dirs)
-                  (cl-pushnew (file-name-as-directory dir)
-                              project-list
-                              :test #'equal))
-                (reverse project-list)))))))
+              (goto-char (point-min))
+              (read (current-buffer)))))))
 
 (defun project--ensure-read-project-list ()
   "Initialize `project--list' if it hasn't already been."
@@ -780,7 +775,8 @@ Arguments the same as in `compile'."
   "Persist `project--list' to the project list file."
   (let ((filename project-list-file))
     (with-temp-buffer
-      (insert (string-join project--list "\n"))
+      (insert ";;; -*- lisp-data -*-\n")
+      (pp project--list (current-buffer))
       (write-region nil nil filename nil 'silent))))
 
 (defun project--add-to-project-list-front (pr)
@@ -788,9 +784,9 @@ Arguments the same as in `compile'."
 Save the result to disk if the project list was changed."
   (project--ensure-read-project-list)
   (let ((dir (project-root pr)))
-    (unless (equal (car project--list) dir)
-      (setq project--list (delete dir project--list))
-      (push dir project--list)
+    (unless (equal (caar project--list) dir)
+      (setq project--list (assoc-delete-all dir project--list))
+      (push (list dir) project--list)
       (project--write-project-list))))
 
 (defun project--remove-from-project-list (pr-dir)
@@ -798,8 +794,8 @@ Save the result to disk if the project list was changed."
 If the directory was in the list before the removal, save the
 result to disk."
   (project--ensure-read-project-list)
-  (when (member pr-dir project--list)
-    (setq project--list (delete pr-dir project--list))
+  (when (assoc pr-dir project--list)
+    (setq project--list (assoc-delete-all pr-dir project--list))
     (message "Project `%s' not found; removed from list" pr-dir)
     (project--write-project-list)))