aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimen Heggestøyl2020-06-05 19:32:30 +0200
committerSimen Heggestøyl2020-06-09 20:45:55 +0200
commitd4e7087b68d70a1f05decbce07340801fe08fe7e (patch)
tree8220c8fd069ef67c97b5401c5e03c3743a658e52
parent5a6e790247ca8f0964ee8acd6dc6c564daaf6077 (diff)
downloademacs-d4e7087b68d70a1f05decbce07340801fe08fe7e.tar.gz
emacs-d4e7087b68d70a1f05decbce07340801fe08fe7e.zip
Save project list as lisp data
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.
-rw-r--r--lisp/progmodes/project.el22
1 files changed, 9 insertions, 13 deletions
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 4d57fb25fda..0cca518d261 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -763,13 +763,8 @@ Arguments the same as in `compile'."
763 (when (file-exists-p filename) 763 (when (file-exists-p filename)
764 (with-temp-buffer 764 (with-temp-buffer
765 (insert-file-contents filename) 765 (insert-file-contents filename)
766 (let ((dirs (split-string (buffer-string) "\n" t)) 766 (goto-char (point-min))
767 (project-list '())) 767 (read (current-buffer)))))))
768 (dolist (dir dirs)
769 (cl-pushnew (file-name-as-directory dir)
770 project-list
771 :test #'equal))
772 (reverse project-list)))))))
773 768
774(defun project--ensure-read-project-list () 769(defun project--ensure-read-project-list ()
775 "Initialize `project--list' if it hasn't already been." 770 "Initialize `project--list' if it hasn't already been."
@@ -780,7 +775,8 @@ Arguments the same as in `compile'."
780 "Persist `project--list' to the project list file." 775 "Persist `project--list' to the project list file."
781 (let ((filename project-list-file)) 776 (let ((filename project-list-file))
782 (with-temp-buffer 777 (with-temp-buffer
783 (insert (string-join project--list "\n")) 778 (insert ";;; -*- lisp-data -*-\n")
779 (pp project--list (current-buffer))
784 (write-region nil nil filename nil 'silent)))) 780 (write-region nil nil filename nil 'silent))))
785 781
786(defun project--add-to-project-list-front (pr) 782(defun project--add-to-project-list-front (pr)
@@ -788,9 +784,9 @@ Arguments the same as in `compile'."
788Save the result to disk if the project list was changed." 784Save the result to disk if the project list was changed."
789 (project--ensure-read-project-list) 785 (project--ensure-read-project-list)
790 (let ((dir (project-root pr))) 786 (let ((dir (project-root pr)))
791 (unless (equal (car project--list) dir) 787 (unless (equal (caar project--list) dir)
792 (setq project--list (delete dir project--list)) 788 (setq project--list (assoc-delete-all dir project--list))
793 (push dir project--list) 789 (push (list dir) project--list)
794 (project--write-project-list)))) 790 (project--write-project-list))))
795 791
796(defun project--remove-from-project-list (pr-dir) 792(defun project--remove-from-project-list (pr-dir)
@@ -798,8 +794,8 @@ Save the result to disk if the project list was changed."
798If the directory was in the list before the removal, save the 794If the directory was in the list before the removal, save the
799result to disk." 795result to disk."
800 (project--ensure-read-project-list) 796 (project--ensure-read-project-list)
801 (when (member pr-dir project--list) 797 (when (assoc pr-dir project--list)
802 (setq project--list (delete pr-dir project--list)) 798 (setq project--list (assoc-delete-all pr-dir project--list))
803 (message "Project `%s' not found; removed from list" pr-dir) 799 (message "Project `%s' not found; removed from list" pr-dir)
804 (project--write-project-list))) 800 (project--write-project-list)))
805 801